Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,6 +3,9 @@ import datetime
|
|
| 3 |
import requests
|
| 4 |
import pytz
|
| 5 |
import yaml
|
|
|
|
|
|
|
|
|
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
|
@@ -10,31 +13,27 @@ from Gradio_UI import GradioUI
|
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
|
| 12 |
@tool
|
| 13 |
-
def
|
| 14 |
-
"""
|
| 15 |
|
| 16 |
Args:
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
Returns:
|
| 20 |
-
A formatted string with up to 5 news headlines and their links.
|
| 21 |
"""
|
| 22 |
-
search_tool = DuckDuckGoSearchTool()
|
| 23 |
try:
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
for result in results[:5]:
|
| 29 |
-
title = result.get('title', 'No title')
|
| 30 |
-
link = result.get('link', 'No link')
|
| 31 |
-
headlines.append(f"{len(headlines) + 1}. {title} - {link}")
|
| 32 |
-
|
| 33 |
-
if not headlines:
|
| 34 |
-
return f"No headlines found for topic '{topic}'."
|
| 35 |
-
return "\n".join(headlines)
|
| 36 |
except Exception as e:
|
| 37 |
-
return f"Error
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
@tool
|
| 39 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 40 |
"""A tool that fetches the current local time in a specified timezone.
|
|
|
|
| 3 |
import requests
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
+
import os
|
| 7 |
+
from youtube_transcript_api import YouTubeTranscriptApi
|
| 8 |
+
import re
|
| 9 |
from tools.final_answer import FinalAnswerTool
|
| 10 |
|
| 11 |
from Gradio_UI import GradioUI
|
|
|
|
| 13 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 14 |
|
| 15 |
@tool
|
| 16 |
+
def get_video_transcript(url: str) -> str:
|
| 17 |
+
"""Returns the transcript text of a give YouTube video URL.
|
| 18 |
|
| 19 |
Args:
|
| 20 |
+
url: YouTube video url given by a user.
|
|
|
|
|
|
|
|
|
|
| 21 |
"""
|
|
|
|
| 22 |
try:
|
| 23 |
+
video_id = extract_video_id(url)
|
| 24 |
+
transctipt = YouTubeTranscriptApi.get_transcript(video_id)
|
| 25 |
+
text = " ".join([entry["text"] for entry in transctipt])
|
| 26 |
+
return text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
except Exception as e:
|
| 28 |
+
return f"Error: {str(e)}"
|
| 29 |
+
|
| 30 |
+
def extract_video_id(url: str) -> str:
|
| 31 |
+
match = re.search(r"(?:v=|youtu\.be/)([^&\n?#]+)", url)
|
| 32 |
+
if match:
|
| 33 |
+
return match.grou(1)
|
| 34 |
+
else:
|
| 35 |
+
raise ValueError("Invalid YouTube URL.")
|
| 36 |
+
|
| 37 |
@tool
|
| 38 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 39 |
"""A tool that fetches the current local time in a specified timezone.
|