Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,65 +1,47 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
arg2: il secondo argomento
|
| 18 |
-
"""
|
| 19 |
-
ritorna "Quale magia costruirai?"
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
def get_current_time_in_timezone ( timezone: str ) -> str :
|
| 23 |
-
"""Uno strumento che recupera l'ora locale corrente in un fuso orario specificato.
|
| 24 |
-
Argomenti:
|
| 25 |
-
fuso orario: una stringa che rappresenta un fuso orario valido (ad esempio, 'America/New_York').
|
| 26 |
-
"""
|
| 27 |
-
prova :
|
| 28 |
-
# Crea oggetto fuso orario
|
| 29 |
-
tz = pytz.timezone(fuso orario)
|
| 30 |
-
# Ottieni l'ora corrente in quel fuso orario
|
| 31 |
-
local_time = datetime.datetime.now(tz).strftime( "%Y-%m-%d %H:%M:%S" )
|
| 32 |
-
return f"L'ora locale corrente in {timezone} è: {local_time} "
|
| 33 |
except Exception as e:
|
| 34 |
-
|
| 35 |
|
|
|
|
| 36 |
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
custom_role_conversions= Nessuno ,
|
| 43 |
)
|
| 44 |
|
|
|
|
|
|
|
| 45 |
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
con open ( "prompts.yaml" , 'r' ) come flusso:
|
| 50 |
-
prompt_templates = yaml.safe_load(flusso)
|
| 51 |
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
tools=[final_answer],
|
| 55 |
-
max_steps=
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
planning_interval=
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
prompt_templates=
|
| 62 |
)
|
| 63 |
|
| 64 |
-
|
| 65 |
-
GradioUI(agente).launch()
|
|
|
|
| 1 |
+
from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool, tool
|
| 2 |
+
import datetime
|
| 3 |
+
import requests
|
| 4 |
+
import pytz
|
| 5 |
+
import yaml
|
| 6 |
+
from tools.final_answer import FinalAnswerTool
|
| 7 |
+
from Gradio_UI import GradioUI
|
| 8 |
+
|
| 9 |
+
# Tool personalizzato per ottenere l'ora attuale a Milano
|
| 10 |
+
@tool
|
| 11 |
+
def get_current_time_milan() -> str:
|
| 12 |
+
"""Restituisce l'ora attuale a Milano."""
|
| 13 |
+
try:
|
| 14 |
+
tz = pytz.timezone('Europe/Rome') # Milano è nella timezone di Roma
|
| 15 |
+
local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
|
| 16 |
+
return f"L'ora attuale a Milano è: {local_time}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
except Exception as e:
|
| 18 |
+
return f"Errore nel recupero dell'ora per Milano: {str(e)}"
|
| 19 |
|
| 20 |
+
final_answer = FinalAnswerTool()
|
| 21 |
|
| 22 |
+
model = HfApiModel(
|
| 23 |
+
max_tokens=2096,
|
| 24 |
+
temperature=0.5,
|
| 25 |
+
model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
|
| 26 |
+
custom_role_conversions=None,
|
|
|
|
| 27 |
)
|
| 28 |
|
| 29 |
+
# Importa lo strumento di generazione immagini dal tool Hub
|
| 30 |
+
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 31 |
|
| 32 |
+
with open("prompts.yaml", 'r') as stream:
|
| 33 |
+
prompt_templates = yaml.safe_load(stream)
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
+
agent = CodeAgent(
|
| 36 |
+
model=model,
|
| 37 |
+
tools=[final_answer, get_current_time_milan], # Aggiunto il nuovo tool
|
| 38 |
+
max_steps=6,
|
| 39 |
+
verbosity_level=1,
|
| 40 |
+
grammar=None,
|
| 41 |
+
planning_interval=None,
|
| 42 |
+
name=None,
|
| 43 |
+
description=None,
|
| 44 |
+
prompt_templates=prompt_templates
|
| 45 |
)
|
| 46 |
|
| 47 |
+
GradioUI(agent).launch()
|
|
|