Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -835,22 +835,36 @@ async def fetch_airforce_video(prompt: str, duration: int = 5) -> bytes:
|
|
| 835 |
|
| 836 |
@app.get("/gen/video/airforce/{prompt}")
|
| 837 |
@app.post("/gen/video/airforce")
|
| 838 |
-
async def genvideo_airforce(request: Request, prompt: str = None
|
|
|
|
| 839 |
if prompt is None:
|
| 840 |
body = await request.json()
|
| 841 |
prompt = body.get("prompt")
|
| 842 |
duration = body.get("duration", 5)
|
| 843 |
|
| 844 |
-
|
| 845 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 846 |
|
| 847 |
-
|
|
|
|
|
|
|
|
|
|
| 848 |
|
|
|
|
| 849 |
return Response(
|
| 850 |
-
content=
|
| 851 |
media_type="video/mp4",
|
| 852 |
-
headers={
|
| 853 |
-
"Content-Length": str(len(video_content)),
|
| 854 |
-
"Accept-Ranges": "bytes",
|
| 855 |
-
}
|
| 856 |
)
|
|
|
|
| 835 |
|
| 836 |
@app.get("/gen/video/airforce/{prompt}")
|
| 837 |
@app.post("/gen/video/airforce")
|
| 838 |
+
async def genvideo_airforce(request: Request, prompt: str = None):
|
| 839 |
+
data = await request.json()
|
| 840 |
if prompt is None:
|
| 841 |
body = await request.json()
|
| 842 |
prompt = body.get("prompt")
|
| 843 |
duration = body.get("duration", 5)
|
| 844 |
|
| 845 |
+
body = {
|
| 846 |
+
"model": "grok-imagine-video",
|
| 847 |
+
"prompt": prompt,
|
| 848 |
+
}
|
| 849 |
+
|
| 850 |
+
async with httpx.AsyncClient(timeout=600) as client:
|
| 851 |
+
resp = await client.post(
|
| 852 |
+
"https://api.airforce/v1/images/generations",
|
| 853 |
+
headers={"Authorization": f"Bearer {AIRFORCE_API_KEY}", "Content-Type": "application/json"},
|
| 854 |
+
json=body
|
| 855 |
+
)
|
| 856 |
+
|
| 857 |
+
if resp.status_code != 200:
|
| 858 |
+
return JSONResponse(status_code=resp.status_code, content=resp.json())
|
| 859 |
|
| 860 |
+
result = resp.json()
|
| 861 |
+
video_url = result.get("data", [{}])[0].get("url")
|
| 862 |
+
if not video_url:
|
| 863 |
+
raise HTTPException(500, "No video URL returned from Airforce")
|
| 864 |
|
| 865 |
+
video_resp = await client.get(video_url)
|
| 866 |
return Response(
|
| 867 |
+
content=video_resp.content,
|
| 868 |
media_type="video/mp4",
|
| 869 |
+
headers={"Content-Length": str(len(video_resp.content))}
|
|
|
|
|
|
|
|
|
|
| 870 |
)
|