Superbrida commited on
Commit
80494ac
·
verified ·
1 Parent(s): 12437db

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -56
app.py CHANGED
@@ -1,65 +1,47 @@
1
- da smolagents importa CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool, strumento
2
- importa datetime
3
- importa richieste
4
- importa pytz
5
- importa yaml
6
- da tools.final_answer importa FinalAnswerTool
7
-
8
- da Gradio_UI importa GradioUI
9
-
10
- # Di seguito è riportato un esempio di uno strumento che non fa nulla. Stupiscici con la tua creatività!
11
-
12
- def my_custom_tool ( arg1: str , arg2: int )-> str : # è importante specificare il tipo di ritorno
13
- # Mantieni questo formato per la descrizione dello strumento / descrizione degli argomenti ma sentiti libero di modificare lo strumento
14
- """Uno strumento che non fa ancora nulla
15
- Argomenti:
16
- arg1: il primo argomento
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
- return f"Errore durante il recupero dell'ora per il fuso orario ' {timezone} ': { str (e)} "
35
 
 
36
 
37
- risposta_finale = StrumentoRispostaFinale()
38
- modello = HfApiModel(
39
- numero massimo di token = 2096 ,
40
- temperatura= 0,5 ,
41
- model_id= 'Qwen/Qwen2.5-Coder-32B-Istruzione' ,
42
- custom_role_conversions= Nessuno ,
43
  )
44
 
 
 
45
 
46
- # Strumento di importazione dall'hub
47
- image_generation_tool = load_tool( "agents-course/text-to-image" , trust_remote_code= True )
48
-
49
- con open ( "prompts.yaml" , 'r' ) come flusso:
50
- prompt_templates = yaml.safe_load(flusso)
51
 
52
- agente = CodeAgent(
53
- modello=modello,
54
- tools=[final_answer], # aggiungi i tuoi strumenti qui (non rimuovere final_answer)
55
- max_steps= 6 ,
56
- livello_di_verbosità= 1 ,
57
- grammatica= Nessuna ,
58
- planning_interval= Nessuno ,
59
- nome= Nessuno ,
60
- descrizione= Nessuno ,
61
- prompt_templates=template_prompt
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()