-
Notifications
You must be signed in to change notification settings - Fork 0
/
flask_server.py
57 lines (49 loc) · 1.44 KB
/
flask_server.py
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import os
from flask import Flask, request, render_template_string
from flask_cors import CORS
import search
app = Flask(__name__)
CORS(app, resources={r"/*": {"origins": "*"}})
# HTML template
html_template = """
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Search Form</title>
</head>
<body>
<form action="/search" method="post">
<label for="query">Query:</label>
<input type="text" id="query" name="query"><br><br>
<input type="checkbox" id="custom_embedding" name="custom_embedding">
<label for="custom_embedding">Use custom embedding</label><br><br>
<button type="submit">Search</button>
</form>
</body>
</html>
"""
@app.route('/', methods=['GET'])
def index_handler():
return render_template_string(html_template)
@app.route('/search', methods=['POST'])
def search_handler():
# This function will handle the search request
# You can fill this function with your search logic
data = request.form
query = data.get('query')
use_embeddings = data.get('custom_embedding', None) is not None
answer = search.main(query, use_embeddings)
return f"""
Received query: {query}, use custom embedding: {use_embeddings}.
<br/>
<br/>
Answer:
{answer}
"""
if __name__ == '__main__':
app.run(
host=os.getenv('FLASK_HOST', '0.0.0.0'),
port=os.getenv("FLASK_PORT", 80)
)