Spaces:
Sleeping
Sleeping
Create main.py
Browse files
main.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI
|
| 2 |
+
import wikipedia
|
| 3 |
+
|
| 4 |
+
app = FastAPI()
|
| 5 |
+
|
| 6 |
+
@app.get("/")
|
| 7 |
+
async def get_wikipedia_url(topic: str):
|
| 8 |
+
try:
|
| 9 |
+
# Search for the exact page
|
| 10 |
+
page = wikipedia.page(topic, auto_suggest=False, redirect=True)
|
| 11 |
+
url = page.url
|
| 12 |
+
return {"topic": topic, "url": url}
|
| 13 |
+
except Exception:
|
| 14 |
+
# Default fallback if not found
|
| 15 |
+
return {"topic": topic, "url": "https://en.wikipedia.org/wiki/Main_Page"}
|