hiwei commited on
Commit
cfe4bd1
1 Parent(s): 6bacd97

add paper_preview.py

Browse files
Files changed (1) hide show
  1. apps/paper_preview.py +61 -0
apps/paper_preview.py ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import traceback
2
+
3
+ import gradio as gr
4
+
5
+ from apps.components import chat_accordion
6
+
7
+ IDEA_TITLE = "论文速览"
8
+
9
+ prompt_tmpl = """下面是一篇论文的标题和摘要,请从以下几个方面进行总结:
10
+
11
+ 1. 介绍本文的主要工作
12
+ 2. 本文工作的主要亮点
13
+ 3. 核心关键词(最多5个技术,能够代表本文核心技术,格式:`英文` (`中文`) )
14
+ 4. 从实用性、创新性和推荐度进行打分(各项满分5分)。
15
+
16
+ ===
17
+ 标题:{title}
18
+ ===
19
+ 摘要:{abstract}
20
+ ===
21
+
22
+ 注意:生成内容要简练,语言的组织要通顺、容易阅读和理解,并能够快速获取信息。
23
+ """
24
+
25
+
26
+ def paper_preview_demo(client):
27
+ def preview(title, abstract, temperature, top_p):
28
+ if not title or not abstract:
29
+ return None
30
+ content = prompt_tmpl.format(title=title, abstract=abstract)
31
+ try:
32
+ stream = client.simple_chat(
33
+ content,
34
+ [],
35
+ temperature=temperature,
36
+ top_p=top_p,
37
+ )
38
+ for resp, _ in stream:
39
+ pass
40
+ return resp
41
+ except Exception:
42
+ return traceback.format_exc()
43
+
44
+ with gr.Row():
45
+ with gr.Column():
46
+ title = gr.Textbox(label="论文标题")
47
+ abstract = gr.Textbox(label="摘要", lines=5)
48
+ with gr.Row():
49
+ with gr.Column():
50
+ submit = gr.Button("速览", variant="primary")
51
+ with gr.Column():
52
+ clear = gr.Button("清空")
53
+ temperature, top_p = chat_accordion()
54
+
55
+ with gr.Column():
56
+ outputs = gr.Textbox(label="速览内容", lines=5)
57
+
58
+ submit.click(
59
+ preview, inputs=[title, abstract, temperature, top_p], outputs=outputs
60
+ )
61
+ clear.click(lambda x: (None, None), inputs=None, outputs=[title, abstract])