Sonu313131 commited on
Commit
834181c
·
verified ·
1 Parent(s): 12b96a9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -1
app.py CHANGED
@@ -15,6 +15,40 @@ openai_key = os.environ.get("OPENAI_API_KEY")
15
 
16
  search_tool = DuckDuckGoSearchTool()
17
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
 
19
  ##Tool 2
20
  import wikipedia
@@ -75,6 +109,7 @@ class WikipediaQATool(Tool):
75
 
76
  wiki_tool = WikipediaQATool()
77
  #excel_tool = ExcelAnalysisTool()
 
78
 
79
  async def run_and_submit_all(profile: gr.OAuthProfile | None):
80
  log_output = ""
@@ -82,7 +117,7 @@ async def run_and_submit_all(profile: gr.OAuthProfile | None):
82
  try:
83
 
84
  agent = ToolCallingAgent(
85
- tools=[search_tool],
86
  model=OpenAIServerModel(
87
  model_id="gpt-4o", # ✅ valid OpenAI model name
88
  temperature=0.0,
 
15
 
16
  search_tool = DuckDuckGoSearchTool()
17
 
18
+ ##Tool 1
19
+ import re
20
+ from youtube_transcript_api import YouTubeTranscriptApi
21
+ from smolagents import Tool
22
+
23
+ class YouTubeCaptionTool(Tool):
24
+ name = "youtube_caption_reader"
25
+ description = "Extracts captions from a YouTube video given its URL and returns the transcript or a segment."
26
+
27
+ inputs = {
28
+ "url": {
29
+ "type": "string",
30
+ "description": "Full YouTube video URL (e.g., https://www.youtube.com/watch?v=abc123)"
31
+ }
32
+ }
33
+
34
+ output_type = "string"
35
+
36
+ def forward(self, url: str) -> str:
37
+ try:
38
+ # Extract the video ID from the URL
39
+ match = re.search(r"(?:v=|youtu.be/)([\w-]+)", url)
40
+ if not match:
41
+ return "Could not extract video ID from URL."
42
+
43
+ video_id = match.group(1)
44
+ transcript = YouTubeTranscriptApi.get_transcript(video_id)
45
+ full_text = " ".join([entry['text'] for entry in transcript])
46
+
47
+ return full_text[:3000] # return first 3000 characters
48
+
49
+ except Exception as e:
50
+ return f"Failed to retrieve transcript: {str(e)}"
51
+
52
 
53
  ##Tool 2
54
  import wikipedia
 
109
 
110
  wiki_tool = WikipediaQATool()
111
  #excel_tool = ExcelAnalysisTool()
112
+ yt_tool = YouTubeCaptionTool()
113
 
114
  async def run_and_submit_all(profile: gr.OAuthProfile | None):
115
  log_output = ""
 
117
  try:
118
 
119
  agent = ToolCallingAgent(
120
+ tools=[search_tool, yt_tool],
121
  model=OpenAIServerModel(
122
  model_id="gpt-4o", # ✅ valid OpenAI model name
123
  temperature=0.0,