Faizbulbul commited on
Commit
43c9d4d
·
verified ·
1 Parent(s): 35ec0be

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -6
app.py CHANGED
@@ -1,10 +1,37 @@
1
- FROM python:3.10
 
 
 
2
 
3
- WORKDIR /app
 
4
 
5
- COPY requirements.txt .
6
- RUN pip install --no-cache-dir -r requirements.txt
 
 
 
 
7
 
8
- COPY . .
 
 
9
 
10
- CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ from pydantic import BaseModel
3
+ import torch
4
+ from diffusers import StableVideoDiffusionPipeline
5
 
6
+ # API Init
7
+ app = FastAPI()
8
 
9
+ # Load Model
10
+ device = "cuda" if torch.cuda.is_available() else "cpu"
11
+ pipe = StableVideoDiffusionPipeline.from_pretrained(
12
+ "stabilityai/stable-video-diffusion-img2vid"
13
+ )
14
+ pipe.to(device)
15
 
16
+ # Request Model
17
+ class VideoRequest(BaseModel):
18
+ prompt: str
19
 
20
+ # Root Endpoint
21
+ @app.get("/")
22
+ def home():
23
+ return {"message": "AI Video Generator API is running!"}
24
+
25
+ # Generate Video Endpoint
26
+ @app.post("/generate-video")
27
+ def generate_video(request: VideoRequest):
28
+ video_frames = pipe(request.prompt, num_inference_steps=50).frames
29
+ video_path = "output.mp4"
30
+ video_frames[0].save(video_path)
31
+ return {"message": "Video generated successfully!", "video_url": video_path}
32
+
33
+ # Run API
34
+ if __name__ == "__main__":
35
+ import uvicorn
36
+
37
+ uvicorn.run(app, host="0.0.0.0", port=7860)