uriva commited on
Commit
f2edce9
·
1 Parent(s): 6d31c91

Change API output to gr.File for proper file serving

Browse files
Files changed (1) hide show
  1. app.py +8 -10
app.py CHANGED
@@ -204,23 +204,23 @@ def _process_video_api_impl(
204
  file_path, gazing_ratio, task_loss_requirement, output_fps, progress=None
205
  ):
206
  """API-friendly endpoint that takes a file path string instead of gr.File.
207
- Returns only the gazing video path for programmatic use."""
208
  if not file_path or not os.path.exists(file_path):
209
- return "Error: file not found"
210
 
211
  metadata = extract_metadata(file_path)
212
  if metadata[1] is None:
213
- return "Error: could not read file"
214
 
215
  _, tmp_path, total_frames, fps, _, _ = metadata
216
 
217
- yield "Loading model..."
218
 
219
  if progress:
220
  progress(0.0, desc="Loading model...")
221
  setup = get_model(device)
222
 
223
- yield "Processing video..."
224
 
225
  if progress:
226
  progress(0.1, desc="Processing video...")
@@ -239,9 +239,7 @@ def _process_video_api_impl(
239
  progress_callback=update_progress,
240
  spatial_batch_size=2,
241
  ):
242
- yield "Processing..."
243
-
244
- yield "Saving output..."
245
 
246
  fps_to_use = output_fps if output_fps is not None else results["fps"]
247
 
@@ -249,7 +247,7 @@ def _process_video_api_impl(
249
  save_video(results["gazing_frames"], gazing_file.name, fps_to_use)
250
  gazing_file.close()
251
 
252
- yield gazing_file.name
253
 
254
 
255
  if ZEROGPU_AVAILABLE:
@@ -461,7 +459,7 @@ with gr.Blocks(title="AutoGaze Demo", delete_cache=(86400, 86400)) as demo:
461
  )
462
  api_output_fps = gr.Number(label="Output FPS", value=None)
463
  api_button = gr.Button("Process (API)")
464
- api_result = gr.Textbox(label="Result Path")
465
  api_button.click(
466
  fn=process_video_api,
467
  inputs=[api_file_path, api_gazing_ratio, api_task_loss, api_output_fps],
 
204
  file_path, gazing_ratio, task_loss_requirement, output_fps, progress=None
205
  ):
206
  """API-friendly endpoint that takes a file path string instead of gr.File.
207
+ Returns the gazing video as a gr.File output for proper file serving."""
208
  if not file_path or not os.path.exists(file_path):
209
+ raise gr.Error("file not found")
210
 
211
  metadata = extract_metadata(file_path)
212
  if metadata[1] is None:
213
+ raise gr.Error("could not read file")
214
 
215
  _, tmp_path, total_frames, fps, _, _ = metadata
216
 
217
+ yield gr.update()
218
 
219
  if progress:
220
  progress(0.0, desc="Loading model...")
221
  setup = get_model(device)
222
 
223
+ yield gr.update()
224
 
225
  if progress:
226
  progress(0.1, desc="Processing video...")
 
239
  progress_callback=update_progress,
240
  spatial_batch_size=2,
241
  ):
242
+ yield gr.update()
 
 
243
 
244
  fps_to_use = output_fps if output_fps is not None else results["fps"]
245
 
 
247
  save_video(results["gazing_frames"], gazing_file.name, fps_to_use)
248
  gazing_file.close()
249
 
250
+ yield gr.File(value=gazing_file.name)
251
 
252
 
253
  if ZEROGPU_AVAILABLE:
 
459
  )
460
  api_output_fps = gr.Number(label="Output FPS", value=None)
461
  api_button = gr.Button("Process (API)")
462
+ api_result = gr.File(label="Result")
463
  api_button.click(
464
  fn=process_video_api,
465
  inputs=[api_file_path, api_gazing_ratio, api_task_loss, api_output_fps],