Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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
|
| 13 |
-
"""
|
|
|
|
| 14 |
Args:
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
| 16 |
"""
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
return f"
|
| 23 |
-
|
| 24 |
-
return f"
|
| 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],
|
| 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()
|