gabejavitt commited on
Commit
1c6d6d6
·
verified ·
1 Parent(s): 8d7aa79

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -3
app.py CHANGED
@@ -488,7 +488,8 @@ def get_youtube_transcript(video_url: str) -> str:
488
  if not video_id:
489
  return f"Error: Could not extract video ID."
490
 
491
- transcript_list = YouTubeTranscriptApi.get_transcript(video_id)
 
492
 
493
  if not transcript_list:
494
  return "Error: No transcript found."
@@ -1320,11 +1321,25 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
1320
  for item in questions_data:
1321
  task_id = item.get("task_id")
1322
  question_text = item.get("question")
 
 
 
 
 
 
 
 
 
 
 
 
1323
  if not task_id or question_text is None:
1324
  print(f"Skipping item with missing task_id or question: {item}")
1325
  continue
1326
  try:
1327
- submitted_answer = agent(question_text)
 
 
1328
  answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
1329
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
1330
  except Exception as e:
@@ -1397,7 +1412,6 @@ with gr.Blocks() as demo:
1397
  **Disclaimers:**
1398
  Once clicking on the "submit button, it can take quite some time ( this is the time for the agent to go through all the questions).
1399
  This space provides a basic setup and is intentionally sub-optimal to encourage you to develop your own, more robust solution. For instance for the delay process of the submit button, a solution could be to cache the answers and submit in a seperate action or even to answer the questions in async.
1400
- Please note that this version requires an OpenAI Key to run.
1401
  """
1402
  )
1403
 
 
488
  if not video_id:
489
  return f"Error: Could not extract video ID."
490
 
491
+ from youtube_transcript_api import YouTubeTranscriptApi
492
+ transcript_list = YouTubeTranscriptApi.list_transcripts(video_id).find_transcript(['en']).fetch()
493
 
494
  if not transcript_list:
495
  return "Error: No transcript found."
 
1321
  for item in questions_data:
1322
  task_id = item.get("task_id")
1323
  question_text = item.get("question")
1324
+ # Download attached files if they exist
1325
+ # Handle file attachments
1326
+ file_info = ""
1327
+ if item.get("file_path"):
1328
+ file_path = item["file_path"]
1329
+ file_info = f"\n\n[Note: Question references file: {file_path}]"
1330
+
1331
+ # Check if file exists
1332
+ if not os.path.exists(file_path):
1333
+ print(f"⚠️ Warning: File {file_path} not found!")
1334
+ file_info += f"\n[WARNING: File not found in current directory]"
1335
+
1336
  if not task_id or question_text is None:
1337
  print(f"Skipping item with missing task_id or question: {item}")
1338
  continue
1339
  try:
1340
+ question_with_context = question_text + file_info
1341
+ submitted_answer = agent(question_with_context)
1342
+ #submitted_answer = agent(question_text)
1343
  answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
1344
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
1345
  except Exception as e:
 
1412
  **Disclaimers:**
1413
  Once clicking on the "submit button, it can take quite some time ( this is the time for the agent to go through all the questions).
1414
  This space provides a basic setup and is intentionally sub-optimal to encourage you to develop your own, more robust solution. For instance for the delay process of the submit button, a solution could be to cache the answers and submit in a seperate action or even to answer the questions in async.
 
1415
  """
1416
  )
1417