-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
60 lines (41 loc) · 1.5 KB
/
app.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
57
58
59
import importlib
import logging
from flask import Flask, render_template
from flask_socketio import SocketIO, emit
from chat import SparkApi
from ocr.routes import ocr_bp
from translate.translation import translate_bp # 导入新的蓝图
from ppt.routes import ppt_bp
from chat.routes import chat_bp, appid, api_key, api_secret, Spark_url, domain
from manage import manage_bp
logging.getLogger('werkzeug').disabled = True
app = Flask(__name__)
app.config['SECRET_KEY'] = 'your_secret_key'
socketio = SocketIO(app)
app.register_blueprint(ocr_bp, url_prefix='/ocr')
app.register_blueprint(translate_bp, url_prefix='/tra') # 注册新的蓝图
app.register_blueprint(ppt_bp, url_prefix='/ppt')
app.register_blueprint(manage_bp, url_prefix='/manage')
app.register_blueprint(chat_bp, url_prefix='/chat')
@app.route('/')
def index():
return render_template('tool-main.html')
@app.route('/tool')
def tool():
return render_template('Tools.html')
@app.route('/tool-main')
def toolmain():
return render_template('tool-main.html')
@socketio.on('message')
def handle_message(data):
question = data['question']
SparkApi.answer = ""
text = [{"role": "user", "content": question}]
def process_response(content, is_complete=False):
if is_complete:
emit('complete')
else:
emit('response', {'content': content})
SparkApi.main(appid, api_key, api_secret, Spark_url, domain, text, process_response)
if __name__ == '__main__':
socketio.run(app, debug=True)