jiadisu commited on
Commit
b397c92
·
1 Parent(s): 8f6bbb3

update processing

Browse files
Files changed (1) hide show
  1. app.py +24 -9
app.py CHANGED
@@ -10,6 +10,7 @@ Architecture:
10
  """
11
 
12
  import os
 
13
 
14
  import gradio as gr
15
  from openai import OpenAI
@@ -134,18 +135,32 @@ def run_generation(image, prompt, seed, seconds):
134
  yield None, "", str(e)
135
  return
136
 
137
- # Yield so the user sees the enhanced prompt; Gradio's timer runs during Step 2
138
  yield None, enhanced, "Generating video ..."
139
 
140
- # Step 2: Send to router
 
141
  print(f"[Generate] Sending to router ...")
142
- result = generate(
143
- image=image,
144
- video_prompt=enhanced,
145
- seed=int(seed),
146
- output_dir=OUTPUT_DIR,
147
- seconds=int(seconds),
148
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
149
 
150
  if result["error"]:
151
  print(f"[Generate] Error from router: {result['error']}")
 
10
  """
11
 
12
  import os
13
+ import threading
14
 
15
  import gradio as gr
16
  from openai import OpenAI
 
135
  yield None, "", str(e)
136
  return
137
 
138
+ # Yield so the user sees the enhanced prompt
139
  yield None, enhanced, "Generating video ..."
140
 
141
+ # Step 2: Send to router in background thread, yield periodically to keep
142
+ # Gradio's processing indicator alive (SSE connection drops if idle too long)
143
  print(f"[Generate] Sending to router ...")
144
+ gen_result = [None]
145
+ gen_done = threading.Event()
146
+
147
+ def _do_generate():
148
+ gen_result[0] = generate(
149
+ image=image,
150
+ video_prompt=enhanced,
151
+ seed=int(seed),
152
+ output_dir=OUTPUT_DIR,
153
+ seconds=int(seconds),
154
+ )
155
+ gen_done.set()
156
+
157
+ threading.Thread(target=_do_generate, daemon=True).start()
158
+
159
+ # Keep yielding same values every 10s to maintain the connection
160
+ while not gen_done.wait(timeout=10):
161
+ yield None, enhanced, "Generating video ..."
162
+
163
+ result = gen_result[0]
164
 
165
  if result["error"]:
166
  print(f"[Generate] Error from router: {result['error']}")