Browse Source

定义基本结构

root 6 months ago
parent
commit
3bdaf2b9d0

+ 11 - 13
app.py

@@ -94,7 +94,7 @@ model = AutoModel(model="E:\\yuyin_model\\Voice_translation", model_revision="v2
 # inference_pipeline = pipeline(
 #     task=Tasks.auto_speech_recognition,
 #     # model='iic/speech_paraformer-large-vad-punc_asr_nat-zh-cn-16k-common-vocab8404-pytorch',
-#     model='C:\\Users\\siwei\\.cache\\modelscope\\hub\\iic\\speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-pytorch', 
+#     model='C:\\Users\\siwei\\.cache\\modelscope\\hub\\iic\\speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-pytorch',
 #     # model="model\punc_ct-transformer_cn-en-common-vocab471067-large",
 #     model_revision="v2.0.4",
 #     device='gpu')
@@ -113,7 +113,7 @@ def route_embed():
 
     if file.filename == '':
         return jsonify({"error": "No selected file"}), 400
-    
+
     embedded = embed(file)
     end_time = time.time()
     print("Time taken for embedding: ", end_time - start_time)
@@ -122,7 +122,7 @@ def route_embed():
         return jsonify({"message": "File embedded successfully"}), 200
 
     return jsonify({"error": "File embedded unsuccessfully"}), 400
-    
+
 
 
 def route_query(msg):
@@ -151,9 +151,7 @@ def home():
 # 后台接口
 
 
-@app.route("/hello")
-def hello():
-    return "Hello, World!"
+
 
 
 #定义需要替换的词
@@ -192,8 +190,8 @@ def upload_file():
     file.save(file_path)
 
     #语音转文字模型1
-    res = model.generate(file_path, 
-                batch_size_s=30, 
+    res = model.generate(file_path,
+                batch_size_s=30,
                 hotword='test')
     texts = [item['text'] for item in res]
     msg = ' '.join(texts)
@@ -213,7 +211,7 @@ def upload_file():
     for word in words_to_replace:
         msg = msg.replace(word, "抱坡")
     print(msg)
-    
+
 
     return jsonify({"msg": "上传成功",
                     "code": 200,
@@ -270,7 +268,7 @@ factors是因子选择
         },
     ]
 }
-json中"condition"的值为"gt"、"lt"、"get"、"let"、"between","not_intersect"、"intersect"、"not_contain"、"contain"、"between"  
+json中"condition"的值为"gt"、"lt"、"get"、"let"、"between","not_intersect"、"intersect"、"not_contain"、"contain"、"between"
 """
 sys_question = """请扮演问答工具,对用户输入信息进行回答,请严格以markdown格式输出并保障寄送格式正确无误"""
 # 智能选址
@@ -372,7 +370,7 @@ def inputMsg():
                 # if landType != "未找到相关数据" and landType != "" and districtName  != "未找到相关数据"and districtName != "":
                 if landType in land and districtName in addtress:
                     json_res = jsonResToDict(json_res)
-                    # print(json_res)  
+                    # print(json_res)
                 else:
                     json_res = "未找到相关数据"
                     json_res = jsonResToDict_wrong(json_res)
@@ -390,7 +388,7 @@ def inputMsg():
         json_res = update_chat_history_simple(msg)
         json_res = jsonResToDict_questions(json_res)
         print(json_res)  # 打印生成的回复
-    
+
     # 返回响应
     return jsonify(json_res)
 
@@ -493,7 +491,7 @@ def jsonResToDict(json_res):
     for factor_id, factor_info in input_factors.items():
         if factor_id not in added_factor_ids:
             res["yxyz"].append(factor_info)
-        
+
     resObj = {}
     resObj["data"] = res
     resObj["code"] = 200

+ 10 - 0
app/__init__.py

@@ -0,0 +1,10 @@
+from flask import Flask
+from .routes import main_bp
+
+
+def create_app():
+    app = Flask(__name__)
+
+    # 注册蓝图, 使得蓝图中的路由生效
+    app.register_blueprint(main_bp)
+    return app

BIN
app/__pycache__/__init__.cpython-310.pyc


BIN
app/__pycache__/routes.cpython-310.pyc


+ 13 - 0
app/routes.py

@@ -0,0 +1,13 @@
+# routes.py
+from flask import Blueprint, render_template
+# from app.services.example_service import get_user_data  # 导入 service 中的函数
+
+main_bp = Blueprint('main', __name__)
+
+@main_bp.route('/')
+def index():
+    return render_template('index.html')
+
+@main_bp.route("/hello")
+def hello():
+    return "Hello, World!"

+ 1 - 0
app/services/__init__.py

@@ -0,0 +1 @@
+# 空文件,标识 services 是一个 Python 包

+ 0 - 0
templates/index.html → app/templates/index.html


+ 9 - 0
run.py

@@ -0,0 +1,9 @@
+from app import create_app
+
+app = create_app()
+
+if __name__ == '__main__':
+    app.run(
+        host='0.0.0.0',
+        port=4000
+    )