Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -151,25 +151,24 @@ def wiki_search(query: str) -> str:
|
|
| 151 |
"""
|
| 152 |
|
| 153 |
encoded_query = urllib.parse.quote(query)
|
| 154 |
-
|
| 155 |
url = f"https://en.wikipedia.org/api/rest_v1/page/summary/{encoded_query}"
|
| 156 |
|
| 157 |
try:
|
| 158 |
-
|
| 159 |
|
| 160 |
-
|
| 161 |
-
|
| 162 |
|
| 163 |
-
|
| 164 |
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
|
| 171 |
except Exception as e:
|
| 172 |
-
|
| 173 |
|
| 174 |
final_answer = FinalAnswerTool()
|
| 175 |
|
|
|
|
| 151 |
"""
|
| 152 |
|
| 153 |
encoded_query = urllib.parse.quote(query)
|
|
|
|
| 154 |
url = f"https://en.wikipedia.org/api/rest_v1/page/summary/{encoded_query}"
|
| 155 |
|
| 156 |
try:
|
| 157 |
+
response = requests.get(url, timeout=10)
|
| 158 |
|
| 159 |
+
if response.status_code != 200:
|
| 160 |
+
return "No Wikipedia page found."
|
| 161 |
|
| 162 |
+
data = response.json()
|
| 163 |
|
| 164 |
+
return {
|
| 165 |
+
"title": data.get("title"),
|
| 166 |
+
"summary": data.get("extract"),
|
| 167 |
+
"url": data.get("content_urls", {}).get("desktop", {}).get("page"),
|
| 168 |
+
}
|
| 169 |
|
| 170 |
except Exception as e:
|
| 171 |
+
return f"Error fetching Wikipedia data: {str(e)}"
|
| 172 |
|
| 173 |
final_answer = FinalAnswerTool()
|
| 174 |
|