Spaces:
Build error
Build error
File size: 1,973 Bytes
97f6077 b7d38b4 2b10390 99bfa27 abf5754 97f6077 abf5754 b7d38b4 abf5754 97f6077 b7d38b4 99bfa27 97f6077 ae964f3 99bfa27 ae964f3 97f6077 b7d38b4 97f6077 b7d38b4 abf5754 97f6077 |
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 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
from fastapi import FastAPI, HTTPException
from fastapi.responses import JSONResponse
from fastapi.encoders import jsonable_encoder
from fastapi.staticfiles import StaticFiles
from fastapi.templating import Jinja2Templates
import requests
import os
from webscout import WEBS, transcriber
app = FastAPI()
BASE_URL = "https://oevortex-webscout-api.hf.space"
app.mount("/static", StaticFiles(directory="static"), name="static")
templates = Jinja2Templates(directory="templates")
@app.get("/", response_class=HTMLResponse)
async def index(request: Request):
return templates.TemplateResponse("index.html", {"request": request})
@app.get("/api/suggestions")
async def get_suggestions(q: str):
api_endpoint = f"{BASE_URL}/api/suggestions?q={q}"
response = requests.get(api_endpoint)
return response.json()
@app.get("/api/search")
async def search(
q: str,
max_results: int = 10,
timelimit: Optional[str] = None,
safesearch: str = "moderate",
region: str = "wt-wt",
backend: str = "api"
):
"""Perform a text search."""
try:
with WEBS() as webs:
results = webs.text(keywords=q, region=region, safesearch=safesearch, timelimit=timelimit, backend=backend, max_results=max_results)
# Extract the data you want to display
search_results = [
{
'title': result.title,
'description': result.description
} for result in results
]
return JSONResponse(content=jsonable_encoder(search_results))
except Exception as e:
raise HTTPException(status_code=500, detail=f"Error during search: {e}")
@app.get("/api/answers")
async def get_people_also_search(q: str):
api_endpoint = f"{BASE_URL}/api/answers?q={q}"
response = requests.get(api_endpoint)
return response.json()
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=7860, reload=True) |