wangrongsheng commited on
Commit
36d0e0c
1 Parent(s): e51689f

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -3
app.py CHANGED
@@ -12,6 +12,27 @@ from PIL import Image
12
  import gradio
13
  import markdown
14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  class Paper:
16
  def __init__(self, path, title='', url='', abs='', authers=[], sl=[]):
17
  # 初始化函数,根据pdf路径初始化Paper对象
@@ -610,6 +631,27 @@ def upload_pdf(key, text, file):
610
  sum_info = reader.summary_with_chat(paper_list=paper_list, key=key)
611
  return sum_info
612
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
613
  # 标题
614
  title = "ChatPaper"
615
  # 描述
@@ -634,7 +676,8 @@ ip = [
634
  gradio.inputs.File(label="请上传论文PDF(必填)")
635
  ]
636
 
637
- interface = gradio.Interface(fn=upload_pdf, inputs=ip, outputs="html", title=title, description=description)
638
 
639
- # 运行Gradio应用程序
640
- interface.launch()
 
 
12
  import gradio
13
  import markdown
14
 
15
+ def get_response(system, context, myKey, raw = False):
16
+ openai.api_key = myKey
17
+ response = openai.ChatCompletion.create(
18
+ model="gpt-3.5-turbo",
19
+ messages=[system, *context],
20
+ )
21
+ openai.api_key = ""
22
+ if raw:
23
+ return response
24
+ else:
25
+ message = response["choices"][0]["message"]["content"]
26
+ message_with_stats = f'{message}'
27
+ return message, parse_text(message_with_stats)
28
+
29
+ def valid_apikey(api_key):
30
+ try:
31
+ get_response({"role": "system", "content": "You are a helpful assistant."}, [{"role": "user", "content": "test"}], api_key)
32
+ return "可用的api-key"
33
+ except:
34
+ return "无效的api-key"
35
+
36
  class Paper:
37
  def __init__(self, path, title='', url='', abs='', authers=[], sl=[]):
38
  # 初始化函数,根据pdf路径初始化Paper对象
 
631
  sum_info = reader.summary_with_chat(paper_list=paper_list, key=key)
632
  return sum_info
633
 
634
+ api_title = "api-key可用验证"
635
+ api_description = '''<div align='left'>
636
+
637
+ <img src='https://visitor-badge.laobi.icu/badge?page_id=https://huggingface.co/spaces/wangrongsheng/ChatPaper'>
638
+
639
+ <img align='right' src='https://i.328888.xyz/2023/03/12/vH9dU.png' width="150">
640
+
641
+ Use ChatGPT to summary the papers.Star our Github [🌟ChatPaper](https://github.com/kaixindelele/ChatPaper) .
642
+
643
+ 💗如果您觉得我们的项目对您有帮助,还请您给我们一些鼓励!💗
644
+
645
+ 🔴请注意:千万不要用于严肃的学术场景,只能用于论文阅读前的初筛!
646
+
647
+ </div>
648
+ '''
649
+
650
+ api_input = [
651
+ gradio.inputs.Textbox(label="请输入你的api-key(必填)", default="")
652
+ ]
653
+ api_gui = gradio.Interface(fn=valid_apikey, inputs=api_input, outputs="text", title=api_title, description=api_description)
654
+
655
  # 标题
656
  title = "ChatPaper"
657
  # 描述
 
676
  gradio.inputs.File(label="请上传论文PDF(必填)")
677
  ]
678
 
679
+ chatpaper_gui = gradio.Interface(fn=upload_pdf, inputs=ip, outputs="html", title=title, description=description)
680
 
681
+ # Start server
682
+ gui = gradio.TabbedInterface(interface_list=[api_gui, chatpaper_gui], tab_names=["API-key", "ChatPaper"])
683
+ gui.launch(quiet=True,show_api=False)