Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -804,8 +804,8 @@ async def genvideo_airforce(request: Request, prompt: str = None):
|
|
| 804 |
"prompt": prompt,
|
| 805 |
"n": 1,
|
| 806 |
"size": "1024x1024",
|
| 807 |
-
"response_format": "
|
| 808 |
-
"sse":
|
| 809 |
"mode": "normal",
|
| 810 |
"aspectRatio": "3:2"
|
| 811 |
}
|
|
@@ -819,15 +819,31 @@ async def genvideo_airforce(request: Request, prompt: str = None):
|
|
| 819 |
|
| 820 |
if resp.status_code != 200:
|
| 821 |
return JSONResponse(status_code=resp.status_code, content=resp.json())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 822 |
|
| 823 |
-
|
| 824 |
-
video_url = result.get("data", [{}])[0].get("url")
|
| 825 |
-
if not video_url:
|
| 826 |
-
raise HTTPException(500, "No video URL returned from Airforce")
|
| 827 |
|
| 828 |
-
video_resp = await client.get(video_url)
|
| 829 |
return Response(
|
| 830 |
-
content=
|
| 831 |
media_type="video/mp4",
|
| 832 |
-
headers={
|
|
|
|
|
|
|
|
|
|
| 833 |
)
|
|
|
|
| 804 |
"prompt": prompt,
|
| 805 |
"n": 1,
|
| 806 |
"size": "1024x1024",
|
| 807 |
+
"response_format": "b64_json",
|
| 808 |
+
"sse": False,
|
| 809 |
"mode": "normal",
|
| 810 |
"aspectRatio": "3:2"
|
| 811 |
}
|
|
|
|
| 819 |
|
| 820 |
if resp.status_code != 200:
|
| 821 |
return JSONResponse(status_code=resp.status_code, content=resp.json())
|
| 822 |
+
if not resp.content:
|
| 823 |
+
raise HTTPException(
|
| 824 |
+
status_code=502,
|
| 825 |
+
detail="api.airforce returned empty response"
|
| 826 |
+
)
|
| 827 |
+
|
| 828 |
+
try:
|
| 829 |
+
result = resp.json()
|
| 830 |
+
b64_video = result["data"][0]["b64_json"]
|
| 831 |
+
except Exception:
|
| 832 |
+
raise HTTPException(
|
| 833 |
+
502,
|
| 834 |
+
f"Invalid api.airforce response: {resp.text[:500]}"
|
| 835 |
+
)
|
| 836 |
+
|
| 837 |
+
if not b64_video:
|
| 838 |
+
raise HTTPException(502, "Airforce returned empty b64_json")
|
| 839 |
|
| 840 |
+
video_bytes = base64.b64decode(b64_video)
|
|
|
|
|
|
|
|
|
|
| 841 |
|
|
|
|
| 842 |
return Response(
|
| 843 |
+
content=video_bytes,
|
| 844 |
media_type="video/mp4",
|
| 845 |
+
headers={
|
| 846 |
+
"Content-Length": str(len(video_bytes)),
|
| 847 |
+
"Accept-Ranges": "bytes",
|
| 848 |
+
},
|
| 849 |
)
|