Spaces:
Runtime error
Runtime error
File size: 566 Bytes
3809b9b fd2f1d1 10da29a fd2f1d1 11ee355 fd2f1d1 11ee355 fd2f1d1 11ee355 10da29a 11ee355 fd2f1d1 3809b9b fd2f1d1 3809b9b fd2f1d1 d3ff814 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from duckduckgo_search import DDGS
app = FastAPI()
# CORS issue fix
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
@app.get("/search")
async def search_duckduckgo(query: str):
try:
with DDGS() as ddgs:
results = ddgs.text(query, max_results=10)
return {"query": query, "results": results}
except Exception as e:
return {"error": str(e)}
|