forked from baichuan-inc/Baichuan2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
QA_achieve.py
53 lines (40 loc) · 1.4 KB
/
QA_achieve.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from docx import Document
import requests
import json
import pandas as pd
import re
def clean_text(text):
return text.strip().replace('\n', ' ')
#切分文档,当前为按照word标题切分
def split_document_by_headings(doc_path):
doc = Document(doc_path)
sections = []
current_section = []
for paragraph in doc.paragraphs:
if paragraph.style.name.startswith('Heading'):
if current_section:
sections.append("\n".join(current_section))
current_section = []
print(paragraph.text)
current_section.append(clean_text(paragraph.text))
else:
current_section.append(clean_text(paragraph.text))
# Add the last section
if current_section:
sections.append("".join(current_section))
return sections
url = "http://127.0.0.1:5000/generate"
sections = split_document_by_headings("zhufeiyu/baichuan/Baichuan2/test.docx")
# 调用函数并打印文档内容
excel_question = f""
data = {"input": excel_question}
# print("请求数据:", data)
# 发送请求
session = requests.Session()
response = session.post(url, json=data, headers={"Content-Type": "application/json", "Cache-Control": "no-cache"})
# 检查响应状态码
if response.status_code == 200:
# 解析响应内容
result = response.json()
response_string = result['response']
print(response_string)