Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -62,29 +62,28 @@ class Reviewer:
|
|
62 |
return result, response.usage.total_tokens
|
63 |
|
64 |
def extract_chapter(self, pdf_path):
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
break
|
88 |
return extracted_text
|
89 |
|
90 |
def main(api, review_format, paper_pdf, language):
|
|
|
62 |
return result, response.usage.total_tokens
|
63 |
|
64 |
def extract_chapter(self, pdf_path):
|
65 |
+
# 创建一个PDF阅读器对象
|
66 |
+
pdf_reader = PyPDF2.PdfReader(pdf_path)
|
67 |
+
# 获取PDF的总页数
|
68 |
+
num_pages = len(pdf_reader.pages)
|
69 |
+
# 初始化提取状态和提取文本
|
70 |
+
extraction_started = False
|
71 |
+
extracted_text = ""
|
72 |
+
# 遍历PDF中的每一页
|
73 |
+
for page_number in range(num_pages):
|
74 |
+
page = pdf_reader.pages[page_number]
|
75 |
+
page_text = page.extract_text()
|
76 |
+
|
77 |
+
# 如果找到了章节标题,开始提取
|
78 |
+
if 'Abstract'.lower() in page_text.lower() and not extraction_started:
|
79 |
+
extraction_started = True
|
80 |
+
page_number_start = page_number
|
81 |
+
# 如果提取已开始,将页面文本添加到提取文本中
|
82 |
+
if extraction_started:
|
83 |
+
extracted_text += page_text
|
84 |
+
# 如果找到下一章节标题,停止提取
|
85 |
+
if page_number_start + 1 < page_number:
|
86 |
+
break
|
|
|
87 |
return extracted_text
|
88 |
|
89 |
def main(api, review_format, paper_pdf, language):
|