fernvndes commited on
Commit
086df54
·
verified ·
1 Parent(s): 9665c0f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -24
app.py CHANGED
@@ -1,14 +1,13 @@
1
- from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
2
  import datetime
3
  import pytz
4
  import yaml
5
- import requests
6
  import random
7
  from tools.final_answer import FinalAnswerTool
8
 
9
  from Gradio_UI import GradioUI
10
 
11
- # Below is an example of a tool that does nothing. Amaze us with your creativity !
12
  @tool
13
  def generate_random_number(start: int, end: int) -> int:
14
  """Gera um número aleatório entre 'start' e 'end'.
@@ -22,47 +21,43 @@ def generate_random_number(start: int, end: int) -> int:
22
  """
23
  return random.randint(start, end)
24
 
25
-
26
-
27
  @tool
28
  def get_current_time_in_timezone(timezone: str) -> str:
29
  """A tool that fetches the current local time in a specified timezone.
 
30
  Args:
31
  timezone: A string representing a valid timezone (e.g., 'America/New_York').
32
  """
33
  try:
34
- # Create timezone object
35
  tz = pytz.timezone(timezone)
36
- # Get current time in that timezone
37
  local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
38
  return f"The current local time in {timezone} is: {local_time}"
39
  except Exception as e:
40
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
41
 
42
-
43
  final_answer = FinalAnswerTool()
44
 
45
- # If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
46
- # model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
47
-
48
  model = HfApiModel(
49
- max_tokens=2096,
50
- temperature=0.5,
51
- #model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded
52
- model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud',# it is possible that this model may be overloaded
53
- custom_role_conversions=None,
54
  )
55
 
56
-
57
- # Import tool from Hub
58
- image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
59
-
60
  with open("prompts.yaml", 'r') as stream:
61
  prompt_templates = yaml.safe_load(stream)
62
-
 
63
  agent = CodeAgent(
64
  model=model,
65
- tools=[final_answer, generate_random_number], ## add your tools here (don't remove final answer)
66
  max_steps=6,
67
  verbosity_level=1,
68
  grammar=None,
@@ -72,5 +67,5 @@ agent = CodeAgent(
72
  prompt_templates=prompt_templates
73
  )
74
 
75
-
76
- GradioUI(agent).launch()
 
1
+ from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool, tool
2
  import datetime
3
  import pytz
4
  import yaml
 
5
  import random
6
  from tools.final_answer import FinalAnswerTool
7
 
8
  from Gradio_UI import GradioUI
9
 
10
+ # Ferramenta para gerar um número aleatório entre 'start' e 'end'
11
  @tool
12
  def generate_random_number(start: int, end: int) -> int:
13
  """Gera um número aleatório entre 'start' e 'end'.
 
21
  """
22
  return random.randint(start, end)
23
 
24
+ # Ferramenta para obter a hora local em um fuso horário específico
 
25
  @tool
26
  def get_current_time_in_timezone(timezone: str) -> str:
27
  """A tool that fetches the current local time in a specified timezone.
28
+
29
  Args:
30
  timezone: A string representing a valid timezone (e.g., 'America/New_York').
31
  """
32
  try:
33
+ # Criando objeto de fuso horário
34
  tz = pytz.timezone(timezone)
35
+ # Obtendo a hora atual no fuso horário especificado
36
  local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
37
  return f"The current local time in {timezone} is: {local_time}"
38
  except Exception as e:
39
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
40
 
41
+ # Instanciando a ferramenta de resposta final
42
  final_answer = FinalAnswerTool()
43
 
44
+ # Modelo da Hugging Face (endereços e credenciais)
 
 
45
  model = HfApiModel(
46
+ max_tokens=2096,
47
+ temperature=0.5,
48
+ # Se o modelo acima estiver sobrecarregado, use este:
49
+ model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud',
50
+ custom_role_conversions=None,
51
  )
52
 
53
+ # Carregando os templates de prompts a partir de um arquivo YAML
 
 
 
54
  with open("prompts.yaml", 'r') as stream:
55
  prompt_templates = yaml.safe_load(stream)
56
+
57
+ # Criando o agente com ferramentas e modelo
58
  agent = CodeAgent(
59
  model=model,
60
+ tools=[final_answer, generate_random_number], # Adicionando ferramentas personalizadas (não remova final_answer)
61
  max_steps=6,
62
  verbosity_level=1,
63
  grammar=None,
 
67
  prompt_templates=prompt_templates
68
  )
69
 
70
+ # Iniciando a interface Gradio para o agente
71
+ GradioUI(agent).launch()