martynabaran commited on
Commit
b093398
·
verified ·
1 Parent(s): b9f02ed

Update agent.py

Browse files
Files changed (1) hide show
  1. agent.py +22 -0
agent.py CHANGED
@@ -384,6 +384,27 @@ def analyze_excel_file(file_path: str, query: str = "") -> str:
384
  except Exception as e:
385
  return f"Error analyzing Excel file: {str(e)}"
386
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
387
  # load the system prompt from the file
388
  with open("system_prompt.txt", "r", encoding="utf-8") as f:
389
  system_prompt = f.read()
@@ -427,6 +448,7 @@ tools = [
427
  extract_text_from_image,
428
  analyze_csv_file,
429
  analyze_excel_file,
 
430
  ]
431
 
432
 
 
384
  except Exception as e:
385
  return f"Error analyzing Excel file: {str(e)}"
386
 
387
+ @tool
388
+ def youtube_transcript(video_url: str) -> str:
389
+ """
390
+ Extract transcript from a YouTube video.
391
+ Args:
392
+ video_url (str): The full URL to the YouTube video.
393
+ Returns:
394
+ str: The text transcript or an error.
395
+ """
396
+ try:
397
+ from youtube_transcript_api import YouTubeTranscriptApi
398
+ from urllib.parse import urlparse, parse_qs
399
+
400
+ video_id = parse_qs(urlparse(video_url).query)['v'][0]
401
+ transcript = YouTubeTranscriptApi.get_transcript(video_id)
402
+ text = "\n".join([entry['text'] for entry in transcript])
403
+ return f"<YouTubeTranscript video_id=\"{video_id}\">\n{text}\n</YouTubeTranscript>"
404
+ except Exception as e:
405
+ return f"Error extracting YouTube transcript: {str(e)}"
406
+
407
+
408
  # load the system prompt from the file
409
  with open("system_prompt.txt", "r", encoding="utf-8") as f:
410
  system_prompt = f.read()
 
448
  extract_text_from_image,
449
  analyze_csv_file,
450
  analyze_excel_file,
451
+ youtube_transcript,
452
  ]
453
 
454