Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,55 +3,20 @@ 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
|
| 9 |
|
| 10 |
@tool
|
| 11 |
def get_weather(city: str) -> str:
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
Args:
|
| 16 |
-
city (str): Name of the city to get weather for.
|
| 17 |
-
|
| 18 |
-
Returns:
|
| 19 |
-
str: Weather description for the city.
|
| 20 |
-
"""
|
| 21 |
-
final_answer = FinalAnswerTool()
|
| 22 |
-
|
| 23 |
-
# If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
|
| 24 |
-
# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
| 25 |
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
return "API key not found. Please set OPENWEATHER_API_KEY in your environment."
|
| 29 |
-
endpoint = f"http://api.openweathermap.org/data/2.5/weather?q={city}&appid={api_key}&units=metric"
|
| 30 |
-
|
| 31 |
-
try:
|
| 32 |
-
response = requests.get(endpoint)
|
| 33 |
-
if response.status_code == 200:
|
| 34 |
-
data = response.json()
|
| 35 |
-
weather = data["weather"][0]["description"]
|
| 36 |
-
temperature = data["main"]["temp"]
|
| 37 |
-
return f"The weather in {city} is currently '{weather}' with a temperature of {temperature}°C."
|
| 38 |
-
else:
|
| 39 |
-
return f"Could not fetch weather data for {city}. Please check the city name or try again later."
|
| 40 |
-
except Exception as e:
|
| 41 |
-
return f"An error occurred: {str(e)}"
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
agent = CodeAgent(
|
| 46 |
-
tools=[get_weather],
|
| 47 |
-
description="Weather info agent",
|
| 48 |
-
model="gpt-3.5-turbo" # or whatever model is supported
|
| 49 |
-
)
|
| 50 |
-
demo = GradioUI(
|
| 51 |
-
agent=get_weather,
|
| 52 |
-
)
|
| 53 |
-
demo.launch(ssr=False)
|
| 54 |
|
|
|
|
| 55 |
@tool
|
| 56 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 57 |
"""A tool that fetches the current local time in a specified timezone.
|
|
|
|
| 3 |
import requests
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
+
import gradio as gr
|
| 7 |
from tools.final_answer import FinalAnswerTool
|
| 8 |
|
| 9 |
from Gradio_UI import GradioUI
|
| 10 |
|
| 11 |
@tool
|
| 12 |
def get_weather(city: str) -> str:
|
| 13 |
+
# Your weather logic here
|
| 14 |
+
return f"Demo response for {city}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
+
demo = gr.Interface(fn=get_weather, inputs="text", outputs="text")
|
| 17 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
+
|
| 20 |
@tool
|
| 21 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 22 |
"""A tool that fetches the current local time in a specified timezone.
|