Spaces:
Build error
Build error
Upload app.py
Browse files
app.py
CHANGED
@@ -412,18 +412,16 @@ class Reader:
|
|
412 |
chat_summary_text = self.chat_summary(text=text, key=str(key))
|
413 |
htmls.append(chat_summary_text)
|
414 |
|
415 |
-
#
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
#
|
426 |
-
|
427 |
# 第二步总结方法:
|
428 |
# TODO,由于有些文章的方法章节名是算法名,所以简单的通过关键词来筛选,很难获取,后面需要用其他的方案去优化。
|
429 |
method_key = ''
|
@@ -468,28 +466,8 @@ class Reader:
|
|
468 |
else:
|
469 |
text = summary_text
|
470 |
text = text[:max_token]
|
471 |
-
|
472 |
-
|
473 |
-
# htmls.append("\n")
|
474 |
-
experiment_text = ''
|
475 |
-
experiment_key = ''
|
476 |
-
review_text = "<summary>" + chat_summary_text + "\n <Method summary>:\n" + chat_method_text
|
477 |
-
for parse_key in paper.section_text_dict.keys():
|
478 |
-
if 'Experiments' in parse_key.lower() or 'Results' in parse_key.lower():
|
479 |
-
experiment_key = parse_key
|
480 |
-
break
|
481 |
-
if experiment_key != '':
|
482 |
-
# conclusion
|
483 |
-
experiment_text += paper.section_text_dict[experiment_key]
|
484 |
-
max_token = 2500 * 4
|
485 |
-
text = review_text + "\n <Experiments>:\n" + experiment_text
|
486 |
-
else:
|
487 |
-
text = review_text
|
488 |
-
text = text[:max_token]
|
489 |
-
|
490 |
-
|
491 |
-
chat_review_text = self.chat_review(text=text, key=str(key))
|
492 |
-
htmls.append(chat_review_text)
|
493 |
htmls.append("\n")
|
494 |
md_text = "\n".join(htmls)
|
495 |
|
@@ -601,58 +579,8 @@ class Reader:
|
|
601 |
for choice in response.choices:
|
602 |
result += choice.message.content
|
603 |
print("summary_result:\n", result)
|
604 |
-
return result
|
605 |
-
|
606 |
-
@tenacity.retry(wait=tenacity.wait_exponential(multiplier=1, min=4, max=10),
|
607 |
-
stop=tenacity.stop_after_attempt(5),
|
608 |
-
reraise=True)
|
609 |
-
def chat_review(self, text):
|
610 |
-
openai.api_key = self.chat_api_list[self.cur_api]
|
611 |
-
self.cur_api += 1
|
612 |
-
self.cur_api = 0 if self.cur_api >= len(self.chat_api_list) - 1 else self.cur_api
|
613 |
-
|
614 |
-
response = openai.ChatCompletion.create(
|
615 |
-
model="gpt-3.5-turbo",
|
616 |
-
messages=[
|
617 |
-
{"role": "system",
|
618 |
-
"content": "You are a researcher in the field of [" + self.key_word + "] who is good at reviewing papers using concise statements"},
|
619 |
-
# chatgpt 角色
|
620 |
-
{"role": "assistant",
|
621 |
-
"content": "This is the title, author, link, abstract, introduction, method, and experiments of an English document. I need your help to read and review the following questions: " + text},
|
622 |
-
# 背景知识
|
623 |
-
{"role": "user", "content": """
|
624 |
-
1. summarize according to the following four points.Be sure to use English answers (proper nouns need to be marked in English)
|
625 |
-
- (1):What is the research background of this article?
|
626 |
-
- (2):What are the past methods? What are the problems with them? Is the approach well motivated?
|
627 |
-
- (3):What is the research methodology proposed in this paper?
|
628 |
-
- (4):On what task and what performance is achieved by the methods in this paper? Can the performance support their goals?
|
629 |
-
Follow the format of the output that follows:
|
630 |
-
2. Strengths: \n\n
|
631 |
-
- (1):Background;\n
|
632 |
-
- (2):Main challenges and Motivations;\n
|
633 |
-
- (3):The detail of methods\n
|
634 |
-
- (4):Results.\n\n
|
635 |
-
3. Weakness: \n\n
|
636 |
-
- (1):Motivation;\n
|
637 |
-
- (2):Methods;\n
|
638 |
-
- (3):Novelty\n
|
639 |
-
- (4):Results.\n\n
|
640 |
-
4. Other questions: \n\n
|
641 |
-
- (1):\n
|
642 |
-
- (2):\n
|
643 |
-
- (3):\n
|
644 |
-
- (4):\n\n
|
645 |
-
Be sure to use English answers, statements as concise and academic as possible, do not have too much repetitive information, numerical values using the original numbers, be sure to strictly follow the format, the corresponding content output to xxx, in accordance with \n line feed.
|
646 |
-
"""},
|
647 |
-
]
|
648 |
-
)
|
649 |
-
result = ''
|
650 |
-
for choice in response.choices:
|
651 |
-
result += choice.message.content
|
652 |
-
print("review_result:\n", result)
|
653 |
-
return result
|
654 |
-
|
655 |
-
|
656 |
def export_to_markdown(self, text, file_name, mode='w'):
|
657 |
# 使用markdown模块的convert方法,将文本转换为html格式
|
658 |
# html = markdown.markdown(text)
|
@@ -683,13 +611,13 @@ def upload_pdf(key, text, file):
|
|
683 |
return sum_info
|
684 |
|
685 |
# 标题
|
686 |
-
title = "
|
687 |
# 描述
|
688 |
description = '''<div align='center'>
|
689 |
|
690 |
-
Use ChatGPT to summary
|
691 |
|
692 |
-
|
693 |
|
694 |
</div>
|
695 |
'''
|
|
|
412 |
chat_summary_text = self.chat_summary(text=text, key=str(key))
|
413 |
htmls.append(chat_summary_text)
|
414 |
|
415 |
+
# TODO 往md文档中插入论文里的像素最大的一张图片,这个方案可以弄的更加智能一些:
|
416 |
+
first_image, ext = paper.get_image_path()
|
417 |
+
if first_image is None or self.gitee_key == '':
|
418 |
+
pass
|
419 |
+
else:
|
420 |
+
image_title = self.validateTitle(paper.title)
|
421 |
+
image_url = self.upload_gitee(image_path=first_image, image_name=image_title, ext=ext)
|
422 |
+
htmls.append("\n")
|
423 |
+
htmls.append("![Fig]("+image_url+")")
|
424 |
+
htmls.append("\n")
|
|
|
|
|
425 |
# 第二步总结方法:
|
426 |
# TODO,由于有些文章的方法章节名是算法名,所以简单的通过关键词来筛选,很难获取,后面需要用其他的方案去优化。
|
427 |
method_key = ''
|
|
|
466 |
else:
|
467 |
text = summary_text
|
468 |
text = text[:max_token]
|
469 |
+
chat_conclusion_text = self.chat_conclusion(text=text, key=str(key))
|
470 |
+
htmls.append(chat_conclusion_text)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
471 |
htmls.append("\n")
|
472 |
md_text = "\n".join(htmls)
|
473 |
|
|
|
579 |
for choice in response.choices:
|
580 |
result += choice.message.content
|
581 |
print("summary_result:\n", result)
|
582 |
+
return result
|
583 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
584 |
def export_to_markdown(self, text, file_name, mode='w'):
|
585 |
# 使用markdown模块的convert方法,将文本转换为html格式
|
586 |
# html = markdown.markdown(text)
|
|
|
611 |
return sum_info
|
612 |
|
613 |
# 标题
|
614 |
+
title = "ChatPaper"
|
615 |
# 描述
|
616 |
description = '''<div align='center'>
|
617 |
|
618 |
+
Use ChatGPT to summary the papers.
|
619 |
|
620 |
+
Star our Github [ChatPaper](https://github.com/kaixindelele/ChatPaper)
|
621 |
|
622 |
</div>
|
623 |
'''
|