Spaces:
Runtime error
Runtime error
wangrongsheng
commited on
Commit
•
2864074
1
Parent(s):
f3ef2af
Upload 2 files
Browse files- app.py +73 -0
- requirements.txt +3 -0
app.py
ADDED
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from scholarly import scholarly
|
3 |
+
import openai
|
4 |
+
|
5 |
+
def process(key, choice, artitle, trans):
|
6 |
+
openai.api_key = str(key)
|
7 |
+
|
8 |
+
results = []
|
9 |
+
if choice=='单个生成':
|
10 |
+
search_query = scholarly.search_pubs(str(artitle))
|
11 |
+
pub = next(search_query)
|
12 |
+
bib = scholarly.bibtex(pub)
|
13 |
+
|
14 |
+
if trans=='bib':
|
15 |
+
results.append(bib)
|
16 |
+
else:
|
17 |
+
prompt = "请把以下bib格式转为"+str(trans)+"格式:"+str(bib)
|
18 |
+
completion = openai.ChatCompletion.create(
|
19 |
+
model="gpt-3.5-turbo",
|
20 |
+
messages=[
|
21 |
+
{"role": "system", "content": "You are a helpful assistant."},
|
22 |
+
{"role": "user", "content": prompt}
|
23 |
+
]
|
24 |
+
)
|
25 |
+
results.append(completion.choices[0].message)
|
26 |
+
if choice=='批量生成':
|
27 |
+
m_artitle = artitle.split('\n')
|
28 |
+
for i in range(len(m_artitle)):
|
29 |
+
if trans=='bib':
|
30 |
+
results.append(bib)
|
31 |
+
else:
|
32 |
+
prompt = "请把以下bib格式转为"+str(trans)+"格式:"+str(bib)
|
33 |
+
completion = openai.ChatCompletion.create(
|
34 |
+
model="gpt-3.5-turbo",
|
35 |
+
messages=[
|
36 |
+
{"role": "system", "content": "You are a helpful assistant."},
|
37 |
+
{"role": "user", "content": prompt}
|
38 |
+
]
|
39 |
+
)
|
40 |
+
results.append(completion.choices[0].message+'\n')
|
41 |
+
|
42 |
+
return results
|
43 |
+
|
44 |
+
# 标题
|
45 |
+
title = "ChatCitation"
|
46 |
+
# 描述
|
47 |
+
description = '''<div align='left'>
|
48 |
+
论文引用
|
49 |
+
</div>
|
50 |
+
'''
|
51 |
+
|
52 |
+
input_c = [
|
53 |
+
gradio.inputs.Textbox(label="输入OpenAI的API-key",
|
54 |
+
default="",
|
55 |
+
type='password'),
|
56 |
+
gradio.inputs.Radio(choices=["单个生成", "批量生成"],
|
57 |
+
default="单个生成",
|
58 |
+
label="题目生成(默认单个生成)"),
|
59 |
+
gradio.inputs.Textbox(
|
60 |
+
label="输入论文标题(如果为批量则每行一个标题)",
|
61 |
+
default="Transfer learning based plant diseases detection using ResNet50"),
|
62 |
+
gradio.inputs.Dropdown(
|
63 |
+
choices=["AMA", "MLA", "APA", "GB/T 7714", "bib"],
|
64 |
+
label="转化的格式(默认bib)",
|
65 |
+
default="APA"),
|
66 |
+
]
|
67 |
+
|
68 |
+
demo = gr.Interface(fn=process,
|
69 |
+
inputs=input_c,
|
70 |
+
outputs="text",
|
71 |
+
title=title,
|
72 |
+
description=description)
|
73 |
+
demo.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
gradio==3.19.0
|
2 |
+
scholarly
|
3 |
+
openai
|