abrahamdw882 commited on
Commit
0f32810
·
verified ·
1 Parent(s): 4854058

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -15
app.py CHANGED
@@ -5,9 +5,10 @@ from pydantic import BaseModel
5
  import uvicorn
6
  import os
7
  import uuid
 
 
8
 
9
- # GGUF & video libraries
10
- from gguf_runtime import GGUFModel # Make sure gguf-runtime is installed
11
  from moviepy.editor import ImageSequenceClip
12
 
13
  app = FastAPI(title="WAN2 GGUF API", version="1.0")
@@ -17,13 +18,12 @@ MODEL_REPO = "calcuis/wan2-gguf"
17
  MODEL_FILE = "wan2.2-animate-14b-q4_0.gguf"
18
  MODEL_DIR = "models"
19
  OUTPUT_DIR = "outputs"
 
20
 
21
  os.makedirs(MODEL_DIR, exist_ok=True)
22
  os.makedirs(OUTPUT_DIR, exist_ok=True)
23
 
24
  # -------------------- Download model --------------------
25
- from huggingface_hub import hf_hub_download
26
-
27
  model_path = hf_hub_download(
28
  repo_id=MODEL_REPO,
29
  filename=MODEL_FILE,
@@ -31,16 +31,30 @@ model_path = hf_hub_download(
31
  )
32
  print("✅ Model downloaded to:", model_path)
33
 
34
- # -------------------- Load GGUF model --------------------
35
- print("Loading WAN2 GGUF model...")
36
- wan2_model = GGUFModel(model_path)
37
- print("✅ WAN2 model loaded")
38
-
39
  # -------------------- Request schema --------------------
40
  class PromptRequest(BaseModel):
41
  prompt: str
42
  steps: int = 20
43
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
  # -------------------- Routes --------------------
45
  @app.get("/")
46
  def root():
@@ -58,12 +72,11 @@ def generate_video(request: PromptRequest):
58
  file_id = str(uuid.uuid4())
59
  file_path = os.path.join(OUTPUT_DIR, f"{file_id}.mp4")
60
 
61
- # ---- WAN2 inference ----
62
- # This generates frames from prompt
63
- frames = wan2_model.generate_video(
64
- prompt=request.prompt,
65
- steps=request.steps
66
- )
67
 
68
  # ---- Save frames as MP4 ----
69
  clip = ImageSequenceClip(frames, fps=12)
 
5
  import uvicorn
6
  import os
7
  import uuid
8
+ import subprocess
9
+ import json
10
 
11
+ from huggingface_hub import hf_hub_download
 
12
  from moviepy.editor import ImageSequenceClip
13
 
14
  app = FastAPI(title="WAN2 GGUF API", version="1.0")
 
18
  MODEL_FILE = "wan2.2-animate-14b-q4_0.gguf"
19
  MODEL_DIR = "models"
20
  OUTPUT_DIR = "outputs"
21
+ NODE_CLI = "gguf-node-cli.js" # Path to your gguf-node CLI
22
 
23
  os.makedirs(MODEL_DIR, exist_ok=True)
24
  os.makedirs(OUTPUT_DIR, exist_ok=True)
25
 
26
  # -------------------- Download model --------------------
 
 
27
  model_path = hf_hub_download(
28
  repo_id=MODEL_REPO,
29
  filename=MODEL_FILE,
 
31
  )
32
  print("✅ Model downloaded to:", model_path)
33
 
 
 
 
 
 
34
  # -------------------- Request schema --------------------
35
  class PromptRequest(BaseModel):
36
  prompt: str
37
  steps: int = 20
38
 
39
+ # -------------------- Helper: GGUF Node CLI --------------------
40
+ def generate_frames_with_node(prompt, steps=20):
41
+ """
42
+ Calls gguf-node CLI to generate frames.
43
+ CLI should output JSON array of frame image paths.
44
+ """
45
+ try:
46
+ result = subprocess.run(
47
+ ["node", NODE_CLI, "--model", model_path, "--prompt", prompt, "--steps", str(steps)],
48
+ capture_output=True,
49
+ text=True,
50
+ check=True
51
+ )
52
+ frames = json.loads(result.stdout)
53
+ return frames
54
+ except subprocess.CalledProcessError as e:
55
+ print("Error calling gguf-node:", e.stderr)
56
+ return []
57
+
58
  # -------------------- Routes --------------------
59
  @app.get("/")
60
  def root():
 
72
  file_id = str(uuid.uuid4())
73
  file_path = os.path.join(OUTPUT_DIR, f"{file_id}.mp4")
74
 
75
+ # ---- WAN2 inference via Node CLI ----
76
+ frames = generate_frames_with_node(request.prompt, request.steps)
77
+
78
+ if not frames:
79
+ return {"status": "error", "message": "Failed to generate frames"}
 
80
 
81
  # ---- Save frames as MP4 ----
82
  clip = ImageSequenceClip(frames, fps=12)