jayur commited on
Commit
f4620ba
·
verified ·
1 Parent(s): 60d8485

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -5
app.py CHANGED
@@ -11,15 +11,19 @@ from Gradio_UI import GradioUI
11
  @tool
12
  def lingua_stats(language:str)->str: #it's import to specify the return type
13
  #Keep this format for the description / args / args description but feel free to modify the tool
14
- """A tool that retrieves the number of speakers for the language
15
  Args:
16
  language: Name of the language e.g. Tamil, Hindi, English
17
  """
18
  try:
19
- # Create DuckDuckGo web search object
20
- search = DuckDuckGoSearchRun()
21
- lang_spkrs = search.invoke(f"How many people speak {language}")
22
- return f"The {language} speaking population is : {lang_spkrs}"
 
 
 
 
23
  except Exception as e:
24
  return f"Error: Search failed for {language}"
25
 
 
11
  @tool
12
  def lingua_stats(language:str)->str: #it's import to specify the return type
13
  #Keep this format for the description / args / args description but feel free to modify the tool
14
+ """A tool that retrieves the number of speakers for the language as a percentage of the world population
15
  Args:
16
  language: Name of the language e.g. Tamil, Hindi, English
17
  """
18
  try:
19
+ # Create agent web search object
20
+ from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel
21
+
22
+ model = HfApiModel()
23
+ agent = CodeAgent(tools=[DuckDuckGoSearchTool()], model=model)
24
+ world_population = agent.run("What is the world population?")
25
+ lang_spkrs = agent.run(f"How many people in the speak {language}?")
26
+ return f"The percentage of {language} speaking population in the world is : {lang_spkrs}/{world_population}"
27
  except Exception as e:
28
  return f"Error: Search failed for {language}"
29