Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -35,6 +35,44 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 35 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 36 |
|
| 37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
final_answer = FinalAnswerTool()
|
| 39 |
|
| 40 |
# 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:
|
|
@@ -64,7 +102,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 64 |
|
| 65 |
agent = CodeAgent(
|
| 66 |
model=model,
|
| 67 |
-
tools=[final_answer,
|
| 68 |
max_steps=6,
|
| 69 |
verbosity_level=1,
|
| 70 |
grammar=None,
|
|
|
|
| 35 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 36 |
|
| 37 |
|
| 38 |
+
|
| 39 |
+
@tool
|
| 40 |
+
def get_last_match(team: str) -> str:
|
| 41 |
+
"""
|
| 42 |
+
Get the last 5 matches of a team introduced.
|
| 43 |
+
|
| 44 |
+
Args:
|
| 45 |
+
team: string representing a football team name
|
| 46 |
+
"""
|
| 47 |
+
search_query = f"{team} last 5 matches"
|
| 48 |
+
search_results = DuckDuckGoSearchTool().run(search_query)
|
| 49 |
+
|
| 50 |
+
matches = []
|
| 51 |
+
# Iterate through search results to find matches
|
| 52 |
+
for result in search_results:
|
| 53 |
+
snippet = result.get('snippet', '').lower()
|
| 54 |
+
# Check if snippet contains match-related keywords
|
| 55 |
+
if ' vs ' in snippet or 'match' in snippet or 'result' in snippet:
|
| 56 |
+
# Split snippet into lines to parse each match
|
| 57 |
+
lines = result['snippet'].split('\n')
|
| 58 |
+
for line in lines:
|
| 59 |
+
# Look for lines indicating a match (e.g., containing 'vs' or dates)
|
| 60 |
+
if ' vs ' in line or (' vs. ' in line) or (' - ' in line and ('win' in line or 'draw' in line or 'loss' in line)):
|
| 61 |
+
match_info = line.strip()
|
| 62 |
+
matches.append(match_info)
|
| 63 |
+
if len(matches) >= 5:
|
| 64 |
+
break
|
| 65 |
+
if len(matches) >= 5:
|
| 66 |
+
break
|
| 67 |
+
|
| 68 |
+
if not matches:
|
| 69 |
+
return f"No recent matches found for the team."
|
| 70 |
+
|
| 71 |
+
# Format the last 5 matches
|
| 72 |
+
formatted_matches = "\n".join(matches[:5])
|
| 73 |
+
return formatted_matches
|
| 74 |
+
|
| 75 |
+
|
| 76 |
final_answer = FinalAnswerTool()
|
| 77 |
|
| 78 |
# 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:
|
|
|
|
| 102 |
|
| 103 |
agent = CodeAgent(
|
| 104 |
model=model,
|
| 105 |
+
tools=[final_answer, get_last_match, image_generation_tool], ## add your tools here (don't remove final answer)
|
| 106 |
max_steps=6,
|
| 107 |
verbosity_level=1,
|
| 108 |
grammar=None,
|