Ridealist commited on
Commit
68f056c
1 Parent(s): 5ea4cc2

fix: batch_size setting, error handling

Browse files
Files changed (1) hide show
  1. src/obs_eval_gradio.py +12 -12
src/obs_eval_gradio.py CHANGED
@@ -68,12 +68,12 @@ def _process_video(image_file):
68
  return base64Frames
69
 
70
 
71
- def _make_video_batch(image_file, total_batch_percent):
72
 
73
  frames = _process_video(image_file)
74
 
75
  TOTAL_FRAME_COUNT = len(frames)
76
- BATCH_SIZE = 5
77
  TOTAL_BATCH_SIZE = int(TOTAL_FRAME_COUNT * total_batch_percent / 100)
78
  BATCH_STEP = int(TOTAL_FRAME_COUNT / TOTAL_BATCH_SIZE)
79
 
@@ -98,9 +98,9 @@ def _make_video_batch(image_file, total_batch_percent):
98
  return base64FramesBatch
99
 
100
 
101
- def show_batches(image_file, total_batch_size):
102
 
103
- batched_frames = _make_video_batch(image_file, total_batch_size)
104
 
105
  images = []
106
  for i, l in enumerate(batched_frames):
@@ -151,7 +151,7 @@ def call_gpt_vision(api_key, instruction):
151
  full_result.append(result)
152
  except Exception as e:
153
  print(f"Error: {e}")
154
- pass
155
 
156
  if 'full_result' not in global_dict:
157
  global_dict.setdefault('full_result', full_result)
@@ -229,12 +229,12 @@ def main():
229
  label="Upload your video (under 10 second video is the best..!)",
230
  file_types=["video"],
231
  )
232
- # batch_size = gr.Number(
233
- # label="Number of images in one batch",
234
- # value=2,
235
- # minimum=2,
236
- # maximum=5
237
- # )
238
  total_batch_percent = gr.Number(
239
  label="Percentage(%) of batched image frames to total frames",
240
  value=5,
@@ -282,7 +282,7 @@ def main():
282
  output_box_fin_fin = gr.Textbox(label="FINAL EVALUATION", lines=10, interactive=True)
283
 
284
 
285
- process_button.click(fn=validate_api_key, inputs=api_key_input, outputs=None).success(fn=show_batches, inputs=[video_upload, total_batch_percent], outputs=gallery)
286
  submit_button.click(fn=call_gpt_vision, inputs=[api_key_input, instruction_input], outputs=output_box).then(get_full_result, None, output_box_fin)
287
  submit_button_2.click(fn=get_final_anser, inputs=[api_key_input, output_box_fin], outputs=output_box_fin_fin)
288
 
 
68
  return base64Frames
69
 
70
 
71
+ def _make_video_batch(image_file, batch_size, total_batch_percent):
72
 
73
  frames = _process_video(image_file)
74
 
75
  TOTAL_FRAME_COUNT = len(frames)
76
+ BATCH_SIZE = int(batch_size)
77
  TOTAL_BATCH_SIZE = int(TOTAL_FRAME_COUNT * total_batch_percent / 100)
78
  BATCH_STEP = int(TOTAL_FRAME_COUNT / TOTAL_BATCH_SIZE)
79
 
 
98
  return base64FramesBatch
99
 
100
 
101
+ def show_batches(image_file, batch_size, total_batch_percent):
102
 
103
+ batched_frames = _make_video_batch(image_file, batch_size, total_batch_percent)
104
 
105
  images = []
106
  for i, l in enumerate(batched_frames):
 
151
  full_result.append(result)
152
  except Exception as e:
153
  print(f"Error: {e}")
154
+ yield f'### BATCH_{idx+1}\n' + "-"*50 + "\n" + f"Error: {e}" + "\n" + "-"*50
155
 
156
  if 'full_result' not in global_dict:
157
  global_dict.setdefault('full_result', full_result)
 
229
  label="Upload your video (under 10 second video is the best..!)",
230
  file_types=["video"],
231
  )
232
+ batch_size = gr.Number(
233
+ label="Number of images in one batch",
234
+ value=2,
235
+ minimum=2,
236
+ maximum=5
237
+ )
238
  total_batch_percent = gr.Number(
239
  label="Percentage(%) of batched image frames to total frames",
240
  value=5,
 
282
  output_box_fin_fin = gr.Textbox(label="FINAL EVALUATION", lines=10, interactive=True)
283
 
284
 
285
+ process_button.click(fn=validate_api_key, inputs=api_key_input, outputs=None).success(fn=show_batches, inputs=[video_upload, batch_size, total_batch_percent], outputs=gallery)
286
  submit_button.click(fn=call_gpt_vision, inputs=[api_key_input, instruction_input], outputs=output_box).then(get_full_result, None, output_box_fin)
287
  submit_button_2.click(fn=get_final_anser, inputs=[api_key_input, output_box_fin], outputs=output_box_fin_fin)
288