GlazedDon0t commited on
Commit
4d2be90
·
1 Parent(s): 89de692
Files changed (1) hide show
  1. src/inference_logic.py +20 -8
src/inference_logic.py CHANGED
@@ -274,8 +274,20 @@ async def run_gemini_labeling_pipeline(video_path: str, caption: str, transcript
274
  uploaded_file = None
275
  is_text_only = False
276
  if video_path and os.path.exists(video_path):
 
277
  uploaded_file = await loop.run_in_executor(None, lambda: genai_legacy.upload_file(path=video_path))
278
- while uploaded_file.state.name == "PROCESSING": await asyncio.sleep(2)
 
 
 
 
 
 
 
 
 
 
 
279
  else: is_text_only = True
280
 
281
  active_tools =[]
@@ -313,8 +325,8 @@ async def run_gemini_labeling_pipeline(video_path: str, caption: str, transcript
313
  f"{toon_schema}"
314
  )
315
  save_debug_log(request_id, 'prompt', prompt_text, attempt, 'reprompt')
316
- inputs = [prompt_text]
317
- if uploaded_file: inputs.append(uploaded_file)
318
  response = await loop.run_in_executor(None, lambda: model.generate_content(inputs, generation_config={"temperature": 0.2}))
319
  raw_text = response.text
320
  save_debug_log(request_id, 'response', raw_text, attempt, 'reprompt')
@@ -325,8 +337,8 @@ async def run_gemini_labeling_pipeline(video_path: str, caption: str, transcript
325
 
326
  macro_prompt = FCOT_MACRO_PROMPT.format(system_persona=system_persona, caption=caption, transcript=transcript)
327
  save_debug_log(request_id, 'prompt', macro_prompt, attempt, 'fcot_macro')
328
- inputs1 =[macro_prompt]
329
- if uploaded_file: inputs1.insert(0, uploaded_file)
330
  res1 = await loop.run_in_executor(None, lambda: chat.send_message(inputs1))
331
  macro_hypothesis = res1.text
332
  save_debug_log(request_id, 'response', macro_hypothesis, attempt, 'fcot_macro')
@@ -354,8 +366,8 @@ async def run_gemini_labeling_pipeline(video_path: str, caption: str, transcript
354
  prompt_used = prompt_text
355
  if is_text_only: prompt_text = "NOTE: Text Analysis Only.\n" + prompt_text
356
  save_debug_log(request_id, 'prompt', prompt_text, attempt, f'standard_{reasoning_method}')
357
- inputs = [prompt_text]
358
- if uploaded_file: inputs.append(uploaded_file)
359
  response = await loop.run_in_executor(None, lambda: model.generate_content(inputs, generation_config={"temperature": 0.1}))
360
  raw_text = response.text
361
  save_debug_log(request_id, 'response', raw_text, attempt, f'standard_{reasoning_method}')
@@ -462,7 +474,7 @@ async def run_vertex_labeling_pipeline(video_path: str, caption: str, transcript
462
  )
463
 
464
  save_debug_log(request_id, 'prompt', prompt_text, attempt, 'reprompt')
465
- contents = [prompt_text]
466
  if video_part: contents.insert(0, video_part)
467
 
468
  response = await loop.run_in_executor(None, lambda: client.models.generate_content(model=model_name, contents=contents, config=config))
 
274
  uploaded_file = None
275
  is_text_only = False
276
  if video_path and os.path.exists(video_path):
277
+ yield f"data: - Uploading video to Gemini API...\n\n"
278
  uploaded_file = await loop.run_in_executor(None, lambda: genai_legacy.upload_file(path=video_path))
279
+
280
+ # Continuously poll the API for the updated state
281
+ while True:
282
+ curr_file = await loop.run_in_executor(None, lambda: genai_legacy.get_file(uploaded_file.name))
283
+ if curr_file.state.name == "PROCESSING":
284
+ yield f"data: - Waiting for Gemini to process the video...\n\n"
285
+ await asyncio.sleep(3)
286
+ elif curr_file.state.name == "FAILED":
287
+ yield f"data: - Gemini Video Processing FAILED.\n\n"
288
+ break
289
+ else:
290
+ break
291
  else: is_text_only = True
292
 
293
  active_tools =[]
 
325
  f"{toon_schema}"
326
  )
327
  save_debug_log(request_id, 'prompt', prompt_text, attempt, 'reprompt')
328
+ inputs =[prompt_text]
329
+ if uploaded_file and uploaded_file.state.name != "FAILED": inputs.append(uploaded_file)
330
  response = await loop.run_in_executor(None, lambda: model.generate_content(inputs, generation_config={"temperature": 0.2}))
331
  raw_text = response.text
332
  save_debug_log(request_id, 'response', raw_text, attempt, 'reprompt')
 
337
 
338
  macro_prompt = FCOT_MACRO_PROMPT.format(system_persona=system_persona, caption=caption, transcript=transcript)
339
  save_debug_log(request_id, 'prompt', macro_prompt, attempt, 'fcot_macro')
340
+ inputs1 = [macro_prompt]
341
+ if uploaded_file and uploaded_file.state.name != "FAILED": inputs1.insert(0, uploaded_file)
342
  res1 = await loop.run_in_executor(None, lambda: chat.send_message(inputs1))
343
  macro_hypothesis = res1.text
344
  save_debug_log(request_id, 'response', macro_hypothesis, attempt, 'fcot_macro')
 
366
  prompt_used = prompt_text
367
  if is_text_only: prompt_text = "NOTE: Text Analysis Only.\n" + prompt_text
368
  save_debug_log(request_id, 'prompt', prompt_text, attempt, f'standard_{reasoning_method}')
369
+ inputs =[prompt_text]
370
+ if uploaded_file and uploaded_file.state.name != "FAILED": inputs.append(uploaded_file)
371
  response = await loop.run_in_executor(None, lambda: model.generate_content(inputs, generation_config={"temperature": 0.1}))
372
  raw_text = response.text
373
  save_debug_log(request_id, 'response', raw_text, attempt, f'standard_{reasoning_method}')
 
474
  )
475
 
476
  save_debug_log(request_id, 'prompt', prompt_text, attempt, 'reprompt')
477
+ contents =[prompt_text]
478
  if video_part: contents.insert(0, video_part)
479
 
480
  response = await loop.run_in_executor(None, lambda: client.models.generate_content(model=model_name, contents=contents, config=config))