|
@ -118,6 +118,9 @@ def read_word(word_path): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def getText(fileName): |
|
|
def getText(fileName): |
|
|
|
|
|
''' |
|
|
|
|
|
|
|
|
|
|
|
''' |
|
|
doc = docx.Document(fileName) |
|
|
doc = docx.Document(fileName) |
|
|
TextList = [] |
|
|
TextList = [] |
|
|
for paragraph in doc.paragraphs: |
|
|
for paragraph in doc.paragraphs: |
|
@ -146,6 +149,9 @@ def request_selfmodel_api(prompt): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def request_chatgpt_api(prompt): |
|
|
def request_chatgpt_api(prompt): |
|
|
|
|
|
''' |
|
|
|
|
|
|
|
|
|
|
|
''' |
|
|
OPENAI_API_KEY = "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" |
|
|
OPENAI_API_KEY = "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" |
|
|
url = "https://api.openai.com/v1/chat/completions" |
|
|
url = "https://api.openai.com/v1/chat/completions" |
|
|
# url = "https://one.aiskt.com" |
|
|
# url = "https://one.aiskt.com" |
|
@ -197,8 +203,33 @@ def yanzhengyijibiaoti(mulu, res): |
|
|
return return_bool, dabiaoti_res_list |
|
|
return return_bool, dabiaoti_res_list |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_document_structure(file_path): |
|
|
|
|
|
doc = docx.Document(file_path) |
|
|
|
|
|
structure = [] |
|
|
|
|
|
for paragraph in doc.paragraphs: |
|
|
|
|
|
style = paragraph.style |
|
|
|
|
|
if style.name.startswith("Heading"): |
|
|
|
|
|
level = int(style.name[7:]) |
|
|
|
|
|
text = paragraph.text |
|
|
|
|
|
structure.append((level, text)) |
|
|
|
|
|
return structure |
|
|
|
|
|
|
|
|
|
|
|
def print_document_structure(structure): |
|
|
|
|
|
for level, text in structure: |
|
|
|
|
|
print(f"{' ' * (level - 1)}- {text}") |
|
|
|
|
|
|
|
|
|
|
|
def catalogue_extract(structure): |
|
|
|
|
|
|
|
|
|
|
|
catalogue_list = [] |
|
|
|
|
|
for level, text in structure[:-1]: |
|
|
|
|
|
catalogue_list.append(str(text).strip(" ").strip("\n")) |
|
|
|
|
|
catalogue_str = "\n".join(catalogue_list) |
|
|
|
|
|
return catalogue_list, catalogue_str |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main(path): |
|
|
def main(path): |
|
|
# fileName = "data/基于Python的电影网站设计_范文.docx" |
|
|
|
|
|
|
|
|
# 判断系统 |
|
|
system = platform.system() |
|
|
system = platform.system() |
|
|
if system == 'Linux': |
|
|
if system == 'Linux': |
|
|
file_name = path.split("/")[-1].split(".")[0] |
|
|
file_name = path.split("/")[-1].split(".")[0] |
|
@ -207,24 +238,34 @@ def main(path): |
|
|
|
|
|
|
|
|
text_1 = json.dumps(read_word(path), ensure_ascii=False) |
|
|
text_1 = json.dumps(read_word(path), ensure_ascii=False) |
|
|
print(text_1) |
|
|
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("致谢") |
|
|
# mulu_str = re.findall(pantten_mulu, text_1)[0] |
|
|
|
|
|
# print(mulu_str) |
|
|
print(mulu_list) |
|
|
# 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) |
|
|
|
|
|
|
|
|
|
|
|
document_structure = get_document_structure(path) |
|
|
|
|
|
mulu_list, catalogue_str = catalogue_extract(document_structure) |
|
|
|
|
|
|
|
|
|
|
|
text = text_1.split("目录")[-1].strip("\\n") |
|
|
|
|
|
|
|
|
yijibiaoti = "" |
|
|
yijibiaoti = "" |
|
|
paper_content = {} |
|
|
paper_content = {} |
|
|
for i in range(len(mulu_list) - 1): |
|
|
for i in range(len(mulu_list) - 1): |
|
|
title = mulu_list[i].strip(" ").strip("\\n") |
|
|
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( |
|
|
print(mulu_list[i]) |
|
|
|
|
|
print(mulu_list[i + 1]) |
|
|
|
|
|
print(re.findall(pantten_xiaobiaoti.format(mulu_list[i], mulu_list[i + 1]), text)) |
|
|
|
|
|
content = str(re.findall(pantten_xiaobiaoti.format(mulu_list[i], mulu_list[i + 1]), text)[0]).strip( |
|
|
" ").strip("\\n") |
|
|
" ").strip("\\n") |
|
|
# print(title) |
|
|
# print(title) |
|
|
# print(content) |
|
|
# print(content) |
|
@ -247,20 +288,20 @@ def main(path): |
|
|
mulu_str = "\n".join(mulu_list[:-1]) |
|
|
mulu_str = "\n".join(mulu_list[:-1]) |
|
|
prompt = f'请问把以下目录缩减成只有4个一级标题作为ppt的题目,请问留下原始目录中的哪4个一级标题最合适,一级标题必须在原始目录中\n{mulu_str}\n' |
|
|
prompt = f'请问把以下目录缩减成只有4个一级标题作为ppt的题目,请问留下原始目录中的哪4个一级标题最合适,一级标题必须在原始目录中\n{mulu_str}\n' |
|
|
|
|
|
|
|
|
# try: |
|
|
try: |
|
|
# res = request_chatgpt_api(prompt)['choices'][0]['message']['content'] |
|
|
res = request_chatgpt_api(prompt)['choices'][0]['message']['content'] |
|
|
# except: |
|
|
except: |
|
|
# continue |
|
|
continue |
|
|
|
|
|
|
|
|
res = '''根据您提供的目录内容,如果要将其缩减为只包含4个一级标题的PPT题目,建议选择以下四个一级标题,因为它们分别代表了研究的引入、理论框架、实际应用与实践,以及未来展望,从而形成了一个完整的研究过程和内容框架: |
|
|
|
|
|
|
|
|
|
|
|
1. 一、绪论 |
|
|
|
|
|
2. 二、电影网站设计的基本概念 |
|
|
|
|
|
3. 三、Python在电影网站设计中的应用 |
|
|
|
|
|
4. 五、电影网站设计的实践与展望 |
|
|
|
|
|
|
|
|
|
|
|
这样的选择既涵盖了研究的背景、目的与意义(绪论),也包括了研究的理论基础(电影网站设计的基本概念),以及研究的实际操作和技术实现(Python在电影网站设计中的应用),最后还有对项目实践经验的总结和对未来发展的展望(电影网站设计的实践与展望)。这四个部分共同构成了一个完整的研究报告或项目介绍的框架,能够全面展示电影网站设计项目的各个方面。 |
|
|
# res = '''根据您提供的目录内容,如果要将其缩减为只包含4个一级标题的PPT题目,建议选择以下四个一级标题,因为它们分别代表了研究的引入、理论框架、实际应用与实践,以及未来展望,从而形成了一个完整的研究过程和内容框架: |
|
|
''' |
|
|
# |
|
|
|
|
|
# 1. 一、绪论 |
|
|
|
|
|
# 2. 二、电影网站设计的基本概念 |
|
|
|
|
|
# 3. 三、Python在电影网站设计中的应用 |
|
|
|
|
|
# 4. 五、电影网站设计的实践与展望 |
|
|
|
|
|
# |
|
|
|
|
|
# 这样的选择既涵盖了研究的背景、目的与意义(绪论),也包括了研究的理论基础(电影网站设计的基本概念),以及研究的实际操作和技术实现(Python在电影网站设计中的应用),最后还有对项目实践经验的总结和对未来发展的展望(电影网站设计的实践与展望)。这四个部分共同构成了一个完整的研究报告或项目介绍的框架,能够全面展示电影网站设计项目的各个方面。 |
|
|
|
|
|
# ''' |
|
|
|
|
|
|
|
|
shaixuan_bool, dabiaoti_res_list = yanzhengyijibiaoti("\n".join(mulu_list), res.replace("\n", "\\n")) |
|
|
shaixuan_bool, dabiaoti_res_list = yanzhengyijibiaoti("\n".join(mulu_list), res.replace("\n", "\\n")) |
|
|
if shaixuan_bool == True: |
|
|
if shaixuan_bool == True: |
|
|