-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
48 lines (40 loc) · 1.32 KB
/
main.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
from flask import Flask, render_template, request
import requests
import json
import markdown
app = Flask(__name__)
@app.route('/guide')
def guide():
return render_template('guide.html')
@app.route('/', methods=['GET', 'POST'])
def home():
response = ''
hide_loader = True
if request.method == 'POST':
hide_loader = False
url = 'http://panel.magicgames.mooo.com:1037/api'
api_key = request.form.get('api_key')
question = request.form.get('question')
model = request.form.get('model')
product = request.form.get('product')
internet = request.form.get('internet')
data = {
'api_key': api_key,
'model': model,
'question': question,
}
if model == 'amazon':
data['product'] = product
elif model == 'chat':
data['internet'] = internet
api_response = requests.post(url, json=data).json()
if 'error' in api_response:
response = api_response['error']
else:
response = api_response['answer']
response = markdown.markdown(response)
print(response)
hide_loader = True
return render_template('home.html', response=response, hide_loader=hide_loader)
if __name__ == '__main__':
app.run(host='0.0.0.0', debug=False)