Spaces:
Build error
Build error
File size: 1,437 Bytes
b7d38b4 2b10390 b7d38b4 abf5754 d52ce34 abf5754 b7d38b4 abf5754 d52ce34 abf5754 d52ce34 abf5754 b7d38b4 d52ce34 b7d38b4 abf5754 d52ce34 abf5754 d0bba4a |
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 |
from flask import Flask, render_template, request
import requests
import os
from webscout import WEBS, transcriber
app = Flask(__name__)
BASE_URL = "https://oevortex-webscout-api.hf.space"
@app.route("/", methods=["GET", "POST"])
def index():
return render_template("index.html")
@app.route("/api/suggestions", methods=["GET"])
def get_suggestions():
search_query = request.args.get("q")
api_endpoint = f"{BASE_URL}/api/suggestions?q={search_query}"
response = requests.get(api_endpoint)
return response.json()
@app.get("/api/search")
async def search(
q: str,
max_results: int = 10,
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, backend=backend, max_results=max_results)
return JSONResponse(content=jsonable_encoder(results))
except Exception as e:
raise HTTPException(status_code=500, detail=f"Error during search: {e}")
@app.route("/api/answers", methods=["GET"])
def get_people_also_search():
search_query = request.args.get("q")
api_endpoint = f"{BASE_URL}/api/answers?q={search_query}"
response = requests.get(api_endpoint)
return response.json()
if __name__ == "__main__":
port = int(os.environ.get('PORT', 7860))
app.run(host='0.0.0.0', port=port) |