FinalProject / app.py
MasterOfHugs's picture
Update app.py
93c6301 verified
# app.py
from smolagents import CodeAgent, HfApiModel, Tool
from tools.final_answer import FinalAnswerTool
from tools.web_search import DuckDuckGoSearchTool # 👈 ajout
from tools.visit_webpage import VisitWebpageTool # 👈 ajout
from Gradio_UI import GradioUI
# Définition des outils
final_answer = FinalAnswerTool()
web_search = DuckDuckGoSearchTool() # 👈 instanciation
visit_webpage = VisitWebpageTool() # 👈 instanciation
# Définition du modèle
model = HfApiModel("Qwen/Qwen2.5-Coder-32B-Instruct")
# Définition de l'agent
agent = CodeAgent(
model=model,
tools=[final_answer, web_search, visit_webpage], # 👈 ajout des outils web
add_base_tools=True,
max_steps=20,
)
# Exemple d'outils custom existants
@Tool
def my_custom_tool() -> str:
"""This is a custom tool."""
return "This is my custom tool!"
@Tool
def get_current_time_in_timezone(timezone: str) -> str:
"""Get the current time in a given timezone."""
from datetime import datetime
import pytz
tz = pytz.timezone(timezone)
return str(datetime.now(tz))
# Lancer l'interface Gradio
GradioUI(agent).launch()