Upload server.py with huggingface_hub
Browse files
server.py
CHANGED
|
@@ -51,7 +51,8 @@ def generate():
|
|
| 51 |
from diffusers.utils import export_to_video
|
| 52 |
|
| 53 |
data = request.get_json(force=True)
|
| 54 |
-
|
|
|
|
| 55 |
params = data.get("parameters", {})
|
| 56 |
|
| 57 |
num_frames = int(params.get("num_frames", 25))
|
|
@@ -94,12 +95,21 @@ def generate():
|
|
| 94 |
"format": "mp4",
|
| 95 |
"frames": len(frames),
|
| 96 |
"duration": duration,
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
})
|
| 98 |
except Exception as e:
|
| 99 |
tb = traceback.format_exc()
|
| 100 |
-
print(f"[video] ERROR: {e}", flush=True)
|
| 101 |
-
|
| 102 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
|
| 104 |
if __name__ == "__main__":
|
| 105 |
load_model()
|
|
|
|
| 51 |
from diffusers.utils import export_to_video
|
| 52 |
|
| 53 |
data = request.get_json(force=True)
|
| 54 |
+
# Support both HF format (inputs) and backend format (prompt)
|
| 55 |
+
prompt = data.get("inputs", "") or data.get("prompt", "")
|
| 56 |
params = data.get("parameters", {})
|
| 57 |
|
| 58 |
num_frames = int(params.get("num_frames", 25))
|
|
|
|
| 95 |
"format": "mp4",
|
| 96 |
"frames": len(frames),
|
| 97 |
"duration": duration,
|
| 98 |
+
"success": True,
|
| 99 |
+
"video_base64": video_b64,
|
| 100 |
+
"duration_seconds": duration,
|
| 101 |
+
"model": "wan2.2-ti2v-5b",
|
| 102 |
})
|
| 103 |
except Exception as e:
|
| 104 |
tb = traceback.format_exc()
|
| 105 |
+
print(f"[video] ERROR: {e}\n{tb}", flush=True)
|
| 106 |
+
return jsonify({"error": str(e), "traceback": tb, "success": False}), 500
|
| 107 |
+
|
| 108 |
+
# Also add /api/generate-video route for backend compatibility
|
| 109 |
+
@app.route("/api/generate-video", methods=["POST"])
|
| 110 |
+
def api_generate_video():
|
| 111 |
+
"""Handle the backend's /api/generate-video format by forwarding to generate()"""
|
| 112 |
+
return generate()
|
| 113 |
|
| 114 |
if __name__ == "__main__":
|
| 115 |
load_model()
|