iProsto's picture
Update app.py
0b26969 verified
from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool, tool
import datetime
import requests
import pytz
import yaml
from tools.final_answer import FinalAnswerTool
from Gradio_UI import GradioUI
@tool
def get_list_of_people_on_iss() -> dict:
"""A tool that fetches the current number of people in space. When known it also fetches the names and spacecraft those people are on. Returns.
Returns:
dict: A JSON object containing the following keys:
- "message" (str): Status message (e.g., "success").
- "number" (int): The number of astronauts currently in space.
- "people" (list of dict): A list of astronauts, where each entry contains:
- "name" (str): The astronaut's name.
- "craft" (str): The name of the spacecraft they are on.
Args: None
"""
url = "http://api.open-notify.org/astros.json"
response = requests.get(url)
if response.status_code == 200:
return response.json()
else:
return f"Error fetching astronauts: {response.status_code}"
@tool
def get_iss_location() -> dict:
"""A tool that fetches the current location of the International Space Station (ISS).
Returns:
dict: A JSON object containing the following keys:
- "message" (str): Status message (e.g., "success").
- "timestamp" (int): The UNIX timestamp when the location was recorded.
- "iss_position" (dict): The latitude and longitude of the ISS.
- "latitude" (str): The current latitude of the ISS.
- "longitude" (str): The current longitude of the ISS.
Args: None
"""
url = "http://api.open-notify.org/iss-now.json"
response = requests.get(url)
if response.status_code == 200:
return response.json()
else:
return f"Error fetching ISS location: {response.status_code}"
final_answer = FinalAnswerTool()
# 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:
# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
model = HfApiModel(
max_tokens=2096,
temperature=0.5,
model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud',
custom_role_conversions=None,
)
# Import tool from Hub
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
with open("prompts.yaml", 'r') as stream:
prompt_templates = yaml.safe_load(stream)
agent = CodeAgent(
model=model,
tools=[final_answer, get_list_of_people_on_iss, get_iss_location],
max_steps=6,
verbosity_level=1,
grammar=None,
planning_interval=None,
name=None,
description=None,
prompt_templates=prompt_templates
)
GradioUI(agent).launch()