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 |
|
@@ -15,22 +15,23 @@ def index():
|
|
15 |
def search():
|
16 |
q = request.args.get("q")
|
17 |
max_results = int(request.args.get("max_results", 10))
|
|
|
18 |
safesearch = request.args.get("safesearch", "moderate")
|
19 |
region = request.args.get("region", "wt-wt")
|
20 |
backend = request.args.get("backend", "api")
|
21 |
try:
|
22 |
with WEBS() as webs:
|
23 |
-
results = webs.text(keywords=q, region=region, safesearch=safesearch, backend=backend, max_results=max_results)
|
24 |
-
# Extract
|
25 |
search_results = [
|
26 |
{
|
27 |
-
'title': result.title,
|
28 |
'description': result.description
|
29 |
} for result in results
|
30 |
]
|
31 |
-
return search_results # Return
|
32 |
except Exception as e:
|
33 |
-
return {"error": f"Error during search: {e}"}
|
34 |
|
35 |
if __name__ == "__main__":
|
36 |
port = int(os.environ.get('PORT', 7860))
|
|
|
1 |
+
from flask import Flask, render_template, request, jsonify
|
2 |
import requests
|
3 |
import os
|
4 |
+
from webscout import WEBS, transcriber
|
5 |
|
6 |
app = Flask(__name__)
|
7 |
|
|
|
15 |
def search():
|
16 |
q = request.args.get("q")
|
17 |
max_results = int(request.args.get("max_results", 10))
|
18 |
+
timelimit = request.args.get("timelimit") # Timelimit is optional
|
19 |
safesearch = request.args.get("safesearch", "moderate")
|
20 |
region = request.args.get("region", "wt-wt")
|
21 |
backend = request.args.get("backend", "api")
|
22 |
try:
|
23 |
with WEBS() as webs:
|
24 |
+
results = webs.text(keywords=q, region=region, safesearch=safesearch, timelimit=timelimit, backend=backend, max_results=max_results)
|
25 |
+
# Extract data you want to display
|
26 |
search_results = [
|
27 |
{
|
28 |
+
'title': result.title,
|
29 |
'description': result.description
|
30 |
} for result in results
|
31 |
]
|
32 |
+
return jsonify(search_results) # Return as JSON
|
33 |
except Exception as e:
|
34 |
+
return jsonify({"error": f"Error during search: {e}"})
|
35 |
|
36 |
if __name__ == "__main__":
|
37 |
port = int(os.environ.get('PORT', 7860))
|