Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -40,49 +40,6 @@ def get_random_joke() -> str:
|
|
| 40 |
return f"An error occurred: {str(e)}"
|
| 41 |
|
| 42 |
|
| 43 |
-
@tool
|
| 44 |
-
def question_about_car_km77(query: str) -> str:
|
| 45 |
-
"""
|
| 46 |
-
Queries https://www.km77.com/ for information about a specific car or topic.
|
| 47 |
-
|
| 48 |
-
Args:
|
| 49 |
-
query (str): The keywords or phrase to search for on km77.
|
| 50 |
-
|
| 51 |
-
Returns:
|
| 52 |
-
str: A short text containing the top search results or an error message if none are found.
|
| 53 |
-
"""
|
| 54 |
-
try:
|
| 55 |
-
search_url = f"https://www.km77.com/buscador/?q={query}"
|
| 56 |
-
response = requests.get(search_url, timeout=10)
|
| 57 |
-
|
| 58 |
-
if response.status_code != 200:
|
| 59 |
-
return f"Error accediendo a km77. Código de estado HTTP: {response.status_code}"
|
| 60 |
-
|
| 61 |
-
soup = BeautifulSoup(response.text, 'html.parser')
|
| 62 |
-
|
| 63 |
-
# Ajusta el selector a la estructura actual de km77
|
| 64 |
-
results = soup.select("div.col-xs-12.col-md-8 a")
|
| 65 |
-
if not results:
|
| 66 |
-
return "No se encontraron resultados para tu búsqueda en km77."
|
| 67 |
-
|
| 68 |
-
answer_lines = []
|
| 69 |
-
for r in results[:5]:
|
| 70 |
-
title = r.get_text(strip=True)
|
| 71 |
-
link = r.get("href")
|
| 72 |
-
# Ajustamos a URL absoluta si empieza con '/'
|
| 73 |
-
if link.startswith('/'):
|
| 74 |
-
link = f"https://www.km77.com{link}"
|
| 75 |
-
answer_lines.append(f"- {title}: {link}")
|
| 76 |
-
|
| 77 |
-
answer = (
|
| 78 |
-
f"**Resultados de km77 para** '{query}':\n\n"
|
| 79 |
-
+ "\n".join(answer_lines)
|
| 80 |
-
)
|
| 81 |
-
|
| 82 |
-
return answer
|
| 83 |
-
|
| 84 |
-
except Exception as e:
|
| 85 |
-
return f"Ocurrió un error al realizar la búsqueda: {str(e)}"
|
| 86 |
|
| 87 |
@tool
|
| 88 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 40 |
return f"An error occurred: {str(e)}"
|
| 41 |
|
| 42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
@tool
|
| 45 |
def get_current_time_in_timezone(timezone: str) -> str:
|