Sabbirr12 commited on
Commit
12f509e
·
verified ·
1 Parent(s): eac1619

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -30
app.py CHANGED
@@ -1,34 +1,29 @@
1
- from fastapi import FastAPI, Form
2
- from fastapi.responses import FileResponse
3
- import torch
4
- from diffusers import StableDiffusionPipeline, StableVideoDiffusionPipeline
5
- from diffusers.utils import export_to_video
6
- from PIL import Image
7
 
8
- app = FastAPI()
 
 
 
 
 
9
 
10
- # Force CPU setup
11
- device = "cpu"
12
- dtype = torch.float32
13
- variant = None # Don't use "fp16" on CPU
 
 
 
 
14
 
15
- # Load text-to-image model
16
- text2img_pipe = StableDiffusionPipeline.from_pretrained(
17
- "runwayml/stable-diffusion-v1-5", torch_dtype=dtype
18
- ).to(device)
 
 
 
19
 
20
- # Load image-to-video model
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()