Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,12 +7,13 @@ import uvicorn
|
|
| 7 |
import os
|
| 8 |
import uuid
|
| 9 |
import shutil
|
|
|
|
| 10 |
|
| 11 |
app = FastAPI(title="WAN2 GGUF API", version="1.0")
|
| 12 |
|
| 13 |
# ✅ Directories
|
| 14 |
MODEL_REPO = "calcuis/wan2-gguf"
|
| 15 |
-
MODEL_FILE = "wan2.2-animate-14b-q4_0.gguf"
|
| 16 |
MODEL_DIR = "models"
|
| 17 |
OUTPUT_DIR = "outputs"
|
| 18 |
|
|
@@ -42,37 +43,40 @@ def root():
|
|
| 42 |
@app.post("/generate")
|
| 43 |
def generate_video(request: PromptRequest):
|
| 44 |
"""
|
| 45 |
-
Dummy video generator —
|
| 46 |
-
Replace
|
| 47 |
"""
|
| 48 |
|
| 49 |
# Unique filename
|
| 50 |
file_id = str(uuid.uuid4())
|
| 51 |
file_path = os.path.join(OUTPUT_DIR, f"{file_id}.mp4")
|
| 52 |
|
| 53 |
-
#
|
| 54 |
placeholder_url = (
|
| 55 |
"https://huggingface.co/datasets/huggingface/documentation-images/"
|
| 56 |
"resolve/main/video-placeholder.mp4"
|
| 57 |
)
|
| 58 |
|
| 59 |
-
# Download placeholder
|
| 60 |
placeholder_file = os.path.join(OUTPUT_DIR, "placeholder.mp4")
|
| 61 |
if not os.path.exists(placeholder_file):
|
| 62 |
-
import requests
|
| 63 |
r = requests.get(placeholder_url, stream=True)
|
| 64 |
with open(placeholder_file, "wb") as f:
|
| 65 |
shutil.copyfileobj(r.raw, f)
|
| 66 |
|
| 67 |
-
# Copy placeholder to simulate
|
| 68 |
shutil.copy(placeholder_file, file_path)
|
| 69 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
return {
|
| 71 |
"status": "success",
|
| 72 |
"model_file": MODEL_FILE,
|
| 73 |
"prompt": request.prompt,
|
| 74 |
"steps": request.steps,
|
| 75 |
-
"video_url":
|
| 76 |
"note": "Replace this with actual inference code."
|
| 77 |
}
|
| 78 |
|
|
|
|
| 7 |
import os
|
| 8 |
import uuid
|
| 9 |
import shutil
|
| 10 |
+
import requests
|
| 11 |
|
| 12 |
app = FastAPI(title="WAN2 GGUF API", version="1.0")
|
| 13 |
|
| 14 |
# ✅ Directories
|
| 15 |
MODEL_REPO = "calcuis/wan2-gguf"
|
| 16 |
+
MODEL_FILE = "wan2.2-animate-14b-q4_0.gguf"
|
| 17 |
MODEL_DIR = "models"
|
| 18 |
OUTPUT_DIR = "outputs"
|
| 19 |
|
|
|
|
| 43 |
@app.post("/generate")
|
| 44 |
def generate_video(request: PromptRequest):
|
| 45 |
"""
|
| 46 |
+
Dummy video generator — just copies a placeholder .mp4.
|
| 47 |
+
Replace with actual WAN2 inference later.
|
| 48 |
"""
|
| 49 |
|
| 50 |
# Unique filename
|
| 51 |
file_id = str(uuid.uuid4())
|
| 52 |
file_path = os.path.join(OUTPUT_DIR, f"{file_id}.mp4")
|
| 53 |
|
| 54 |
+
# Hugging Face placeholder video
|
| 55 |
placeholder_url = (
|
| 56 |
"https://huggingface.co/datasets/huggingface/documentation-images/"
|
| 57 |
"resolve/main/video-placeholder.mp4"
|
| 58 |
)
|
| 59 |
|
| 60 |
+
# Download placeholder if not already present
|
| 61 |
placeholder_file = os.path.join(OUTPUT_DIR, "placeholder.mp4")
|
| 62 |
if not os.path.exists(placeholder_file):
|
|
|
|
| 63 |
r = requests.get(placeholder_url, stream=True)
|
| 64 |
with open(placeholder_file, "wb") as f:
|
| 65 |
shutil.copyfileobj(r.raw, f)
|
| 66 |
|
| 67 |
+
# Copy placeholder to simulate output
|
| 68 |
shutil.copy(placeholder_file, file_path)
|
| 69 |
|
| 70 |
+
# ✅ Build full URL for Hugging Face Space
|
| 71 |
+
base_url = "https://abrahamdw882-wan2-api.hf.space"
|
| 72 |
+
video_url = f"{base_url}/file/{file_id}.mp4"
|
| 73 |
+
|
| 74 |
return {
|
| 75 |
"status": "success",
|
| 76 |
"model_file": MODEL_FILE,
|
| 77 |
"prompt": request.prompt,
|
| 78 |
"steps": request.steps,
|
| 79 |
+
"video_url": video_url,
|
| 80 |
"note": "Replace this with actual inference code."
|
| 81 |
}
|
| 82 |
|