Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,19 +4,48 @@ import requests
|
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
|
|
|
| 7 |
|
| 8 |
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 |
-
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
| 15 |
Args:
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
| 18 |
"""
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
| 7 |
+
from serpapi import GoogleSearch
|
| 8 |
|
| 9 |
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 |
+
from serpapi import GoogleSearch
|
| 14 |
+
|
| 15 |
+
def get_google_scholar(topic: str, api_key: str) -> str:
|
| 16 |
+
"""
|
| 17 |
+
Fetches search results from Google Scholar using SerpAPI.
|
| 18 |
+
|
| 19 |
Args:
|
| 20 |
+
topic (str): The search query topic.
|
| 21 |
+
api_key (str): The API key for accessing SerpAPI.
|
| 22 |
+
|
| 23 |
+
Returns:
|
| 24 |
+
str: Formatted search results or an error message.
|
| 25 |
"""
|
| 26 |
+
params = {
|
| 27 |
+
"engine": "google_scholar",
|
| 28 |
+
"q": topic,
|
| 29 |
+
"api_key": api_key
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
try:
|
| 33 |
+
search = GoogleSearch(params)
|
| 34 |
+
results = search.get_dict()
|
| 35 |
+
|
| 36 |
+
# Handle missing 'organic_results' key
|
| 37 |
+
organic_results = results.get("organic_results", [])
|
| 38 |
+
|
| 39 |
+
if not organic_results:
|
| 40 |
+
return "No results found for this query."
|
| 41 |
+
|
| 42 |
+
# Formatting the results in a readable way
|
| 43 |
+
formatted_results = "\n".join([f"{i+1}. {res.get('title', 'No Title')} - {res.get('link', 'No Link')}" for i, res in enumerate(organic_results)])
|
| 44 |
+
|
| 45 |
+
return f"Here are the results:\n{formatted_results}"
|
| 46 |
+
|
| 47 |
+
except Exception as e:
|
| 48 |
+
return f"Error fetching results: {str(e)}"
|
| 49 |
|
| 50 |
@tool
|
| 51 |
def get_current_time_in_timezone(timezone: str) -> str:
|