tournas commited on
Commit
f8ded7c
·
verified ·
1 Parent(s): d7450e8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -17
app.py CHANGED
@@ -1,17 +1,18 @@
 
1
  import datetime
2
  import requests
3
  import pytz
4
  import yaml
5
  import os
6
- from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool, tool
7
  from tools.final_answer import FinalAnswerTool
 
8
  from Gradio_UI import GradioUI
9
 
10
  api_key = os.getenv("ALPHAVANTAGE")
11
  if not api_key:
12
- raise ValueError("\u26a0\ufe0f Key is missing! Add it as a Secret in Hugging Face Spaces.")
13
 
14
- # Define a tool to retrieve the Discounted Cash Flow (DCF) of a company
15
  @tool
16
  def get_dcf_of_company(api_key: str, company_name: str) -> str:
17
  """A tool that retrieves the DCF of a company based on its name.
@@ -57,29 +58,25 @@ def get_dcf_of_company(api_key: str, company_name: str) -> str:
57
  except Exception as e:
58
  return f"Error calculating DCF for company '{company_name}': {str(e)}"
59
 
60
- # Final answer tool
61
- final_answer = FinalAnswerTool()
62
 
63
- # Model
64
- token_limit = 2096
65
  model = HfApiModel(
66
- max_tokens=token_limit,
67
- temperature=0.5,
68
- model_id='Qwen/Qwen2.5-Coder-32B-Instruct', # This model might be overloaded
69
- custom_role_conversions=None,
70
  )
71
 
72
- # Load tool from the Hub
 
73
  image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
74
 
75
- # Load prompt templates
76
  with open("prompts.yaml", 'r') as stream:
77
  prompt_templates = yaml.safe_load(stream)
78
-
79
- # Create the agent
80
  agent = CodeAgent(
81
  model=model,
82
- tools=[final_answer, get_dcf_of_company], # Adding tools
83
  max_steps=6,
84
  verbosity_level=1,
85
  grammar=None,
@@ -89,5 +86,5 @@ agent = CodeAgent(
89
  prompt_templates=prompt_templates
90
  )
91
 
92
- # Launch the Gradio UI
93
  GradioUI(agent).launch()
 
1
+ from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool, tool
2
  import datetime
3
  import requests
4
  import pytz
5
  import yaml
6
  import os
 
7
  from tools.final_answer import FinalAnswerTool
8
+
9
  from Gradio_UI import GradioUI
10
 
11
  api_key = os.getenv("ALPHAVANTAGE")
12
  if not api_key:
13
+ raise ValueError("\u26a0\ufe0f Key is missing! Add it as a Secret in Hugging Face Spaces.")
14
 
15
+ # Below is an example of a tool that does nothing. Amaze us with your creativity!
16
  @tool
17
  def get_dcf_of_company(api_key: str, company_name: str) -> str:
18
  """A tool that retrieves the DCF of a company based on its name.
 
58
  except Exception as e:
59
  return f"Error calculating DCF for company '{company_name}': {str(e)}"
60
 
 
 
61
 
62
+ final_answer = FinalAnswerTool()
 
63
  model = HfApiModel(
64
+ max_tokens=2096,
65
+ temperature=0.5,
66
+ model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
67
+ custom_role_conversions=None,
68
  )
69
 
70
+
71
+ # Import tool from Hub
72
  image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
73
 
 
74
  with open("prompts.yaml", 'r') as stream:
75
  prompt_templates = yaml.safe_load(stream)
76
+
 
77
  agent = CodeAgent(
78
  model=model,
79
+ tools=[final_answer], # add your tools here (don't remove final_answer)
80
  max_steps=6,
81
  verbosity_level=1,
82
  grammar=None,
 
86
  prompt_templates=prompt_templates
87
  )
88
 
89
+
90
  GradioUI(agent).launch()