txarst commited on
Commit
229daef
·
1 Parent(s): 696913d

gradio base64 fix02

Browse files
Files changed (1) hide show
  1. gradio_app.py +9 -9
gradio_app.py CHANGED
@@ -365,17 +365,17 @@ def process_media_unified(media_input, pupil_selection, tv_model, blink_detectio
365
  tuple: (result_image, result_text)
366
  """
367
  try:
368
- # Handle None input
369
- if media_input is None:
370
  from PIL import Image
371
  error_img = Image.new('RGB', (400, 200), 'white')
372
- return error_img, "No media input provided. Please upload an image or video."
373
 
374
- # Check if input is a base64 data URL
375
- if isinstance(media_input, str) and media_input.startswith('data:'):
376
- return process_base64_media(media_input, pupil_selection, tv_model, blink_detection)
377
 
378
- # Check if input is an image or video
379
  if hasattr(media_input, 'name'):
380
  # It's a file object (video)
381
  file_path = media_input.name
@@ -511,8 +511,8 @@ def create_gradio_interface():
511
  api_text_output = gr.Textbox(label="Analysis Results", lines=10)
512
 
513
  api_submit.click(
514
- fn=process_media_unified_with_fallback,
515
- inputs=[api_media_input, api_file_input, api_pupil_selection, api_model, api_blink_detection],
516
  outputs=[api_output, api_text_output]
517
  )
518
 
 
365
  tuple: (result_image, result_text)
366
  """
367
  try:
368
+ # Handle None or empty input
369
+ if media_input is None or (isinstance(media_input, str) and not media_input.strip()):
370
  from PIL import Image
371
  error_img = Image.new('RGB', (400, 200), 'white')
372
+ return error_img, "No media input provided. Please upload an image or video or provide a base64 data URL."
373
 
374
+ # Check if input is a base64 data URL (string input)
375
+ if isinstance(media_input, str) and media_input.strip().startswith('data:'):
376
+ return process_base64_media(media_input.strip(), pupil_selection, tv_model, blink_detection)
377
 
378
+ # Check if input is an image or video file object
379
  if hasattr(media_input, 'name'):
380
  # It's a file object (video)
381
  file_path = media_input.name
 
511
  api_text_output = gr.Textbox(label="Analysis Results", lines=10)
512
 
513
  api_submit.click(
514
+ fn=process_media_unified,
515
+ inputs=[api_media_input, api_pupil_selection, api_model, api_blink_detection],
516
  outputs=[api_output, api_text_output]
517
  )
518