txarst commited on
Commit
2e371ef
·
1 Parent(s): 0bb4f33

api output fix

Browse files
Files changed (1) hide show
  1. gradio_app.py +19 -2
gradio_app.py CHANGED
@@ -249,6 +249,12 @@ def process_media_unified(media_input, pupil_selection, tv_model, blink_detectio
249
  tuple: (result_image, result_text)
250
  """
251
  try:
 
 
 
 
 
 
252
  # Check if input is an image or video
253
  if hasattr(media_input, 'name'):
254
  # It's a file object (video)
@@ -262,9 +268,20 @@ def process_media_unified(media_input, pupil_selection, tv_model, blink_detectio
262
  from PIL import Image
263
  image = Image.open(file_path)
264
  return process_image_gradio(image, pupil_selection, tv_model, blink_detection)
 
 
 
 
 
265
  else:
266
- # It's a PIL Image
267
- return process_image_gradio(media_input, pupil_selection, tv_model, blink_detection)
 
 
 
 
 
 
268
 
269
  except Exception as e:
270
  error_msg = f"Error processing media: {str(e)}"
 
249
  tuple: (result_image, result_text)
250
  """
251
  try:
252
+ # Handle None input
253
+ if media_input is None:
254
+ from PIL import Image
255
+ error_img = Image.new('RGB', (400, 200), 'white')
256
+ return error_img, "No media input provided. Please upload an image or video."
257
+
258
  # Check if input is an image or video
259
  if hasattr(media_input, 'name'):
260
  # It's a file object (video)
 
268
  from PIL import Image
269
  image = Image.open(file_path)
270
  return process_image_gradio(image, pupil_selection, tv_model, blink_detection)
271
+ else:
272
+ # Unknown file type
273
+ from PIL import Image
274
+ error_img = Image.new('RGB', (400, 200), 'white')
275
+ return error_img, f"Unsupported file type: {file_path}"
276
  else:
277
+ # It's a PIL Image or other format
278
+ if media_input is not None:
279
+ return process_image_gradio(media_input, pupil_selection, tv_model, blink_detection)
280
+ else:
281
+ # Fallback for any other None case
282
+ from PIL import Image
283
+ error_img = Image.new('RGB', (400, 200), 'white')
284
+ return error_img, "Invalid media input format."
285
 
286
  except Exception as e:
287
  error_msg = f"Error processing media: {str(e)}"