harryab commited on
Commit
ae96930
·
verified ·
1 Parent(s): 6a98581

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -30
app.py CHANGED
@@ -1,51 +1,44 @@
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
-
8
  from Gradio_UI import GradioUI
9
 
10
- #Marathon training plan
11
  @tool
12
- def get_current_time_in_timezone(timezone: str) -> str:
13
- """A tool that fetches the current local time in a specified timezone.
 
14
  Args:
15
- timezone: A string representing a valid timezone (e.g., 'America/New_York').
 
 
 
16
  """
17
- try:
18
- # Create timezone object
19
- tz = pytz.timezone(timezone)
20
- # Get current time in that timezone
21
- local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
22
- return f"The current local time in {timezone} is: {local_time}"
23
- except Exception as e:
24
- return f"Error fetching time for timezone '{timezone}': {str(e)}"
25
 
26
  final_answer = FinalAnswerTool()
27
 
28
- # 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:
29
- # model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
30
-
31
  model = HfApiModel(
32
- max_tokens=2096,
33
- temperature=0.5,
34
- #model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded
35
- model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud',
36
- custom_role_conversions=None,
37
  )
38
 
39
-
40
- # Import tool from Hub
41
- image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
42
-
43
  with open("prompts.yaml", 'r') as stream:
44
  prompt_templates = yaml.safe_load(stream)
45
-
46
  agent = CodeAgent(
47
  model=model,
48
- tools=[final_answer], ## add your tools here (don't remove final answer)
49
  max_steps=6,
50
  verbosity_level=1,
51
  grammar=None,
@@ -55,5 +48,4 @@ agent = CodeAgent(
55
  prompt_templates=prompt_templates
56
  )
57
 
58
-
59
  GradioUI(agent).launch()
 
1
+ from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool, tool
2
  import datetime
 
3
  import pytz
4
  import yaml
5
  from tools.final_answer import FinalAnswerTool
 
6
  from Gradio_UI import GradioUI
7
 
 
8
  @tool
9
+ def fetch_marathon_plan(goal_time: str) -> str:
10
+ """Fetches a marathon training plan based on a goal time.
11
+
12
  Args:
13
+ goal_time: Desired marathon completion time (e.g., '4:00', '3:30').
14
+
15
+ Returns:
16
+ A link to a training plan or summary of key details.
17
  """
18
+ search_tool = DuckDuckGoSearchTool()
19
+ query = f"marathon training plan {goal_time} site:runnersworld.com"
20
+ results = search_tool.search(query)
21
+
22
+ if results:
23
+ return f"Here is a recommended training plan for {goal_time}: {results[0]['url']}"
24
+ else:
25
+ return f"Could not find a specific plan for {goal_time}, but you can check Runner's World for more details."
26
 
27
  final_answer = FinalAnswerTool()
28
 
 
 
 
29
  model = HfApiModel(
30
+ max_tokens=2096,
31
+ temperature=0.5,
32
+ #model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded
33
+ model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud',
 
34
  )
35
 
 
 
 
 
36
  with open("prompts.yaml", 'r') as stream:
37
  prompt_templates = yaml.safe_load(stream)
38
+
39
  agent = CodeAgent(
40
  model=model,
41
+ tools=[final_answer, fetch_marathon_plan],
42
  max_steps=6,
43
  verbosity_level=1,
44
  grammar=None,
 
48
  prompt_templates=prompt_templates
49
  )
50
 
 
51
  GradioUI(agent).launch()