Spaces:
Build error
Build error
from flask import Flask, render_template, request, jsonify | |
import requests | |
import os | |
from webscout import WEBS, transcriber | |
app = Flask(__name__) | |
BASE_URL = "https://oevortex-webscout-api.hf.space" | |
def index(): | |
return render_template("index.html") | |
def search(): | |
q = request.args.get("q") | |
max_results = int(request.args.get("max_results", 10)) | |
timelimit = request.args.get("timelimit") # Timelimit is optional | |
safesearch = request.args.get("safesearch", "moderate") | |
region = request.args.get("region", "wt-wt") | |
backend = request.args.get("backend", "api") | |
try: | |
with WEBS() as webs: | |
results = webs.text(keywords=q, region=region, safesearch=safesearch, timelimit=timelimit, backend=backend, max_results=max_results) | |
# Extract data you want to display | |
search_results = [ | |
{ | |
'title': result.title, | |
'description': result.description | |
} for result in results | |
] | |
return jsonify(search_results) # Return as JSON | |
except Exception as e: | |
return jsonify({"error": f"Error during search: {e}"}) | |
if __name__ == "__main__": | |
port = int(os.environ.get('PORT', 7860)) | |
app.run(host='0.0.0.0', port=port) |