File size: 1,288 Bytes
b7d38b4
 
2b10390
9fe2fb9
abf5754
d52ce34
abf5754
b7d38b4
abf5754
d52ce34
abf5754
d52ce34
abf5754
9fe2fb9
 
 
 
 
 
 
b7d38b4
 
 
ae964f3
 
 
 
 
 
 
 
b7d38b4
9fe2fb9
b7d38b4
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
from flask import Flask, render_template, request
import requests
import os
from webscout import WEBS

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/search", methods=["GET"])
def search():
    q = request.args.get("q")
    max_results = int(request.args.get("max_results", 10))
    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, backend=backend, max_results=max_results)
            # Extract the data you want to display (adjust based on webscout's structure)
            search_results = [
                {
                    'title': result.title, 
                    'description': result.description
                } for result in results
            ]
            return search_results  # Return the extracted data
    except Exception as e:
        return {"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)