import os import json from flask import Flask, render_template, request, jsonify from PIL import Image app = Flask(__name__) app.config['JSON_AS_ASCII'] = False # 确保JSON响应中的中文字符正确显示 # 添加全局变量来存储当前界面 current_page = "主页" # 确保templates和static文件夹存在 templates_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'templates') static_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'static') if not os.path.exists(templates_dir): os.makedirs(templates_dir) if not os.path.exists(static_dir): os.makedirs(static_dir) # 图片路径 image_paths = { "主页": "E:/文件/LLM_model/RAG/图片/D3/主页.PNG", "工程信息": "E:/文件/LLM_model/RAG/图片/D3/工程信息.PNG", "取费设置": "E:/文件/LLM_model/RAG/图片/D3/取费设置.PNG", "组合件": "E:/文件/LLM_model/RAG/图片/D3/组合件.PNG", "工程量": "E:/文件/LLM_model/RAG/图片/D3/工程量.PNG", "材机分析": "E:/文件/LLM_model/RAG/图片/D3/材机分析.PNG", "工程费用": "E:/文件/LLM_model/RAG/图片/D3/工程费用.PNG", "报表输出": "E:/文件/LLM_model/RAG/图片/D3/报表输出.PNG" } # 创建HTML模板 with open(os.path.join(templates_dir, 'index.html'), 'w', encoding='utf-8') as f: f.write('''
software_name: {response['software_name']}
engineering_type: {response['engineering_type']}
software_version: {response['software_version']}
project_name: {response['project_name']}
current_page: {response['current_page']}
原始JSON:
{json.dumps(response, ensure_ascii=False, indent=2)}
'''
return html
# API调用返回JSON
return json.dumps(response, ensure_ascii=False)
# 添加清空JSON的路由
@app.route('/clear_json')
def clear_json():
global current_page
# 重置当前页面
current_page = ""
# 返回空JSON,添加编码设置
resp = jsonify({})
resp.headers['Content-Type'] = 'application/json; charset=utf-8'
return resp
if __name__ == "__main__":
app.run(host='0.0.0.0', port=1234, debug=True)