Ridealist commited on
Commit
8a0e7e1
1 Parent(s): 9d7f7b1

refactor: apply tqdm, global_dict func, add some info texts

Browse files
Files changed (1) hide show
  1. src/obs_eval_gradio.py +18 -6
src/obs_eval_gradio.py CHANGED
@@ -94,7 +94,11 @@ def _make_video_batch(image_file, batch_size, total_batch_percent):
94
  # assert len(batch) <= BATCH_SIZE
95
  print(f'##{idx} - batch_size: {len(batch)}')
96
 
97
- global_dict.setdefault('batched_frames', base64FramesBatch)
 
 
 
 
98
  return base64FramesBatch
99
 
100
 
@@ -118,13 +122,15 @@ def show_batches(image_file, batch_size, total_batch_percent):
118
  return images
119
 
120
 
121
- def call_gpt_vision(api_key, instruction):
122
  frames = global_dict.get('batched_frames')
123
  openai.api_key = api_key
124
 
125
  full_result = []
 
 
126
 
127
- for idx, batch in enumerate(frames):
128
  PROMPT_MESSAGES = [
129
  {
130
  "role": "system",
@@ -151,7 +157,9 @@ def call_gpt_vision(api_key, instruction):
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)
@@ -160,9 +168,11 @@ def call_gpt_vision(api_key, instruction):
160
 
161
  print(f'### BATCH_{idx+1}')
162
  print('-'*100)
 
 
163
  time.sleep(2)
164
 
165
- yield f'### BATCH_{idx+1}\n' + "-"*50 + "\n" + result.choices[0].message.content + "\n" + "-"*50
166
 
167
 
168
  def get_full_result():
@@ -231,12 +241,14 @@ def main():
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,
241
  minimum=5,
242
  maximum=20,
 
94
  # assert len(batch) <= BATCH_SIZE
95
  print(f'##{idx} - batch_size: {len(batch)}')
96
 
97
+ if 'batched_frames' not in global_dict:
98
+ global_dict.setdefault('batched_frames', base64FramesBatch)
99
+ else:
100
+ global_dict['batched_frames'] = base64FramesBatch
101
+
102
  return base64FramesBatch
103
 
104
 
 
122
  return images
123
 
124
 
125
+ def call_gpt_vision(api_key, instruction, progress=gr.Progress()):
126
  frames = global_dict.get('batched_frames')
127
  openai.api_key = api_key
128
 
129
  full_result = []
130
+ full_text = ""
131
+ idx = 0
132
 
133
+ for batch in progress.tqdm(frames):
134
  PROMPT_MESSAGES = [
135
  {
136
  "role": "system",
 
157
  full_result.append(result)
158
  except Exception as e:
159
  print(f"Error: {e}")
160
+ full_text += f'### BATCH_{idx+1}\n' + "-"*50 + "\n" + f"Error: {e}" + "\n" + "-"*50 + "\n"
161
+ idx += 1
162
+ pass
163
 
164
  if 'full_result' not in global_dict:
165
  global_dict.setdefault('full_result', full_result)
 
168
 
169
  print(f'### BATCH_{idx+1}')
170
  print('-'*100)
171
+ full_text += f'### BATCH_{idx+1}\n' + "-"*50 + "\n" + result.choices[0].message.content + "\n" + "-"*50 + "\n"
172
+ idx += 1
173
  time.sleep(2)
174
 
175
+ return full_text
176
 
177
 
178
  def get_full_result():
 
241
  )
242
  batch_size = gr.Number(
243
  label="Number of images in one batch",
244
+ info="(2<=N<=5)"
245
+ value=5,
246
  minimum=2,
247
  maximum=5
248
  )
249
  total_batch_percent = gr.Number(
250
  label="Percentage(%) of batched image frames to total frames",
251
+ info="(5<=P<=20)"
252
  value=5,
253
  minimum=5,
254
  maximum=20,