hugging / app.py
22Nikk0's picture
Upload folder using huggingface_hub
1787bf2 verified
from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
import requests
import yaml
from tools.final_answer import FinalAnswerTool
from Gradio_UI import GradioUI
# Below is an example of a tool that does nothing. Amaze us with your creativity !
@tool
def get_the_weather_forecast(city_name:str) -> str:
"""
Get the weather forecast for a given city.
Args:
city_name (str): The name of the city to get the weather forecast for.
Returns:
str: The weather forecast for the city.
"""
url = 'https://wttr.in/{}'.format(city_name)
try:
data = requests.get(url)
weather_forecast = data.text
except:
weather_forecast = "Error Occurred"
return(weather_forecast)
@tool
def get_clothes_pieces_url()-> list:
"""
Get a list of URLs related to different types of clothing pieces.
Args:
None
Returns:
list: A list of URLs related to clothing pieces.
"""
return [
"https://dico-petitbac.com/vetements/",
"https://kizoshop.com/blogs/infos/quelles-sont-les-differents-types-de-vetements"
]
@tool
def get_outfits_ideas_url()-> list:
"""
Get a list of URLs related to outfit ideas.
Args:
None
Returns:
list: A list of URLs related to outfit ideas.
"""
return [
"https://www.votrejournal.net/types-de-vetements-les-differents-a-connaitre-pour-bien-shabiller/",
"https://mode-homme-tendance.fr/look-masculin/10-idees-de-tenues-tendance-pour-homme/"
]
finalanswer = FinalAnswerTool()
ducksearch = DuckDuckGoSearchTool()
# 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='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded
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=[finalanswer, ducksearch, get_the_weather_forecast, get_clothes_pieces_url, get_outfits_ideas_url], ## add your tools here (don't remove final answer)
max_steps=15,
verbosity_level=1,
grammar=None,
planning_interval=None,
name="mapmarker",
description="An agent that create a map on which it add multiple markers",
prompt_templates=prompt_templates
)
GradioUI(agent).launch()