huaholou's picture
meteo
f74a591 verified
raw
history blame
2.52 kB
from smolagents import CodeAgent, HfApiModel, load_tool, tool
from tools.final_answer import FinalAnswerTool
from Gradio_UI import GradioUI
import requests
import yaml
# ----------------------------
# 1️⃣ OUTIL : MÉTÉO À PARIS
# ----------------------------
@tool
def get_weather_paris() -> str:
"""Renvoie la météo actuelle à Paris (température + description)."""
try:
url = "https://api.open-meteo.com/v1/forecast?latitude=48.8566&longitude=2.3522&current_weather=true"
response = requests.get(url).json()
weather = response["current_weather"]
temperature = weather["temperature"]
weather_code = weather["weathercode"]
descriptions = {
0: "ciel clair",
1: "principalement clair",
2: "partiellement nuageux",
3: "couvert",
45: "brouillard",
48: "brouillard givrant",
51: "bruine légère",
53: "bruine",
55: "bruine forte",
61: "pluie légère",
63: "pluie",
65: "pluie forte",
71: "neige légère",
73: "neige",
75: "neige forte",
}
description = descriptions.get(weather_code, "conditions météo inconnues")
return f"À Paris, il fait {temperature}°C avec un {description}."
except Exception as e:
return f"Erreur lors de la récupération de la météo : {str(e)}"
# ---------------------------------------------------
# 2️⃣ OUTIL : GÉNÉRATION D’IMAGE
# ---------------------------------------------------
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
# ---------------------------------
# 3️⃣ CHARGEMENT DU PROMPT SYSTÈME
# ---------------------------------
with open("prompts.yaml", "r") as stream:
prompt_templates = yaml.safe_load(stream)
# -------------------------
# 4️⃣ MODÈLE UTILISÉ
# -------------------------
model = HfApiModel(
model_id="Qwen/Qwen2.5-Coder-32B-Instruct",
max_tokens=2048,
temperature=0.5,
)
# -------------------------
# 5️⃣ CRÉATION DE L’AGENT
# -------------------------
final_answer = FinalAnswerTool()
agent = CodeAgent(
model=model,
tools=[final_answer, get_weather_paris, image_generation_tool],
max_steps=6,
verbosity_level=1,
prompt_templates=prompt_templates
)
# -------------------------
# 6️⃣ LANCEMENT DE GRADIO
# -------------------------
GradioUI(agent).launch()