Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,14 +9,70 @@ from Gradio_UI import GradioUI
|
|
| 9 |
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
@tool
|
| 12 |
-
def
|
| 13 |
-
|
| 14 |
-
|
| 15 |
Args:
|
| 16 |
-
|
| 17 |
-
|
| 18 |
"""
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 9 |
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
@tool
|
| 12 |
+
def buscar_duckduckgo(termo: str, num_resultados: int = 5) -> str:
|
| 13 |
+
"""Busca real na web usando DuckDuckGo (gratuito, sem API key).
|
| 14 |
+
|
| 15 |
Args:
|
| 16 |
+
termo: Termo para buscar
|
| 17 |
+
num_resultados: Quantidade de resultados (máximo 10)
|
| 18 |
"""
|
| 19 |
+
if not termo.strip():
|
| 20 |
+
return "❌ Termo de busca não pode estar vazio!"
|
| 21 |
+
|
| 22 |
+
if num_resultados > 10:
|
| 23 |
+
num_resultados = 10
|
| 24 |
+
|
| 25 |
+
try:
|
| 26 |
+
# DuckDuckGo Instant Answer API (gratuita)
|
| 27 |
+
url = "https://api.duckduckgo.com/"
|
| 28 |
+
params = {
|
| 29 |
+
'q': termo,
|
| 30 |
+
'format': 'json',
|
| 31 |
+
'no_html': '1',
|
| 32 |
+
'skip_disambig': '1'
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
response = requests.get(url, params=params, timeout=10)
|
| 36 |
+
|
| 37 |
+
if response.status_code == 200:
|
| 38 |
+
data = response.json()
|
| 39 |
+
|
| 40 |
+
resultado = f"🔍 **Busca: '{termo}'**\n\n"
|
| 41 |
+
|
| 42 |
+
# Abstract (resumo principal)
|
| 43 |
+
if data.get('Abstract'):
|
| 44 |
+
resultado += f"📄 **Resumo:**\n{data['Abstract']}\n\n"
|
| 45 |
+
|
| 46 |
+
# Definition (definição)
|
| 47 |
+
if data.get('Definition'):
|
| 48 |
+
resultado += f"📚 **Definição:**\n{data['Definition']}\n\n"
|
| 49 |
+
|
| 50 |
+
# Related Topics
|
| 51 |
+
if data.get('RelatedTopics'):
|
| 52 |
+
resultado += "🔗 **Tópicos Relacionados:**\n"
|
| 53 |
+
for i, topic in enumerate(data['RelatedTopics'][:num_resultados], 1):
|
| 54 |
+
if isinstance(topic, dict) and topic.get('Text'):
|
| 55 |
+
resultado += f"{i}. {topic['Text'][:100]}...\n"
|
| 56 |
+
resultado += "\n"
|
| 57 |
+
|
| 58 |
+
# Answer (resposta direta)
|
| 59 |
+
if data.get('Answer'):
|
| 60 |
+
resultado += f"💡 **Resposta Direta:**\n{data['Answer']}\n\n"
|
| 61 |
+
|
| 62 |
+
if not any([data.get('Abstract'), data.get('Definition'),
|
| 63 |
+
data.get('RelatedTopics'), data.get('Answer')]):
|
| 64 |
+
resultado += "ℹ️ Nenhum resultado específico encontrado para este termo.\n"
|
| 65 |
+
resultado += "💡 Tente termos mais específicos ou diferentes."
|
| 66 |
+
|
| 67 |
+
return resultado
|
| 68 |
+
|
| 69 |
+
else:
|
| 70 |
+
return f"❌ Erro na busca: Status {response.status_code}"
|
| 71 |
+
|
| 72 |
+
except requests.RequestException as e:
|
| 73 |
+
return f"❌ Erro de conexão: {e}"
|
| 74 |
+
except Exception as e:
|
| 75 |
+
return f"❌ Erro inesperado: {e}"
|
| 76 |
|
| 77 |
@tool
|
| 78 |
def get_current_time_in_timezone(timezone: str) -> str:
|