MohamedRashad commited on
Commit
2eac11a
·
1 Parent(s): c79a44b

Enhance error handling in process function for input image validation and improve user feedback

Browse files
Files changed (1) hide show
  1. app.py +42 -19
app.py CHANGED
@@ -279,31 +279,54 @@ def worker(input_image, prompt, n_prompt, seed, total_second_length, latent_wind
279
 
280
  def process(input_image, prompt, n_prompt, seed, total_second_length, latent_window_size, steps, cfg, gs, rs, gpu_memory_preservation, use_teacache):
281
  global stream
282
- assert input_image is not None, 'No input image!'
283
-
284
- yield None, None, '', '', gr.update(interactive=False), gr.update(interactive=True)
285
-
286
- stream = AsyncStream()
 
 
 
 
 
 
 
 
 
287
 
288
- async_run(worker, input_image, prompt, n_prompt, seed, total_second_length, latent_window_size, steps, cfg, gs, rs, gpu_memory_preservation, use_teacache)
289
 
290
- output_filename = None
291
 
292
- while True:
293
- flag, data = stream.output_queue.next()
294
 
295
- if flag == 'file':
296
- output_filename = data
297
- yield output_filename, gr.update(), gr.update(), gr.update(), gr.update(interactive=False), gr.update(interactive=True)
298
 
299
- if flag == 'progress':
300
- preview, desc, html = data
301
- yield gr.update(), gr.update(visible=True, value=preview), desc, html, gr.update(interactive=False), gr.update(interactive=True)
302
 
303
- if flag == 'end':
304
- yield output_filename, gr.update(visible=False), gr.update(), '', gr.update(interactive=True), gr.update(interactive=False)
305
- break
 
 
 
 
306
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
307
 
308
  def end_process():
309
  stream.input_queue.push('end')
@@ -354,7 +377,7 @@ with gr.Blocks(css=css) as app:
354
 
355
  total_second_length = gr.Slider(label="Total Video Length (Seconds)", minimum=1, maximum=120, value=5, step=0.1)
356
  latent_window_size = gr.Slider(label="Latent Window Size", minimum=1, maximum=33, value=9, step=1, visible=False) # Should not change
357
- steps = gr.Slider(label="Steps", minimum=1, maximum=100, value=10, step=1, info='Changing this value is not recommended.')
358
 
359
  cfg = gr.Slider(label="CFG Scale", minimum=1.0, maximum=32.0, value=1.0, step=0.01, visible=False) # Should not change
360
  gs = gr.Slider(label="Distilled CFG Scale", minimum=1.0, maximum=32.0, value=10.0, step=0.01, info='Changing this value is not recommended.')
 
279
 
280
  def process(input_image, prompt, n_prompt, seed, total_second_length, latent_window_size, steps, cfg, gs, rs, gpu_memory_preservation, use_teacache):
281
  global stream
282
+
283
+ try:
284
+ # Check for valid input image
285
+ if input_image is None:
286
+ yield None, None, '', 'Error: No input image provided!', gr.update(interactive=True), gr.update(interactive=False)
287
+ return
288
+
289
+ # Check if input_image is valid
290
+ if isinstance(input_image, str):
291
+ # Path was provided but file might not exist
292
+ import os
293
+ if not os.path.exists(input_image):
294
+ yield None, None, '', f'Error: Image file not found at path: {input_image}', gr.update(interactive=True), gr.update(interactive=False)
295
+ return
296
 
297
+ yield None, None, '', '', gr.update(interactive=False), gr.update(interactive=True)
298
 
299
+ stream = AsyncStream()
300
 
301
+ async_run(worker, input_image, prompt, n_prompt, seed, total_second_length, latent_window_size, steps, cfg, gs, rs, gpu_memory_preservation, use_teacache)
 
302
 
303
+ output_filename = None
 
 
304
 
305
+ while True:
306
+ flag, data = stream.output_queue.next()
 
307
 
308
+ if flag == 'file':
309
+ output_filename = data
310
+ yield output_filename, gr.update(), gr.update(), gr.update(), gr.update(interactive=False), gr.update(interactive=True)
311
+
312
+ if flag == 'progress':
313
+ preview, desc, html = data
314
+ yield gr.update(), gr.update(visible=True, value=preview), desc, html, gr.update(interactive=False), gr.update(interactive=True)
315
 
316
+ if flag == 'end':
317
+ yield output_filename, gr.update(visible=False), gr.update(), '', gr.update(interactive=True), gr.update(interactive=False)
318
+ break
319
+
320
+ except FileNotFoundError as e:
321
+ error_message = f"Error: Could not find the input image file. Please try a different image or filename without special characters.\nDetails: {str(e)}"
322
+ print(error_message)
323
+ yield None, None, '', error_message, gr.update(interactive=True), gr.update(interactive=False)
324
+
325
+ except Exception as e:
326
+ error_message = f"An unexpected error occurred: {str(e)}"
327
+ print(error_message)
328
+ traceback.print_exc()
329
+ yield None, None, '', error_message, gr.update(interactive=True), gr.update(interactive=False)
330
 
331
  def end_process():
332
  stream.input_queue.push('end')
 
377
 
378
  total_second_length = gr.Slider(label="Total Video Length (Seconds)", minimum=1, maximum=120, value=5, step=0.1)
379
  latent_window_size = gr.Slider(label="Latent Window Size", minimum=1, maximum=33, value=9, step=1, visible=False) # Should not change
380
+ steps = gr.Slider(label="Steps", minimum=1, maximum=100, value=25, step=1, info='Changing this value is not recommended.')
381
 
382
  cfg = gr.Slider(label="CFG Scale", minimum=1.0, maximum=32.0, value=1.0, step=0.01, visible=False) # Should not change
383
  gs = gr.Slider(label="Distilled CFG Scale", minimum=1.0, maximum=32.0, value=10.0, step=0.01, info='Changing this value is not recommended.')