From 10a5680c3ee6f5c5c0c57cd73657b77de57d5878 Mon Sep 17 00:00:00 2001 From: "majiahui@haimaqingfan.com" Date: Thu, 9 May 2024 15:09:10 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=88=90=E5=B9=B6=E8=A1=8C?= =?UTF-8?q?=E8=AF=B7=E6=B1=82=E5=A4=A7=E6=A8=A1=E5=9E=8B=EF=BC=8C=E6=95=88?= =?UTF-8?q?=E7=8E=87=E5=A4=A7=E5=B9=85=E5=BA=A6=E6=8F=90=E9=AB=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ppt_api.py | 76 ++++++++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 57 insertions(+), 19 deletions(-) diff --git a/ppt_api.py b/ppt_api.py index 7fd23f8..1cab7e1 100644 --- a/ppt_api.py +++ b/ppt_api.py @@ -1,6 +1,7 @@ from docx import Document +import platform import os - +import concurrent.futures os.environ['ALL_PROXY'] = 'http://127.0.0.1:10809' import docx import json @@ -126,7 +127,6 @@ def getText(fileName): def request_selfmodel_api(prompt): - print(prompt) url = "http://192.168.31.149:12004/predict" data = { "model": "gpt-4-turbo-preview", @@ -197,9 +197,15 @@ def yanzhengyijibiaoti(mulu, res): return return_bool, dabiaoti_res_list -def main(fileName): +def main(path): # fileName = "data/基于Python的电影网站设计_范文.docx" - text_1 = json.dumps(read_word(fileName), ensure_ascii=False) + system = platform.system() + if system == 'Linux': + file_name = path.split("/")[-1].split(".")[0] + else: + file_name = path.split("\\")[-1].split(".")[0] + + text_1 = json.dumps(read_word(path), ensure_ascii=False) print(text_1) mulu_str = re.findall(pantten_mulu, text_1)[0] print(mulu_str) @@ -213,7 +219,6 @@ def main(fileName): mulu_list.append("致谢") print(mulu_list) - content_list = [] yijibiaoti = "" paper_content = {} @@ -261,6 +266,9 @@ def main(fileName): if shaixuan_bool == True: break + + index_zahnweifu = 0 + zhanweifu = [] content_1 = [] catalogue = [] for yijibiaoti in dabiaoti_res_list: @@ -270,27 +278,58 @@ def main(fileName): for erjibiaoti in paper_content[yijibiaoti]: num = random.randint(2, 6) content = paper_content[yijibiaoti][erjibiaoti] - res = request_selfmodel_api( - f'任务:生成段落主要内容\n请对以下内容进行提取信息,只需要提取{str(num)}条主要内容,使用条数罗列下面这段话的主要信息,例如1. xxx\n2.xxx \n' + content)[ - 'choices'][0]['message']['content'] - tiaoshu_list = str(res).split("\n") - - tiaoshu_list_new = [] - for dantiao in tiaoshu_list: - tiaoshu_list_new.append(re.findall(pantten_content_tiaoshu, dantiao)[0].strip()) + # res = request_selfmodel_api( + # f'任务:生成段落主要内容\n请对以下内容进行提取信息,只需要提取{str(num)}条主要内容,使用条数罗列下面这段话的主要信息,例如1. xxx\n2.xxx \n' + content)[ + # 'choices'][0]['message']['content'] + + zhanweifu.append(f'任务:生成段落主要内容\n请对以下内容进行提取信息,只需要提取{str(num)}条主要内容,使用条数罗列下面这段话的主要信息,例如1. xxx\n2.xxx \n' + content) + content_2.append({ "title_small": re.findall(pantten_erjibiaoti_content, erjibiaoti)[0], - "content_3": tiaoshu_list_new + "content_3": index_zahnweifu }) + index_zahnweifu += 1 content_1.append({ "title_big": yijibiaoti_content, "content_2": content_2 }) + with concurrent.futures.ThreadPoolExecutor(100) as executor: + results = executor.map(request_selfmodel_api, zhanweifu) + + zhanweifu = [] + for result in results: + res = result['choices'][0]['message']['content'] + + tiaoshu_list = str(res).split("\n") + + tiaoshu_list_new = [] + for dantiao in tiaoshu_list: + tiaoshu_list_new.append(re.findall(pantten_content_tiaoshu, dantiao)[0].strip()) + zhanweifu.append(tiaoshu_list_new) + + content_1_new = [] + + for yijibiaoti_content in content_1: + content_2_new = [] + title_big = yijibiaoti_content["title_big"] + for erjibiaoti_content in yijibiaoti_content["content_2"]: + title_small = erjibiaoti_content["title_small"] + content_3 = zhanweifu[erjibiaoti_content["content_3"]] + content_2_new.append({ + "title_small": title_small, + "content_3": content_3 + }) + content_1_new.append({ + "title_big": title_big, + "content_2": content_2_new + }) + + data_new = { - "title": fileName, + "title": file_name, "catalogue": catalogue, - "content_1": content_1 + "content_1": content_1_new } # with open("data/ceshi.json", "w", encoding="utf-8") as f: @@ -307,11 +346,10 @@ def upload_file(): file = request.files.get('file') if file and allowed_file(file.filename): - filename = secure_filename(file.filename) - path = os.path.join(app.config['UPLOAD_FOLDER'], filename) + path = os.path.join(app.config['UPLOAD_FOLDER'], file.filename) print(path) file.save(path) - + # file.save(file.filename) result = main(path) return_text = {"texts": result, "probabilities": None, "status_code": 200}