Spaces:
Sleeping
Sleeping
JM8 commited on
Commit ·
ff949ec
1
Parent(s): ae7a494
First agent
Browse files- .gitignore +2 -0
- app.py +45 -2
.gitignore
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.env
|
| 2 |
+
.vscode
|
app.py
CHANGED
|
@@ -3,9 +3,13 @@ import datetime
|
|
| 3 |
import requests
|
| 4 |
import pytz
|
| 5 |
import yaml
|
|
|
|
|
|
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
|
|
|
|
|
|
| 7 |
|
| 8 |
-
|
| 9 |
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
@tool
|
|
@@ -33,8 +37,47 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 33 |
except Exception as e:
|
| 34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
final_answer = FinalAnswerTool()
|
|
|
|
| 38 |
|
| 39 |
# 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:
|
| 40 |
# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
|
@@ -55,7 +98,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 55 |
|
| 56 |
agent = CodeAgent(
|
| 57 |
model=model,
|
| 58 |
-
tools=[final_answer], ## add your tools here (don't remove final answer)
|
| 59 |
max_steps=6,
|
| 60 |
verbosity_level=1,
|
| 61 |
grammar=None,
|
|
|
|
| 3 |
import requests
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
+
import os
|
| 7 |
+
from Gradio_UI import GradioUI
|
| 8 |
from tools.final_answer import FinalAnswerTool
|
| 9 |
+
from tools.web_search import DuckDuckGoSearchTool
|
| 10 |
+
from dotenv import load_env
|
| 11 |
|
| 12 |
+
load_env()
|
| 13 |
|
| 14 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 15 |
@tool
|
|
|
|
| 37 |
except Exception as e:
|
| 38 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 39 |
|
| 40 |
+
@tool
|
| 41 |
+
def get_laliga_team_ranking(team_name: str) -> int:
|
| 42 |
+
"""Fetches the current ranking of a LaLiga team.
|
| 43 |
+
|
| 44 |
+
Args:
|
| 45 |
+
team_name: The name of the LaLiga team (e.g., 'Real Madrid CF').
|
| 46 |
+
|
| 47 |
+
Returns:
|
| 48 |
+
The team's ranking as an integer.
|
| 49 |
+
"""
|
| 50 |
+
try:
|
| 51 |
+
url = "https://api.football-data.org/v4/competitions/PD/standings"
|
| 52 |
+
headers = {"X-Auth-Token": os.getenv("FOOTBALL_DATA_API")} # Replace with a valid API key
|
| 53 |
+
response = requests.get(url, headers=headers)
|
| 54 |
+
data = response.json()
|
| 55 |
+
|
| 56 |
+
for table in data['standings']:
|
| 57 |
+
for team in table['table']:
|
| 58 |
+
if team['team']['name'].lower() == team_name.lower():
|
| 59 |
+
return team['position']
|
| 60 |
+
|
| 61 |
+
return -1 # Return -1 if the team is not found
|
| 62 |
+
except Exception as e:
|
| 63 |
+
return -1 # Return -1 if there is an error
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
@tool
|
| 67 |
+
def generate_image(prompt: str) -> str:
|
| 68 |
+
"""Generates an image based on a given text prompt.
|
| 69 |
+
|
| 70 |
+
Args:
|
| 71 |
+
prompt: A text description of the image to generate.
|
| 72 |
+
|
| 73 |
+
Returns:
|
| 74 |
+
A URL to the generated image.
|
| 75 |
+
"""
|
| 76 |
+
return image_generation_tool.run(prompt)
|
| 77 |
+
|
| 78 |
|
| 79 |
final_answer = FinalAnswerTool()
|
| 80 |
+
web_search = DuckDuckGoSearchTool()
|
| 81 |
|
| 82 |
# 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:
|
| 83 |
# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
|
|
|
| 98 |
|
| 99 |
agent = CodeAgent(
|
| 100 |
model=model,
|
| 101 |
+
tools=[final_answer, get_current_time_in_timezone, web_search, get_laliga_team_ranking, generate_image], ## add your tools here (don't remove final answer)
|
| 102 |
max_steps=6,
|
| 103 |
verbosity_level=1,
|
| 104 |
grammar=None,
|