FinalProject / app.py
MasterOfHugs's picture
Update app.py
45cc441 verified
raw
history blame
1.17 kB
# 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", token="hf_xxx")
# 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()