Sonu313131 commited on
Commit
d379226
·
verified ·
1 Parent(s): 6c6314d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -16
app.py CHANGED
@@ -20,25 +20,22 @@ from smolagents import Tool
20
  from youtube_transcript_api import YouTubeTranscriptApi
21
  import re
22
 
 
 
23
  class YouTubeTranscriptTool(Tool):
24
  name = "youtube_transcript"
25
- description = "Use this to extract spoken content from a YouTube video given its URL."
 
 
 
 
 
 
 
 
 
 
26
 
27
- def use(self, input_text: str) -> str:
28
- try:
29
- # Extract video ID from URL
30
- video_id_match = re.search(r"(?:v=|youtu\.be/)([a-zA-Z0-9_-]{11})", input_text)
31
- if not video_id_match:
32
- return "Invalid YouTube URL provided."
33
-
34
- video_id = video_id_match.group(1)
35
- transcript = YouTubeTranscriptApi.get_transcript(video_id)
36
-
37
- # Combine into a single string
38
- full_text = " ".join([entry['text'] for entry in transcript])
39
- return full_text[:3000] # limit to 3000 chars
40
- except Exception as e:
41
- return f"Error fetching transcript: {e}"
42
  transcript_tool = YouTubeTranscriptTool()
43
 
44
  async def run_and_submit_all(profile: gr.OAuthProfile | None):
 
20
  from youtube_transcript_api import YouTubeTranscriptApi
21
  import re
22
 
23
+ from smolagents import Tool
24
+
25
  class YouTubeTranscriptTool(Tool):
26
  name = "youtube_transcript"
27
+ description = "Extracts transcript text from a YouTube video URL"
28
+ inputs = {"url": str}
29
+ outputs = {"transcript": str}
30
+
31
+ def __call__(self, url: str) -> dict:
32
+ # Example logic (replace with real code)
33
+ from youtube_transcript_api import YouTubeTranscriptApi
34
+ video_id = url.split("v=")[-1].split("&")[0]
35
+ transcript_list = YouTubeTranscriptApi.get_transcript(video_id)
36
+ transcript_text = " ".join([t["text"] for t in transcript_list])
37
+ return {"transcript": transcript_text}
38
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
  transcript_tool = YouTubeTranscriptTool()
40
 
41
  async def run_and_submit_all(profile: gr.OAuthProfile | None):