From 87a2bd987ea1efff6bc7fd4b0411a9ffd996f284 Mon Sep 17 00:00:00 2001 From: "majiahui@haimaqingfan.com" Date: Thu, 9 May 2024 11:07:40 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A6=96=E6=AC=A1=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ceshi.html | 10 ++ data/ceshi.json | 135 +++++++++++++++++++++++ ppt_api.py | 327 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 472 insertions(+) create mode 100644 ceshi.html create mode 100644 data/ceshi.json create mode 100644 ppt_api.py diff --git a/ceshi.html b/ceshi.html new file mode 100644 index 0000000..af72134 --- /dev/null +++ b/ceshi.html @@ -0,0 +1,10 @@ + + + + + Title + + +\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n
功能描述实现方式
电影资料库存储电影的详细信息数据库设计
搜索引擎帮助用户快速找到想看的电影关键字匹配算法
用户注册与管理管理用户账号和权限会员管理系统
评论与社区交流提供用户发表评论和交流的平台论坛功能集成
票务预订与支付在线购票和支付功能接口集成第三方支付
视频播放服务提供电影在线观看流媒体传输技术
\\n\\n + + \ No newline at end of file diff --git a/data/ceshi.json b/data/ceshi.json new file mode 100644 index 0000000..070387b --- /dev/null +++ b/data/ceshi.json @@ -0,0 +1,135 @@ +{ + "title": "uploads\\Python_.docx", + "catalogue": [ + "一、 绪论", + "二、 电影网站设计的基本概念", + "三、 Python在电影网站设计中的应用", + "五、 电影网站设计的实践与展望" + ], + "content_1": [ + { + "title_big": "一、 绪论", + "content_2": [ + { + "title_small": "1.1 研究背景", + "content_3": [ + "数字媒体内容消费,尤其是电影在线观看、评论和分享的需求,推动了电影网站的发展。", + "Python语言因其简洁语法、强大库支持和丰富框架,在电影网站设计中占据重要地位,并面临用户体验优化、数据安全与隐私保护以及内容版权管理等挑战。", + "研究旨在通过深入探讨Python在电影网站设计中的应用,提供高效、安全、用户友好的解决方案,为电影行业的数字化转型贡献力量。" + ] + }, + { + "title_small": "1.2 研究目的", + "content_3": [ + "本研究旨在通过分析和实践,探讨Python在电影网站开发中的优势及应用方式。", + "研究将评估Python在处理电影数据、开发动态网页、实现用户交互等方面的实际应用情况。", + "研究旨在提出一套完整的电影网站设计方案,并总结电影网站设计与开发的实践经验。" + ] + }, + { + "title_small": "1.3 研究意义", + "content_3": [ + "本研究聚焦于使用Python在电影网站设计中的应用,以提升开发效率和降低项目风险。", + "探讨了电影网站设计不仅是技术问题,也涉及内容与形式的艺术创作,旨在吸引用户并提供良好的用户体验。", + "研究包括对电影网站的基本概念、特点及功能的系统梳理,并将探讨电影网站设计的技术实现,如数据库设计、前端界面设计及后台逻辑处理等。", + "展望了电影网站设计的未来发展趋势,包括利用新兴技术如人工智能、大数据分析来优化设计,并预测可能出现的新型电影网站模式。" + ] + } + ] + }, + { + "title_big": "二、 电影网站设计的基本概念", + "content_2": [ + { + "title_small": "2.1 电影网站的定义", + "content_3": [ + "电影网站通过互联网提供电影信息、观影服务和用户交流等功能。", + "核心功能包括电影资料库、搜索引擎、用户注册与管理、评论与社区交流、票务预订与支付、视频播放服务等。", + "利用HTML5和CSS3技术优化用户体验,采用Python语言开发后台逻辑提高效率,并运用人工智能技术如推荐算法增强用户粘性。" + ] + }, + { + "title_small": "2.2 电影网站的特点", + "content_3": [ + "电影网站提供内容丰富性,包括电影简介、评分、评论和演员阵容等。", + "电影网站支持用户交互性,如注册、评论、打分和分享功能。", + "电影网站运用技术应用性,例如云计算、大数据分析和人工智能推荐系统来提升用户体验。" + ] + }, + { + "title_small": "2.3 电影网站的功能", + "content_3": [ + "电影网站的设计功能对用户体验和使用效率有直接影响。", + "常见的电影网站核心功能包括搜索、分类浏览、详细信息查看、在线观看、评论区、用户注册与登录以及推荐系统。", + "搜索功能允许用户通过关键字查找电影。", + "分类浏览按照电影类型、年份等进行分类展示。", + "详细信息查看提供电影的剧情简介、演员阵容、评分等信息。", + "在线观看支持用户在线观看电影,而推荐系统根据用户历史行为和偏好推荐电影。" + ] + } + ] + }, + { + "title_big": "三、 Python在电影网站设计中的应用", + "content_2": [ + { + "title_small": "3.1 Python的优势", + "content_3": [ + "Python以其简洁易读的语法著称,提高了开发效率。", + "Python拥有丰富的库支持,特别是Flask或Django框架和Pandas、NumPy库,适合电影网站的开发和数据分析。", + "Python是跨平台的编程语言,能在不同操作系统上运行,便于电影网站的部署。", + "Python具备高效的数据处理能力,尤其适用于大量电影数据的存储、检索和分析。", + "Python的动态类型系统为开发人员提供灵活性,有助于快速迭代和修改代码。", + "Python有一个庞大而活跃的开发者社区,提供教程、文档和论坛等资源,帮助解决技术难题。" + ] + }, + { + "title_small": "3.2 Python在网站开发中的应用", + "content_3": [ + "Python在网站开发中的应用非常广泛,尤其是在数据处理和后端逻辑处理方面表现突出。", + "Python通过其强大的库支持和简洁明了的语法,以及异步编程特性,提高了网站开发的效率和响应速度。" + ] + }, + { + "title_small": "3.3 Python在电影网站设计中的具体应用", + "content_3": [ + "Python提供了强大的库,如NumPy和Pandas,用于数据处理和分析。", + "Python的Flask和Django框架以及SQLAlchemy工具简化了后端开发和数据库管理。" + ] + } + ] + }, + { + "title_big": "五、 电影网站设计的实践与展望", + "content_2": [ + { + "title_small": "5.1 实践经验总结", + "content_3": [ + "Python框架选择:Django和Flask都广泛应用,但Django因其全面的功能更适合大型项目。", + "数据库设计:合理的数据库设计对于网站性能至关重要,MySQL和PostgreSQL是两种常用的选择。", + "安全性考虑:防止SQL注入、XSS攻击和CSRF攻击是保障网站安全的关键措施。" + ] + }, + { + "title_small": "5.2 存在问题与改进方向", + "content_3": [ + "内容更新速度慢:电影网站无法及时更新最新电影信息,需要优化后台数据处理流程和加强与电影发行方合作。", + "安全性问题突出:面临数据泄露、恶意软件侵入等风险,需加强网站的安全防护措施。", + "移动端适配不足:智能手机普及但部分网站未能良好适配移动端,需优化响应式网页设计。" + ] + }, + { + "title_small": "5.3 未来发展趋势", + "content_3": [ + "人工智能与机器学习的深度融合,实现个性化内容推荐和界面布局。", + "增强现实(AR)和虚拟现实(VR)技术应用,提供沉浸式观影体验。", + "云计算和边缘计算的广泛使用,提高资源分配效率和数据处理速度。", + "区块链技术探索,建立透明、安全的版权保护机制。", + "跨平台整合发展,实现手机APP、桌面网站及智能电视应用的无缝连接。", + "社交功能加强,促进用户互动,增加用户粘性和网站活跃度。" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/ppt_api.py b/ppt_api.py new file mode 100644 index 0000000..7fd23f8 --- /dev/null +++ b/ppt_api.py @@ -0,0 +1,327 @@ +from docx import Document +import os + +os.environ['ALL_PROXY'] = 'http://127.0.0.1:10809' +import docx +import json +import re +from docx.document import Document +from docx.oxml.table import CT_Tbl +from docx.oxml.text.paragraph import CT_P +from docx.table import _Cell, Table +from docx.text.paragraph import Paragraph +import requests +import random +import time +from flask import Flask, render_template, request, redirect, url_for, jsonify +from werkzeug.utils import secure_filename +app = Flask(__name__) + + +# 上传文件存储目录 +UPLOAD_FOLDER = 'uploads' +app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER + +# 正则表达式 +RE_CHINA_NUMS = "[1-9].(.*)" +# 允许的文件类型 +ALLOWED_EXTENSIONS = {'docx'} + + +pantten_mulu = '目录(.*?)致谢' +pantten_xiaobiaoti = "{}(.*?){}" +pantten_yijibiaoti = '^([一二三四五六七八九])、(.*)' +pantten_erjibiaoti = '^[0-9](\.[0-9]\d*){1}\s{1,}?.*$' +pantten_content_tiaoshu = '[0-9]\.{1}\s{0,}?(.*)' + +pantten_yijibiaoti_content = '^[一二三四五六七八九]、(.*)' +pantten_erjibiaoti_content = '^[0-9]\.[0-9]\s{1,}?(.*)$' + +prompt_two_title_min_max = "为论文题目“{}”生成中文目录,要求只有一级标题,二级标题,一级标题使用中文数字 例如一、xxx;二级标题使用阿拉伯数字 例如1.1 xxx;一级标题生成{}个;每个一级标题包含{}-{}个二级标题" +prompt_two_title_not_min_max = "为论文题目“{}”生成中文目录,要求只有一级标题,二级标题,一级标题使用中文数字 例如一、xxx;二级标题使用阿拉伯数字 例如1.1 xxx;一级标题生成{}个;每个一级标题包含{}个二级标题" + +pantten_title = "为论文题目“(.*?)”生成中文目录" +pantten_xiaobiaoti_geshu = "每个一级标题包含(.*?)个" +pantten_dabiaoti_geshu = "一级标题生成(.*?)个" + +mulusuojian = "请问把以下目录缩减成只有4个一级标题作为ppt的题目,请问留下原始目录中的哪4个一级标题最合适,一级标题必须在原始目录中\n{}\n" + +self_api = "http://192.168.31.149:12004/predict" +gpt_api = "https://api.openai.com/v1/chat/completions" + + +class log: + def __init__(self): + pass + + def log(*args, **kwargs): + format = '%Y/%m/%d-%H:%M:%S' + format_h = '%Y-%m-%d' + value = time.localtime(int(time.time())) + dt = time.strftime(format, value) + dt_log_file = time.strftime(format_h, value) + log_file = 'log_file/access-%s' % dt_log_file + ".log" + if not os.path.exists(log_file): + with open(os.path.join(log_file), 'w', encoding='utf-8') as f: + print(dt, *args, file=f, **kwargs) + else: + with open(os.path.join(log_file), 'a+', encoding='utf-8') as f: + print(dt, *args, file=f, **kwargs) + + +def allowed_file(filename): + return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS + + +def iter_block_items(parent): + """ + Yield each paragraph and table child within *parent*, in document order. + Each returned value is an instance of either Table or Paragraph. *parent* + would most commonly be a reference to a main Document object, but + also works for a _Cell object, which itself can contain paragraphs and tables. + """ + if isinstance(parent, Document): + parent_elm = parent.element.body + elif isinstance(parent, _Cell): + parent_elm = parent._tc + else: + raise ValueError("something's not right") + + for child in parent_elm.iterchildren(): + if isinstance(child, CT_P): + yield Paragraph(child, parent) + elif isinstance(child, CT_Tbl): + yield Table(child, parent) + + +def read_table(table): + return [[cell.text for cell in row.cells] for row in table.rows] + + +def read_word(word_path): + paper_text = [] + doc = docx.Document(word_path) + for block in iter_block_items(doc): + if isinstance(block, Paragraph): + paper_text.append(block.text) + elif isinstance(block, Table): + table_list = read_table(block) + table_list_new = [] + for row in table_list: + table_list_new.append("" + "\n".join(row) + "") + table_str = "\n\n" + "\n\n\n".join(table_list_new) + "\n\n" + table_str = "\n" + table_str + "
\n\n" + paper_text.append(table_str) + paper_text = "\n".join(paper_text) + return paper_text + + +def getText(fileName): + doc = docx.Document(fileName) + TextList = [] + for paragraph in doc.paragraphs: + TextList.append(paragraph.text) + + return '\n'.join(TextList) + + +def request_selfmodel_api(prompt): + print(prompt) + url = "http://192.168.31.149:12004/predict" + data = { + "model": "gpt-4-turbo-preview", + "messages": [ + {"role": "user", "content": prompt} + ], + "top_p": 0.7, + "temperature": 0.95 + } + response = requests.post( + url, + json=data, + timeout=100000 + ) + + return response.json() + + +def request_chatgpt_api(prompt): + OPENAI_API_KEY = "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" + url = "https://api.openai.com/v1/chat/completions" + # url = "https://one.aiskt.com" + headers = { + "Content-Type": "application/json", + "Authorization": f"Bearer {OPENAI_API_KEY}" + } + data = { + "model": "gpt-4-turbo-preview", + "messages": [ + {"role": "user", "content": prompt} + ], + "top_p": 0.7, + "temperature": 0.95 + } + response = requests.post(url, + headers=headers, + data=json.dumps(data), + timeout=1200) + + return response.json() + + +def yanzhengyijibiaoti(mulu, res): + ''' + 判断生成的大标题是否可用 + :param mulu: + :param res: + :return: + ''' + + mulu_list = str(mulu).split("\n") + + dabiaoti_list = [] + dabiaoti_res_list = [] + for i in mulu_list: + res_re = re.findall(pantten_yijibiaoti, i) + if res_re != []: + dabiaoti_list.append(re.findall(pantten_yijibiaoti, i)[0]) + for i in dabiaoti_list: + if i[1].strip() in res: + dabiaoti_res_list.append("、".join(i)) + + if len(dabiaoti_res_list) == 4: + return_bool = True + else: + return_bool = False + + return return_bool, dabiaoti_res_list + + +def main(fileName): + # fileName = "data/基于Python的电影网站设计_范文.docx" + text_1 = json.dumps(read_word(fileName), ensure_ascii=False) + print(text_1) + mulu_str = re.findall(pantten_mulu, text_1)[0] + print(mulu_str) + mulu_list_xuhao = str(mulu_str).split("\\n") + + mulu_list = [] + for i in mulu_list_xuhao: + if i != "": + mulu_list.append(i.split("\\t")[0]) + + mulu_list.append("致谢") + + print(mulu_list) + content_list = [] + + yijibiaoti = "" + paper_content = {} + for i in range(len(mulu_list) - 1): + title = mulu_list[i].strip(" ").strip("\\n") + content = str(re.findall(pantten_xiaobiaoti.format(mulu_list[i], mulu_list[i + 1]), text_1)[1]).strip( + " ").strip("\\n") + # print(title) + # print(content) + + yijibiaoti_res = re.findall(pantten_yijibiaoti, title) + erjibiaoti_res = re.findall(pantten_erjibiaoti, title) + if yijibiaoti_res != []: + # title = "、".join([yijibiaoti_res[0][1], yijibiaoti_res[0][1].strip()]) + paper_content[title] = {} + yijibiaoti = title + continue + + elif erjibiaoti_res != []: + paper_content[yijibiaoti][title] = content.replace("\\n", "\n") + + else: + paper_content[yijibiaoti][title] += "\n".join(title + content) + + while True: + mulu_str = "\n".join(mulu_list[:-1]) + prompt = f'请问把以下目录缩减成只有4个一级标题作为ppt的题目,请问留下原始目录中的哪4个一级标题最合适,一级标题必须在原始目录中\n{mulu_str}\n' + + # try: + # res = request_chatgpt_api(prompt)['choices'][0]['message']['content'] + # except: + # continue + + res = '''根据您提供的目录内容,如果要将其缩减为只包含4个一级标题的PPT题目,建议选择以下四个一级标题,因为它们分别代表了研究的引入、理论框架、实际应用与实践,以及未来展望,从而形成了一个完整的研究过程和内容框架: + + 1. 一、绪论 + 2. 二、电影网站设计的基本概念 + 3. 三、Python在电影网站设计中的应用 + 4. 五、电影网站设计的实践与展望 + + 这样的选择既涵盖了研究的背景、目的与意义(绪论),也包括了研究的理论基础(电影网站设计的基本概念),以及研究的实际操作和技术实现(Python在电影网站设计中的应用),最后还有对项目实践经验的总结和对未来发展的展望(电影网站设计的实践与展望)。这四个部分共同构成了一个完整的研究报告或项目介绍的框架,能够全面展示电影网站设计项目的各个方面。 + ''' + + shaixuan_bool, dabiaoti_res_list = yanzhengyijibiaoti("\n".join(mulu_list), res.replace("\n", "\\n")) + if shaixuan_bool == True: + break + + content_1 = [] + catalogue = [] + for yijibiaoti in dabiaoti_res_list: + content_2 = [] + yijibiaoti_content = re.findall(pantten_yijibiaoti_content, yijibiaoti)[0] + catalogue.append(yijibiaoti_content) + 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()) + content_2.append({ + "title_small": re.findall(pantten_erjibiaoti_content, erjibiaoti)[0], + "content_3": tiaoshu_list_new + }) + content_1.append({ + "title_big": yijibiaoti_content, + "content_2": content_2 + }) + + data_new = { + "title": fileName, + "catalogue": catalogue, + "content_1": content_1 + } + + # with open("data/ceshi.json", "w", encoding="utf-8") as f: + # f.write(json.dumps(data_new, ensure_ascii=False, indent=2)) + + return data_new + +@app.route('/predict', methods=['POST']) +def upload_file(): + + if 'file' not in request.files: + return "1" + + 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) + print(path) + file.save(path) + + + result = main(path) + return_text = {"texts": result, "probabilities": None, "status_code": 200} + + log.log('start at', + 'filename:{}, result:{}'.format( + path, return_text)) + return jsonify(return_text) + else: + return "不允许的文件类型" + +if __name__ == "__main__": + app.run(host="0.0.0.0", port=21000, threaded=True) \ No newline at end of file