Iris commited on
Commit
8544ad2
·
1 Parent(s): 8c21739

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +101 -0
app.py ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import openai
2
+ from openai.error import RateLimitError
3
+
4
+
5
+ openai.api_key = "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"
6
+ prompt = """
7
+ 我需要你帮助我完成会议记录的总结和梳理。我会给你提供一长段会议记录,其中包含多个参会者的对话记录。你需要完成如下的任务:
8
+ 1. 提取出会议主要讨论的几个主题或者要点。
9
+ 2. 针对会议的每一个主题,请你找到所有相关的会议记录,并将它们梳理总结,为我生成有条理的摘要。
10
+
11
+ 在输出时,请注意以下几点:
12
+ 1. 输出内容中避免口语化内容
13
+ 2. 输出格式是层级列表
14
+ """
15
+
16
+ def get_chatgpt_reply(query, context=[]):
17
+ context += [query]
18
+ try:
19
+ completion = openai.ChatCompletion.create(
20
+ model="gpt-3.5-turbo",
21
+ messages=[{"role": "user", "content": '\n\n'.join(context)[:4096]}]
22
+ )
23
+ response = completion.choices[0].message["content"]
24
+ except RateLimitError:
25
+ response = "服务器请求次数过多,请稍后重新尝试"
26
+ context += [response]
27
+ responses = [(u,b) for u,b in zip(context[::2], context[1::2])]
28
+ return responses, context
29
+
30
+
31
+ def get_chatgpt_summary(content):
32
+ try:
33
+ completion = openai.ChatCompletion.create(
34
+ model="gpt-3.5-turbo",
35
+ messages=[{"role": "system", "content": prompt},
36
+ {"role": "user", "content": content}],
37
+ temperature=0.5
38
+ )
39
+ response = completion.choices[0].message["content"]
40
+ except RateLimitError:
41
+ response = "服务器请求次数过多,请稍后重新尝试"
42
+ return response
43
+
44
+
45
+ import gradio as gr
46
+ from docx import Document
47
+
48
+
49
+ def upload_file(file):
50
+ doc = Document(file.name)
51
+ content = ""
52
+ for para in doc.paragraphs:
53
+ content += para.text
54
+ content += '\n'
55
+ return content
56
+
57
+ def download_file(content):
58
+ doc = Document()
59
+ doc.add_paragraph(content)
60
+ doc.save("会议纪要.docx")
61
+ return None
62
+
63
+
64
+ with gr.Blocks(theme=gr.themes.Default(text_size='lg', radius_size='sm')) as demo:
65
+ with gr.Column():
66
+ # 产品介绍
67
+ title = gr.Markdown("# <center>ChatMeeting</center>")
68
+ desc = gr.Markdown("<center>让AI帮你整理会议纪要\n\n支持.docx文件</center>")
69
+
70
+ with gr.Column():
71
+ # 文件上传
72
+ file_input = gr.File(file_types=[".docx"], label="原始文稿", interactive=True)
73
+ upload_btn = gr.Button(value="上传")
74
+
75
+ with gr.Row():
76
+ with gr.Tab("原文"):
77
+ # 原文
78
+ content_box = gr.Textbox(label="文稿内容")
79
+ download_btn = gr.Button(value="下载")
80
+ with gr.Tab("总结"):
81
+ # 总结
82
+ summary_box = gr.Textbox(label="总结内容")
83
+ download_btn = gr.Button(value="下载")
84
+ with gr.Column():
85
+ # 对话交互
86
+ chatbot = gr.Chatbot(label="对话内容").style(height=400)
87
+ state = gr.State([])
88
+ txt = gr.Textbox(label="用户", placeholder="请输入内容")
89
+ with gr.Row():
90
+ summary = gr.Button(value="一键梳理")
91
+ clear = gr.Button(value="清空")
92
+
93
+ summary.click(fn=get_chatgpt_summary, inputs=content_box, outputs=summary_box)
94
+ txt.submit(get_chatgpt_reply, [txt, state], [chatbot, state])
95
+ clear.click(lambda: None, None, chatbot, queue=False)
96
+
97
+ upload_btn.click(fn=upload_file, inputs=file_input, outputs=content_box)
98
+ download_btn.click(fn=download_file, inputs=content_box, outputs=None)
99
+
100
+
101
+ demo.launch()