Spaces:
Sleeping
Sleeping
Update app.py
Browse files20 unmodified lines212223242526272829303132331 unmodified line3536373839404111 unmodified lines5354555657585917 unmodified lines77787980818283848586871 unmodified line899091929394952 unmodified lines989910010110210310410510610710810911011111211311411511611711811912012112211 unmodified lines1341351361371381391407 unmodified lines14814915015115215315420 unmodified lines@tooldef get_current_time_in_timezone(timezone: str) -> str:"""Fetch the current local time in a specified timezone."""try:tz = pytz.timezone(timezone)local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")return f"The current local time in {timezone} is: {local_time}"except Exception as e:return f"Error fetching time: {e}"# ------------------------------------------------------1 unmodified line@tooldef get_bitcoin_price() -> str:"""Fetch the current Bitcoin price in USD."""try:r = requests.get("https://api.coingecko.com/api/v3/simple/price",11 unmodified lines@tooldef get_weather_city(city: str) -> str:"""Gets current weather for a city."""try:geo = requests.get("https://geocoding-api.open-meteo.com/v1/search",17 unmodified linestimeout=10,).json()c = weather["current_weather"]return f"Weather in {city}: {c['temperature']}°C, wind {c['windspeed']} km/h"except Exception as e:return f"Weather failed: {e}"# ------------------------------------------------------1 unmodified line@tooldef summarize_neural_networks() -> str:"""Summarizes neural networks history from Wikipedia."""try:r = requests.get("https://en.wikipedia.org/api/rest_v1/page/summary/Artificial_neural_network",2 unmodified linesr.raise_for_status()return r.json().get("extract", "")[:1500]except Exception as e:return f"Wiki fetch failed: {e}"# ------------------------------------------------------# 🔥 FIXED AI NEWS TOOL (RSS + HN API)# ------------------------------------------------------@tooldef search_ai_news(_: str = "") -> str:"""Fetches today's top AI news from reliable feeds."""try:articles = []# --- RSS FEEDS ---feeds = ["https://www.artificialintelligence-news.com/feed/","https://www.technologyreview.com/feed/","https://venturebeat.com/category/ai/feed/",]for url in feeds:11 unmodified linesif title and link:articles.append(f"- {title} — {link}")# --- FALLBACK: HackerNews AI ---if not articles:hn = requests.get("https://hn.algolia.com/api/v1/search_by_date",7 unmodified lines)if not articles:return "No AI news found right now."return "\n".join(articles[:10])20 unmodified lines21222324252627282930313233343536371 unmodified line394041424344454647484911 unmodified lines616263646566676869707117 unmodified lines89909192939495969798991001011021031 unmodified line1051061071081091101111121131141152 unmodified lines11811912012112212312412512612712812913013113213313413513613713813914014114214314411 unmodified lines1561571581591601611627 unmodified lines17017117217317417517620 unmodified lines@tooldef get_current_time_in_timezone(timezone: str) -> str:"""Get the current local time in a timezone.Args:timezone: Timezone string like 'Asia/Tokyo', 'UTC', 'Europe/London'"""try:tz = pytz.timezone(timezone)local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")return f"The current local time in {timezone} is {local_time}"except Exception as e:return f"Error fetching time for timezone {timezone}: {e}"# ------------------------------------------------------1 unmodified line@tooldef get_bitcoin_price() -> str:"""Fetch the current Bitcoin price in USD.Args:None"""try:r = requests.get("https://api.coingecko.com/api/v3/simple/price",11 unmodified lines@tooldef get_weather_city(city: str) -> str:"""Get current weather for a city.Args:city: City name like Tokyo, London, Paris"""try:geo = requests.get("https://geocoding-api.open-meteo.com/v1/search",17 unmodified linestimeout=10,).json()current = weather["current_weather"]return (f"Weather in {city}: {current['temperature']}°C, "f"wind {current['windspeed']} km/h")except Exception as e:return f"Weather lookup failed: {e}"# ------------------------------------------------------1 unmodified line@tooldef summarize_neural_networks() -> str:"""Summarize history of neural networks.Args:None"""try:r = requests.get("https://en.wikipedia.org/api/rest_v1/page/summary/Artificial_neural_network",2 unmodified linesr.raise_for_status()return r.json().get("extract", "")[:1500]except Exception as e:return f"Wikipedia fetch failed: {e}"# ------------------------------------------------------@tooldef search_ai_news(_: str = "") -> str:"""Fetch latest AI news from RSS + HackerNews.Args:_: Dummy parameter required by tool interface."""try:articles = []# RSS feedsfeeds = ["https://venturebeat.com/category/ai/feed/","https://www.technologyreview.com/feed/","https://www.artificialintelligence-news.com/feed/",]for url in feeds:11 unmodified linesif title and link:articles.append(f"- {title} — {link}")# Fallback: HackerNews APIif not articles:hn = requests.get("https://hn.algolia.com/api/v1/search_by_date",7 unmodified lines)if not articles:return "No AI news found today."return "\n".join(articles[:10])
app.py+40-18