Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -16,7 +16,7 @@ import base64
|
|
| 16 |
from subscriptions import fetch_subscription
|
| 17 |
from typing import Optional
|
| 18 |
from keywords import *
|
| 19 |
-
|
| 20 |
WAN_SPACE = "https://huggingface.co/spaces/Wan-AI/Wan2.1"
|
| 21 |
WAN_API_BASE = f"{WAN_SPACE}/gradio_api"
|
| 22 |
|
|
@@ -28,7 +28,7 @@ app.add_middleware(
|
|
| 28 |
allow_methods=["GET", "POST", "HEAD"],
|
| 29 |
allow_headers=["*"],
|
| 30 |
)
|
| 31 |
-
|
| 32 |
@app.get("/")
|
| 33 |
async def reroute_to_status():
|
| 34 |
return RedirectResponse(url="https://inference.js.org", status_code=status.HTTP_308_PERMANENT_REDIRECT)
|
|
@@ -1000,8 +1000,22 @@ async def genvideo_airforce(
|
|
| 1000 |
"seed": -1,
|
| 1001 |
}
|
| 1002 |
|
|
|
|
|
|
|
| 1003 |
if image_urls:
|
| 1004 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1005 |
|
| 1006 |
if inputMode == "fun":
|
| 1007 |
params["enhance"] = "true"
|
|
@@ -1011,10 +1025,15 @@ async def genvideo_airforce(
|
|
| 1011 |
|
| 1012 |
print(f"[VIDEO GEN] Pollinations URL: {url}")
|
| 1013 |
url = url + f"&key={PKEY}"
|
| 1014 |
-
|
| 1015 |
-
|
| 1016 |
-
|
| 1017 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1018 |
if resp.status_code != 200:
|
| 1019 |
body_text = ""
|
| 1020 |
try:
|
|
|
|
| 16 |
from subscriptions import fetch_subscription
|
| 17 |
from typing import Optional
|
| 18 |
from keywords import *
|
| 19 |
+
from assets import save_base64_image, cleanup_image, is_base64_image, asset_router
|
| 20 |
WAN_SPACE = "https://huggingface.co/spaces/Wan-AI/Wan2.1"
|
| 21 |
WAN_API_BASE = f"{WAN_SPACE}/gradio_api"
|
| 22 |
|
|
|
|
| 28 |
allow_methods=["GET", "POST", "HEAD"],
|
| 29 |
allow_headers=["*"],
|
| 30 |
)
|
| 31 |
+
app.include_router(asset_router)
|
| 32 |
@app.get("/")
|
| 33 |
async def reroute_to_status():
|
| 34 |
return RedirectResponse(url="https://inference.js.org", status_code=status.HTTP_308_PERMANENT_REDIRECT)
|
|
|
|
| 1000 |
"seed": -1,
|
| 1001 |
}
|
| 1002 |
|
| 1003 |
+
temp_assets = []
|
| 1004 |
+
|
| 1005 |
if image_urls:
|
| 1006 |
+
processed_urls = []
|
| 1007 |
+
|
| 1008 |
+
for img in image_urls[:2]:
|
| 1009 |
+
if is_base64_image(img):
|
| 1010 |
+
image_id = save_base64_image(img)
|
| 1011 |
+
temp_assets.append(image_id)
|
| 1012 |
+
|
| 1013 |
+
served_url = f"{request.base_url}asset-cdn/assets/{image_id}"
|
| 1014 |
+
processed_urls.append(served_url)
|
| 1015 |
+
else:
|
| 1016 |
+
processed_urls.append(img)
|
| 1017 |
+
|
| 1018 |
+
params["image"] = "|".join(processed_urls)
|
| 1019 |
|
| 1020 |
if inputMode == "fun":
|
| 1021 |
params["enhance"] = "true"
|
|
|
|
| 1025 |
|
| 1026 |
print(f"[VIDEO GEN] Pollinations URL: {url}")
|
| 1027 |
url = url + f"&key={PKEY}"
|
| 1028 |
+
resp = None
|
| 1029 |
+
try:
|
| 1030 |
+
async with httpx.AsyncClient(timeout=600) as client:
|
| 1031 |
+
resp = await client.get(url)
|
| 1032 |
+
finally:
|
| 1033 |
+
for aid in temp_assets:
|
| 1034 |
+
cleanup_image(aid)
|
| 1035 |
+
if resp is None:
|
| 1036 |
+
raise HTTPException(502, "Video generation request failed")
|
| 1037 |
if resp.status_code != 200:
|
| 1038 |
body_text = ""
|
| 1039 |
try:
|