Spaces:
Runtime error
Runtime error
Jamiiwej2903
commited on
Update main.py
Browse files
main.py
CHANGED
@@ -1,13 +1,13 @@
|
|
1 |
from fastapi import FastAPI, File, UploadFile, Form
|
2 |
-
from huggingface_hub import InferenceClient
|
3 |
import uvicorn
|
4 |
from fastapi.responses import StreamingResponse
|
5 |
import io
|
6 |
import base64
|
|
|
7 |
|
8 |
app = FastAPI()
|
9 |
|
10 |
-
|
11 |
|
12 |
@app.post("/generate_video/")
|
13 |
async def generate_video_api(
|
@@ -24,18 +24,24 @@ async def generate_video_api(
|
|
24 |
# Encode the image to base64
|
25 |
image_base64 = base64.b64encode(image_content).decode('utf-8')
|
26 |
|
27 |
-
#
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
# Return the video as a streaming response
|
38 |
-
return StreamingResponse(io.BytesIO(
|
39 |
|
40 |
if __name__ == "__main__":
|
41 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|
|
|
1 |
from fastapi import FastAPI, File, UploadFile, Form
|
|
|
2 |
import uvicorn
|
3 |
from fastapi.responses import StreamingResponse
|
4 |
import io
|
5 |
import base64
|
6 |
+
import requests
|
7 |
|
8 |
app = FastAPI()
|
9 |
|
10 |
+
API_URL = "https://api-inference.huggingface.co/models/stabilityai/stable-video-diffusion-img2vid-xt-1-1-tensorrt"
|
11 |
|
12 |
@app.post("/generate_video/")
|
13 |
async def generate_video_api(
|
|
|
24 |
# Encode the image to base64
|
25 |
image_base64 = base64.b64encode(image_content).decode('utf-8')
|
26 |
|
27 |
+
# Prepare the payload
|
28 |
+
payload = {
|
29 |
+
"inputs": image_base64,
|
30 |
+
"parameters": {
|
31 |
+
"fps": fps,
|
32 |
+
"num_frames": num_frames,
|
33 |
+
"motion_bucket_id": motion_bucket_id,
|
34 |
+
"cond_aug": cond_aug,
|
35 |
+
"seed": seed
|
36 |
+
}
|
37 |
+
}
|
38 |
+
|
39 |
+
# Make the API call
|
40 |
+
response = requests.post(API_URL, json=payload)
|
41 |
+
response.raise_for_status()
|
42 |
+
|
43 |
# Return the video as a streaming response
|
44 |
+
return StreamingResponse(io.BytesIO(response.content), media_type="video/mp4")
|
45 |
|
46 |
if __name__ == "__main__":
|
47 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|