Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,7 +7,6 @@ import os
|
|
| 7 |
from tools.final_answer import FinalAnswerTool
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
from typing import Optional, List
|
| 10 |
-
import requests
|
| 11 |
from datetime import datetime, timedelta
|
| 12 |
|
| 13 |
# Set up OpenWeather API key
|
|
@@ -24,15 +23,14 @@ def get_weather_info(city: str) -> str:
|
|
| 24 |
params = {
|
| 25 |
'q': city,
|
| 26 |
'appid': OPENWEATHER_API_KEY,
|
| 27 |
-
'units': 'metric'
|
| 28 |
}
|
| 29 |
|
| 30 |
response = requests.get(base_url, params=params)
|
| 31 |
-
response.raise_for_status()
|
| 32 |
|
| 33 |
weather_data = response.json()
|
| 34 |
|
| 35 |
-
# Extract relevant information
|
| 36 |
temperature = weather_data['main']['temp']
|
| 37 |
conditions = weather_data['weather'][0]['description']
|
| 38 |
humidity = weather_data['main']['humidity']
|
|
@@ -45,6 +43,7 @@ def get_weather_info(city: str) -> str:
|
|
| 45 |
f"Wind Speed: {wind_speed} m/s")
|
| 46 |
except Exception as e:
|
| 47 |
return f"Error fetching weather for city '{city}': {str(e)}"
|
|
|
|
| 48 |
@tool
|
| 49 |
def crypto_tracker(action: str, crypto_id: Optional[str] = None) -> str:
|
| 50 |
"""Tracks cryptocurrency prices and changes using CoinGecko API
|
|
@@ -137,7 +136,6 @@ def crypto_tracker(action: str, crypto_id: Optional[str] = None) -> str:
|
|
| 137 |
f"Description: {data['description']['en'][:300]}..."
|
| 138 |
)
|
| 139 |
|
| 140 |
-
else:
|
| 141 |
elif action == "summary":
|
| 142 |
# Get 24-hour summary for top 5 cryptocurrencies
|
| 143 |
response = requests.get(
|
|
@@ -165,7 +163,7 @@ def crypto_tracker(action: str, crypto_id: Optional[str] = None) -> str:
|
|
| 165 |
|
| 166 |
for coin in data:
|
| 167 |
price_change = coin['price_change_percentage_24h']
|
| 168 |
-
volume_change = (coin['total_volume'] / coin['market_cap']) * 100
|
| 169 |
|
| 170 |
# Determine market sentiment
|
| 171 |
if price_change > 5:
|
|
@@ -188,7 +186,7 @@ def crypto_tracker(action: str, crypto_id: Optional[str] = None) -> str:
|
|
| 188 |
f" Market Sentiment: {sentiment}\n\n"
|
| 189 |
)
|
| 190 |
|
| 191 |
-
# Add significant events
|
| 192 |
significant_events = []
|
| 193 |
for coin in data:
|
| 194 |
if abs(coin['price_change_percentage_24h']) > 10:
|
|
@@ -225,27 +223,21 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 225 |
timezone: A string representing a valid timezone (e.g., 'America/New_York').
|
| 226 |
"""
|
| 227 |
try:
|
| 228 |
-
# Create timezone object
|
| 229 |
tz = pytz.timezone(timezone)
|
| 230 |
-
|
| 231 |
-
local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
|
| 232 |
return f"The current local time in {timezone} is: {local_time}"
|
| 233 |
except Exception as e:
|
| 234 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 235 |
|
| 236 |
final_answer = FinalAnswerTool()
|
| 237 |
|
| 238 |
-
# If the agent does not answer, the model is overloaded, please use another model or the following
|
| 239 |
-
# Hugging Face Endpoint that also contains qwen2.5 coder:
|
| 240 |
-
# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
| 241 |
model = HfApiModel(
|
| 242 |
max_tokens=2096,
|
| 243 |
temperature=0.5,
|
| 244 |
-
model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
|
| 245 |
custom_role_conversions=None,
|
| 246 |
)
|
| 247 |
|
| 248 |
-
# Import tool from Hub
|
| 249 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 250 |
|
| 251 |
with open("prompts.yaml", 'r') as stream:
|
|
@@ -261,7 +253,7 @@ agent = CodeAgent(
|
|
| 261 |
image_generation_tool,
|
| 262 |
get_current_time_in_timezone,
|
| 263 |
get_weather_info,
|
| 264 |
-
|
| 265 |
],
|
| 266 |
max_steps=6,
|
| 267 |
verbosity_level=1,
|
|
|
|
| 7 |
from tools.final_answer import FinalAnswerTool
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
from typing import Optional, List
|
|
|
|
| 10 |
from datetime import datetime, timedelta
|
| 11 |
|
| 12 |
# Set up OpenWeather API key
|
|
|
|
| 23 |
params = {
|
| 24 |
'q': city,
|
| 25 |
'appid': OPENWEATHER_API_KEY,
|
| 26 |
+
'units': 'metric'
|
| 27 |
}
|
| 28 |
|
| 29 |
response = requests.get(base_url, params=params)
|
| 30 |
+
response.raise_for_status()
|
| 31 |
|
| 32 |
weather_data = response.json()
|
| 33 |
|
|
|
|
| 34 |
temperature = weather_data['main']['temp']
|
| 35 |
conditions = weather_data['weather'][0]['description']
|
| 36 |
humidity = weather_data['main']['humidity']
|
|
|
|
| 43 |
f"Wind Speed: {wind_speed} m/s")
|
| 44 |
except Exception as e:
|
| 45 |
return f"Error fetching weather for city '{city}': {str(e)}"
|
| 46 |
+
|
| 47 |
@tool
|
| 48 |
def crypto_tracker(action: str, crypto_id: Optional[str] = None) -> str:
|
| 49 |
"""Tracks cryptocurrency prices and changes using CoinGecko API
|
|
|
|
| 136 |
f"Description: {data['description']['en'][:300]}..."
|
| 137 |
)
|
| 138 |
|
|
|
|
| 139 |
elif action == "summary":
|
| 140 |
# Get 24-hour summary for top 5 cryptocurrencies
|
| 141 |
response = requests.get(
|
|
|
|
| 163 |
|
| 164 |
for coin in data:
|
| 165 |
price_change = coin['price_change_percentage_24h']
|
| 166 |
+
volume_change = (coin['total_volume'] / coin['market_cap']) * 100
|
| 167 |
|
| 168 |
# Determine market sentiment
|
| 169 |
if price_change > 5:
|
|
|
|
| 186 |
f" Market Sentiment: {sentiment}\n\n"
|
| 187 |
)
|
| 188 |
|
| 189 |
+
# Add significant events
|
| 190 |
significant_events = []
|
| 191 |
for coin in data:
|
| 192 |
if abs(coin['price_change_percentage_24h']) > 10:
|
|
|
|
| 223 |
timezone: A string representing a valid timezone (e.g., 'America/New_York').
|
| 224 |
"""
|
| 225 |
try:
|
|
|
|
| 226 |
tz = pytz.timezone(timezone)
|
| 227 |
+
local_time = datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
|
|
|
|
| 228 |
return f"The current local time in {timezone} is: {local_time}"
|
| 229 |
except Exception as e:
|
| 230 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 231 |
|
| 232 |
final_answer = FinalAnswerTool()
|
| 233 |
|
|
|
|
|
|
|
|
|
|
| 234 |
model = HfApiModel(
|
| 235 |
max_tokens=2096,
|
| 236 |
temperature=0.5,
|
| 237 |
+
model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
|
| 238 |
custom_role_conversions=None,
|
| 239 |
)
|
| 240 |
|
|
|
|
| 241 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 242 |
|
| 243 |
with open("prompts.yaml", 'r') as stream:
|
|
|
|
| 253 |
image_generation_tool,
|
| 254 |
get_current_time_in_timezone,
|
| 255 |
get_weather_info,
|
| 256 |
+
crypto_tracker # Fixed the name here
|
| 257 |
],
|
| 258 |
max_steps=6,
|
| 259 |
verbosity_level=1,
|