Diwashbarla commited on
Commit
f89392c
·
verified ·
1 Parent(s): 20cdfff

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -24
app.py CHANGED
@@ -31,7 +31,7 @@ def _inject_params(prompt: Dict[str, Any], r: T2VReq) -> Dict[str, Any]:
31
  elif class_type == "EmptyLatentImage":
32
  if r.width is not None: node_data["inputs"]["width"] = r.width
33
  if r.height is not None: node_data["inputs"]["height"] = r.height
34
- if r.length is not None: node_data["inputs"]["batch_size"] = r.length # batch_size ही Frames होते हैं
35
  elif class_type == "CreateVideo":
36
  if r.fps is not None: node_data["inputs"]["fps"] = r.fps
37
  elif class_type == "SaveVideo":
@@ -58,14 +58,18 @@ def _get_history(prompt_id: str, token: str) -> Dict[str, Any]:
58
  return r.json().get(prompt_id, {})
59
 
60
  def _extract_video_from_history(history: Dict[str, Any]) -> Dict[str, str]:
 
 
 
61
  outputs = history.get("outputs", {})
62
  for _, node_out in outputs.items():
63
  for key in ("images", "videos", "files", "gifs"):
64
  if key in node_out:
65
  for it in node_out[key]:
66
- if it.get("filename", "").lower().endswith((".mp4", ".webm", ".gif", ".mov")):
67
- return {"filename": it["filename"], "subfolder": it.get("subfolder", ""), "type": it.get("type", "")}
68
- raise RuntimeError("No video file found in history outputs")
 
69
 
70
  sample_prompts = [
71
  "A majestic cinematic shot of Lord Shiva meditating in the snowy Himalayas, cosmic universe and stars swirling around him, highly detailed, photorealistic",
@@ -127,26 +131,37 @@ with gr.Blocks(title="T2V UI", theme=gr.themes.Soft(primary_hue="blue")) as demo
127
  p = 0
128
  last_emit = -1
129
 
130
- while True:
131
- out = ws.recv()
132
- if isinstance(out, bytes):
133
- continue
134
- msg = json.loads(out)
135
- if msg.get("type") == "executing":
136
- data = msg.get("data", {})
137
- if data.get("prompt_id") != prompt_id:
138
  continue
139
- node = data.get("node")
140
- if node is None:
141
- break
142
- if node not in seen:
143
- seen.add(node)
144
- p = min(99, int(len(seen) / total_nodes * 100))
145
- if p != last_emit:
146
- last_emit = p
147
- yield p, None
148
- ws.close()
149
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
150
  hist = _get_history(prompt_id, req.token)
151
  info = _extract_video_from_history(hist)
152
  q = urlencode(info)
@@ -161,4 +176,3 @@ with gr.Blocks(title="T2V UI", theme=gr.themes.Soft(primary_hue="blue")) as demo
161
 
162
  if __name__ == "__main__":
163
  demo.queue().launch(server_name="0.0.0.0", server_port=7860)
164
-
 
31
  elif class_type == "EmptyLatentImage":
32
  if r.width is not None: node_data["inputs"]["width"] = r.width
33
  if r.height is not None: node_data["inputs"]["height"] = r.height
34
+ if r.length is not None: node_data["inputs"]["batch_size"] = r.length
35
  elif class_type == "CreateVideo":
36
  if r.fps is not None: node_data["inputs"]["fps"] = r.fps
37
  elif class_type == "SaveVideo":
 
58
  return r.json().get(prompt_id, {})
59
 
60
  def _extract_video_from_history(history: Dict[str, Any]) -> Dict[str, str]:
61
+ if "outputs" not in history:
62
+ raise RuntimeError(f"Server crashed before creating outputs! History dump: {json.dumps(history)}")
63
+
64
  outputs = history.get("outputs", {})
65
  for _, node_out in outputs.items():
66
  for key in ("images", "videos", "files", "gifs"):
67
  if key in node_out:
68
  for it in node_out[key]:
69
+ if isinstance(it, dict) and it.get("filename", "").lower().endswith((".mp4", ".webm", ".gif", ".mov")):
70
+ return {"filename": it["filename"], "subfolder": it.get("subfolder", ""), "type": it.get("type", "output")}
71
+
72
+ raise RuntimeError(f"Video not found! Node outputs were: {json.dumps(outputs)}")
73
 
74
  sample_prompts = [
75
  "A majestic cinematic shot of Lord Shiva meditating in the snowy Himalayas, cosmic universe and stars swirling around him, highly detailed, photorealistic",
 
131
  p = 0
132
  last_emit = -1
133
 
134
+ try:
135
+ while True:
136
+ out = ws.recv()
137
+ if isinstance(out, bytes):
 
 
 
 
138
  continue
139
+ msg = json.loads(out)
140
+
141
+ # यहाँ हम असली Error पकड़ेंगे!
142
+ if msg.get("type") == "execution_error":
143
+ ws.close()
144
+ err_data = msg.get("data", {})
145
+ node_type = err_data.get("node_type", "Unknown Node")
146
+ exc_msg = err_data.get("exception_message", "Unknown Error")
147
+ raise gr.Error(f"❌ Server Crashed at '{node_type}': {exc_msg}")
148
+
149
+ if msg.get("type") == "executing":
150
+ data = msg.get("data", {})
151
+ if data.get("prompt_id") != prompt_id:
152
+ continue
153
+ node = data.get("node")
154
+ if node is None:
155
+ break
156
+ if node not in seen:
157
+ seen.add(node)
158
+ p = min(99, int(len(seen) / total_nodes * 100))
159
+ if p != last_emit:
160
+ last_emit = p
161
+ yield p, None
162
+ finally:
163
+ ws.close()
164
+
165
  hist = _get_history(prompt_id, req.token)
166
  info = _extract_video_from_history(hist)
167
  q = urlencode(info)
 
176
 
177
  if __name__ == "__main__":
178
  demo.queue().launch(server_name="0.0.0.0", server_port=7860)