Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,49 +10,34 @@ from Gradio_UI import GradioUI
|
|
| 10 |
|
| 11 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 12 |
@tool
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
"
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
}
|
| 25 |
-
}
|
| 26 |
-
output_type = "string"
|
| 27 |
-
|
| 28 |
-
def forward(self, team_name: str, info_type: str):
|
| 29 |
-
# NOTA: Em produção, o zerozero pode bloquear requests simples.
|
| 30 |
-
# Esta lógica simula a procura e extração.
|
| 31 |
-
search_url = f"https://www.zerozero.pt/search.php?input_search={team_name.replace(' ', '+')}"
|
| 32 |
|
|
|
|
| 33 |
headers = {
|
| 34 |
-
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/
|
| 35 |
}
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
# Aqui precisarias de lógica específica para navegar nas tabelas do ZZ
|
| 46 |
-
# O ZZ usa classes como 'zz-entidade-jogos' ou id='informacao_equipa'
|
| 47 |
-
|
| 48 |
-
return f"Simulação: Encontrei os {info_type} para {team_name}. [Aqui apareceria a lista extraída do HTML]"
|
| 49 |
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
# Para usar no teu CodeAgent:
|
| 54 |
-
# team_tool = ZeroZeroTeamTool()
|
| 55 |
-
# agent = CodeAgent(tools=[team_tool, DuckDuckGoSearchTool()], model=model)
|
| 56 |
|
| 57 |
@tool
|
| 58 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 10 |
|
| 11 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 12 |
@tool
|
| 13 |
+
def get_football_team_info(team_name: str, info_type: str) -> str:
|
| 14 |
+
"""A tool that fetches football team information (results or upcoming matches) from ZeroZero.
|
| 15 |
+
Args:
|
| 16 |
+
team_name: The name of the football team (e.g., 'Benfica', 'Sporting').
|
| 17 |
+
info_type: Type of information to fetch: 'resultados' (past matches) or 'proximos' (future matches).
|
| 18 |
+
"""
|
| 19 |
+
try:
|
| 20 |
+
# Formata o nome para a busca do ZeroZero
|
| 21 |
+
search_query = team_name.replace(" ", "+")
|
| 22 |
+
base_url = "https://www.zerozero.pt"
|
| 23 |
+
search_url = f"{base_url}/search.php?input_search={search_query}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
+
# Headers para evitar bloqueio imediato (fingir ser um browser)
|
| 26 |
headers = {
|
| 27 |
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36"
|
| 28 |
}
|
| 29 |
+
|
| 30 |
+
response = requests.get(search_url, headers=headers, timeout=10)
|
| 31 |
+
|
| 32 |
+
if response.status_code == 200:
|
| 33 |
+
# Aqui o Agente recebe o link de pesquisa se não conseguirmos fazer o parse direto
|
| 34 |
+
# Mas vamos devolver uma resposta estruturada:
|
| 35 |
+
return f"Podes consultar os {info_type} do {team_name} diretamente no ZeroZero aqui: {search_url}"
|
| 36 |
+
else:
|
| 37 |
+
return f"O ZeroZero devolveu um erro {response.status_code}. Tenta pesquisar manualmente por {team_name}."
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
+
except Exception as e:
|
| 40 |
+
return f"Erro ao tentar aceder a informações do {team_name}: {str(e)}"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
@tool
|
| 43 |
def get_current_time_in_timezone(timezone: str) -> str:
|