Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
from flask import Flask, render_template, request
|
2 |
import requests
|
3 |
import os
|
4 |
-
from webscout import WEBS
|
5 |
|
6 |
app = Flask(__name__)
|
7 |
|
@@ -18,22 +18,19 @@ def get_suggestions():
|
|
18 |
response = requests.get(api_endpoint)
|
19 |
return response.json()
|
20 |
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
backend: str = "api"
|
29 |
-
):
|
30 |
-
"""Perform a text search."""
|
31 |
try:
|
32 |
with WEBS() as webs:
|
33 |
results = webs.text(keywords=q, region=region, safesearch=safesearch, backend=backend, max_results=max_results)
|
34 |
-
return
|
35 |
except Exception as e:
|
36 |
-
|
37 |
|
38 |
@app.route("/api/answers", methods=["GET"])
|
39 |
def get_people_also_search():
|
@@ -42,7 +39,6 @@ def get_people_also_search():
|
|
42 |
response = requests.get(api_endpoint)
|
43 |
return response.json()
|
44 |
|
45 |
-
|
46 |
if __name__ == "__main__":
|
47 |
port = int(os.environ.get('PORT', 7860))
|
48 |
app.run(host='0.0.0.0', port=port)
|
|
|
1 |
from flask import Flask, render_template, request
|
2 |
import requests
|
3 |
import os
|
4 |
+
from webscout import WEBS
|
5 |
|
6 |
app = Flask(__name__)
|
7 |
|
|
|
18 |
response = requests.get(api_endpoint)
|
19 |
return response.json()
|
20 |
|
21 |
+
@app.route("/api/search", methods=["GET"])
|
22 |
+
def search():
|
23 |
+
q = request.args.get("q")
|
24 |
+
max_results = int(request.args.get("max_results", 10))
|
25 |
+
safesearch = request.args.get("safesearch", "moderate")
|
26 |
+
region = request.args.get("region", "wt-wt")
|
27 |
+
backend = request.args.get("backend", "api")
|
|
|
|
|
|
|
28 |
try:
|
29 |
with WEBS() as webs:
|
30 |
results = webs.text(keywords=q, region=region, safesearch=safesearch, backend=backend, max_results=max_results)
|
31 |
+
return results
|
32 |
except Exception as e:
|
33 |
+
return {"error": f"Error during search: {e}"}
|
34 |
|
35 |
@app.route("/api/answers", methods=["GET"])
|
36 |
def get_people_also_search():
|
|
|
39 |
response = requests.get(api_endpoint)
|
40 |
return response.json()
|
41 |
|
|
|
42 |
if __name__ == "__main__":
|
43 |
port = int(os.environ.get('PORT', 7860))
|
44 |
app.run(host='0.0.0.0', port=port)
|