Update app.py
Browse files
app.py
CHANGED
|
@@ -1,34 +1,29 @@
|
|
| 1 |
-
|
| 2 |
-
from
|
| 3 |
-
import
|
| 4 |
-
from diffusers import StableDiffusionPipeline, StableVideoDiffusionPipeline
|
| 5 |
-
from diffusers.utils import export_to_video
|
| 6 |
-
from PIL import Image
|
| 7 |
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
"
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
-
|
| 21 |
-
video_pipe = StableVideoDiffusionPipeline.from_pretrained(
|
| 22 |
-
"stabilityai/stable-video-diffusion-img2vid-xt", torch_dtype=dtype, variant=variant
|
| 23 |
-
).to(device)
|
| 24 |
-
|
| 25 |
-
@app.post("/generate")
|
| 26 |
-
def generate_video(prompt: str = Form(...), aspect: str = Form("16:9")):
|
| 27 |
-
image = text2img_pipe(prompt).images[0]
|
| 28 |
-
image = image.resize((1024, 576) if aspect == "16:9" else (576, 1024))
|
| 29 |
-
|
| 30 |
-
generator = torch.manual_seed(42)
|
| 31 |
-
frames = video_pipe(image, decode_chunk_size=8, generator=generator).frames[0]
|
| 32 |
-
export_to_video(frames, "output.mp4", fps=7)
|
| 33 |
-
|
| 34 |
-
return FileResponse("output.mp4", media_type="video/mp4", filename="output.mp4")
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from modelscope.pipelines import pipeline
|
| 3 |
+
from modelscope.utils.constant import Tasks
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
+
# Load ModelScope pipeline
|
| 6 |
+
video_pipe = pipeline(
|
| 7 |
+
Tasks.text_to_video_synthesis,
|
| 8 |
+
model='damo/text-to-video-synthesis',
|
| 9 |
+
device='cuda'
|
| 10 |
+
)
|
| 11 |
|
| 12 |
+
def generate(prompt, image):
|
| 13 |
+
image_path = "input.png"
|
| 14 |
+
image.save(image_path)
|
| 15 |
+
result = video_pipe({
|
| 16 |
+
'text': prompt,
|
| 17 |
+
'input_image': image_path
|
| 18 |
+
})
|
| 19 |
+
return result['video_path']
|
| 20 |
|
| 21 |
+
with gr.Blocks() as demo:
|
| 22 |
+
gr.Markdown("## 🎬 Text + Image → Shorts-Ready Video")
|
| 23 |
+
prompt = gr.Textbox(label="🔤 লিখুন (Bengali/English)")
|
| 24 |
+
image_input = gr.Image(type="pil", label="🖼️ একটি ছবি দিন")
|
| 25 |
+
video_output = gr.Video(label="🎥 Generated Video")
|
| 26 |
+
generate_btn = gr.Button("🎞️ ভিডিও তৈরি করুন")
|
| 27 |
+
generate_btn.click(fn=generate, inputs=[prompt, image_input], outputs=video_output)
|
| 28 |
|
| 29 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|