Update app.py
Browse files
app.py
CHANGED
@@ -20,14 +20,18 @@ import re
|
|
20 |
from youtube_transcript_api import YouTubeTranscriptApi
|
21 |
from smolagents import Tool
|
22 |
|
23 |
-
|
24 |
-
|
25 |
-
|
|
|
|
|
|
|
|
|
26 |
|
27 |
inputs = {
|
28 |
"url": {
|
29 |
"type": "string",
|
30 |
-
"description": "
|
31 |
}
|
32 |
}
|
33 |
|
@@ -35,19 +39,21 @@ class YouTubeCaptionTool(Tool):
|
|
35 |
|
36 |
def forward(self, url: str) -> str:
|
37 |
try:
|
38 |
-
# Extract
|
39 |
-
|
40 |
-
|
41 |
-
return "Could not extract video ID from URL."
|
42 |
|
43 |
-
|
44 |
-
|
45 |
-
full_text = " ".join([entry['text'] for entry in transcript])
|
46 |
|
47 |
-
|
|
|
|
|
48 |
|
|
|
49 |
except Exception as e:
|
50 |
-
return f"
|
|
|
51 |
|
52 |
|
53 |
##Tool 2
|
@@ -121,7 +127,7 @@ async def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
121 |
model=OpenAIServerModel(model_id="gpt-4o-mini",
|
122 |
api_key=os.environ["OPENAI_API_KEY"],
|
123 |
temperature=0.0),
|
124 |
-
max_steps=
|
125 |
verbosity_level=2
|
126 |
)
|
127 |
except Exception as e:
|
|
|
20 |
from youtube_transcript_api import YouTubeTranscriptApi
|
21 |
from smolagents import Tool
|
22 |
|
23 |
+
from smolagents import Tool
|
24 |
+
from youtube_transcript_api import YouTubeTranscriptApi
|
25 |
+
from urllib.parse import urlparse, parse_qs
|
26 |
+
|
27 |
+
class YouTubeTranscriptTool(Tool):
|
28 |
+
name = "youtube_transcript"
|
29 |
+
description = "Fetches the full transcript of a YouTube video from its URL."
|
30 |
|
31 |
inputs = {
|
32 |
"url": {
|
33 |
"type": "string",
|
34 |
+
"description": "The full YouTube video URL"
|
35 |
}
|
36 |
}
|
37 |
|
|
|
39 |
|
40 |
def forward(self, url: str) -> str:
|
41 |
try:
|
42 |
+
# Extract video ID from URL
|
43 |
+
parsed = urlparse(url)
|
44 |
+
video_id = parse_qs(parsed.query).get("v", [None])[0]
|
|
|
45 |
|
46 |
+
if not video_id:
|
47 |
+
return "Error: Invalid YouTube URL or missing video ID."
|
|
|
48 |
|
49 |
+
# Fetch the transcript
|
50 |
+
transcript_list = YouTubeTranscriptApi.get_transcript(video_id)
|
51 |
+
transcript_text = " ".join(entry["text"] for entry in transcript_list)
|
52 |
|
53 |
+
return transcript_text[:5000] # Optional: truncate to 5000 chars
|
54 |
except Exception as e:
|
55 |
+
return f"Error retrieving transcript: {str(e)}"
|
56 |
+
|
57 |
|
58 |
|
59 |
##Tool 2
|
|
|
127 |
model=OpenAIServerModel(model_id="gpt-4o-mini",
|
128 |
api_key=os.environ["OPENAI_API_KEY"],
|
129 |
temperature=0.0),
|
130 |
+
max_steps=18,
|
131 |
verbosity_level=2
|
132 |
)
|
133 |
except Exception as e:
|