Faizbulbul commited on
Commit
3f3c56c
·
verified ·
1 Parent(s): d8cd495

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -15
app.py CHANGED
@@ -1,22 +1,32 @@
1
- import gradio as gr
 
2
  import torch
3
  from diffusers import StableVideoDiffusionPipeline
 
4
 
5
- # Load Model
 
 
 
6
  pipe = StableVideoDiffusionPipeline.from_pretrained("stabilityai/stable-video-diffusion-img2vid")
7
- pipe.to("cuda" if torch.cuda.is_available() else "cpu")
8
 
9
- def generate_video(prompt):
10
- video_frames = pipe(prompt, num_inference_steps=50).frames
11
- video_path = "output.mp4"
12
- video_frames[0].save(video_path)
13
- return video_path
14
 
15
- iface = gr.Interface(
16
- fn=generate_video,
17
- inputs=gr.Textbox(label="Enter Prompt"),
18
- outputs=gr.Video(label="Generated Video"),
19
- title="AI Video Generator"
20
- )
 
 
 
 
21
 
22
- iface.launch()
 
 
 
 
1
+ from fastapi import FastAPI, HTTPException
2
+ from pydantic import BaseModel
3
  import torch
4
  from diffusers import StableVideoDiffusionPipeline
5
+ import uuid
6
 
7
+ app = FastAPI()
8
+
9
+ # ✅ Model Load करो (GPU अगर Available है तो)
10
+ device = "cuda" if torch.cuda.is_available() else "cpu"
11
  pipe = StableVideoDiffusionPipeline.from_pretrained("stabilityai/stable-video-diffusion-img2vid")
12
+ pipe.to(device)
13
 
14
+ # ✅ Request Body Format
15
+ class VideoRequest(BaseModel):
16
+ prompt: str
 
 
17
 
18
+ # API Endpoint: Video Generate करने के लिए
19
+ @app.post("/generate-video")
20
+ async def generate_video(request: VideoRequest):
21
+ try:
22
+ video_frames = pipe(request.prompt, num_inference_steps=50).frames
23
+ video_path = f"output_{uuid.uuid4().hex}.mp4"
24
+ video_frames[0].save(video_path)
25
+ return {"message": "Video generated successfully!", "video_url": video_path}
26
+ except Exception as e:
27
+ raise HTTPException(status_code=500, detail=str(e))
28
 
29
+ # ✅ Root Endpoint Check करने के लिए
30
+ @app.get("/")
31
+ def home():
32
+ return {"message": "AI Video Generator API is running!"}