Spaces:
Sleeping
Sleeping
Update app.py
Browse files2 unmodified lines3456781 unmodified line101112131415161718192021222324252627282930313233343536373839402 unmodified linesimport requestsimport pytzimport yamlfrom tools.final_answer import FinalAnswerToolfrom Gradio_UI import GradioUI1 unmodified line# Below is an example of a tool that does nothing. Amaze us with your creativity !@tooldef fetch_headlines(topic: str) -> str:"""Fetches recent news healines for a given topic using DuckDuckGo search.Args:topic: The topic to search for (e.g., 'AI', 'Politics', 'Sport')Returns:A formatted string with up to 5 news headlines and their links."""search_tool = DuckDuckGoSearchTool()try:query = f"{topic} news"results = search_tool(query)headlines = []for result in results[:5]:title = result.get('title', 'No title')link = result.get('link', 'No link')headlines.append(f"{len(headlines) + 1}. {title} - {link}")if not headlines:return f"No headlines found for topic '{topic}'."return "\n".join(headlines)except Exception as e:return f"Error fetching headlines: {str(e)}"@tooldef get_current_time_in_timezone(timezone: str) -> str:"""A tool that fetches the current local time in a specified timezone.2 unmodified lines345678910111 unmodified line1314151617181920212223242526272829303132333435363738392 unmodified linesimport requestsimport pytzimport yamlimport osfrom youtube_transcript_api import YouTubeTranscriptApiimport refrom tools.final_answer import FinalAnswerToolfrom Gradio_UI import GradioUI1 unmodified line# Below is an example of a tool that does nothing. Amaze us with your creativity !@tooldef get_video_transcript(url: str) -> str:"""Returns the transcript text of a give YouTube video URL.Args:url: YouTube video url given by a user."""try:video_id = extract_video_id(url)transctipt = YouTubeTranscriptApi.get_transcript(video_id)text = " ".join([entry["text"] for entry in transctipt])return textexcept Exception as e:return f"Error: {str(e)}"def extract_video_id(url: str) -> str:match = re.search(r"(?:v=|youtu\.be/)([^&\n?#]+)", url)if match:return match.grou(1)else:raise ValueError("Invalid YouTube URL.")@tooldef get_current_time_in_timezone(timezone: str) -> str:"""A tool that fetches the current local time in a specified timezone.
app.py+19-20