KingNish commited on
Commit
abf5754
·
verified ·
1 Parent(s): 8f2dd03

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -0
app.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, render_template, request
2
+ from eel import init, start
3
+ import requests
4
+
5
+ app = Flask(__name__, static_folder='static')
6
+ init("web") # eel will look for web folder
7
+
8
+ BASE_URL = "https://oevortex-webscout-api.hf.space"
9
+
10
+ @app.route('/')
11
+ def index():
12
+ return render_template('index.html')
13
+
14
+ @app.route('/api/suggestions')
15
+ def get_suggestions():
16
+ query = request.args.get('q')
17
+ api_endpoint = f"{BASE_URL}/api/suggestions?q={query}"
18
+ response = requests.get(api_endpoint)
19
+ response.raise_for_status() # Raise an error for bad responses
20
+ return response.json()
21
+
22
+ @app.route('/api/search')
23
+ def perform_search():
24
+ query = request.args.get('q')
25
+ timelimit = request.args.get('timelimit', 'none')
26
+ safesearch = request.args.get('safesearch', 'off')
27
+
28
+ api_endpoint = f"{BASE_URL}/api/search?q={query}&max_results=100&timelimit={timelimit}&safesearch={safesearch}"
29
+ response = requests.get(api_endpoint)
30
+ response.raise_for_status() # Raise an error for bad responses
31
+ return response.json()
32
+
33
+ @app.route('/api/answers')
34
+ def get_people_also_search():
35
+ query = request.args.get('q')
36
+ api_endpoint = f"{BASE_URL}/api/answers?q={query}"
37
+ response = requests.get(api_endpoint)
38
+ response.raise_for_status()
39
+ return response.json()
40
+
41
+ if __name__ == "__main__":
42
+ start('index.html', mode='chrome', port=8080)