Spaces:
Runtime error
Runtime error
wangrongsheng
commited on
Commit
•
776a106
1
Parent(s):
903553e
Upload app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
import gradio as gr
|
2 |
-
from scholarly import scholarly
|
3 |
import openai
|
4 |
|
5 |
def process(key, choice, artitle, trans):
|
@@ -7,6 +7,9 @@ def process(key, choice, artitle, trans):
|
|
7 |
|
8 |
results = []
|
9 |
if choice=='单个生成':
|
|
|
|
|
|
|
10 |
search_query = scholarly.search_pubs(str(artitle))
|
11 |
pub = next(search_query)
|
12 |
bib = scholarly.bibtex(pub)
|
@@ -21,17 +24,22 @@ def process(key, choice, artitle, trans):
|
|
21 |
{"role": "system", "content": "You are a helpful assistant."},
|
22 |
{"role": "user", "content": prompt}
|
23 |
]
|
24 |
-
)
|
25 |
-
print(completion.choices[0].message[
|
26 |
-
print('-------------')
|
27 |
print(completion.choices[0].text)
|
28 |
-
results.append(completion.choices[0].message
|
29 |
if choice=='批量生成':
|
30 |
m_artitle = artitle.split('\n')
|
31 |
for i in range(len(m_artitle)):
|
32 |
if trans=='bib':
|
33 |
results.append(bib)
|
34 |
else:
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
prompt = "请把以下bib格式转为"+str(trans)+"格式:"+str(bib)
|
36 |
completion = openai.ChatCompletion.create(
|
37 |
model="gpt-3.5-turbo",
|
@@ -73,4 +81,4 @@ demo = gr.Interface(fn=process,
|
|
73 |
outputs="text",
|
74 |
title=title,
|
75 |
description=description)
|
76 |
-
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
from scholarly import scholarly, ProxyGenerator
|
3 |
import openai
|
4 |
|
5 |
def process(key, choice, artitle, trans):
|
|
|
7 |
|
8 |
results = []
|
9 |
if choice=='单个生成':
|
10 |
+
pg = ProxyGenerator()
|
11 |
+
pg.FreeProxies()
|
12 |
+
scholarly.use_proxy(pg)
|
13 |
search_query = scholarly.search_pubs(str(artitle))
|
14 |
pub = next(search_query)
|
15 |
bib = scholarly.bibtex(pub)
|
|
|
24 |
{"role": "system", "content": "You are a helpful assistant."},
|
25 |
{"role": "user", "content": prompt}
|
26 |
]
|
27 |
+
)
|
28 |
+
print(completion.choices[0].message['content'])
|
|
|
29 |
print(completion.choices[0].text)
|
30 |
+
results.append(completion.choices[0].message)
|
31 |
if choice=='批量生成':
|
32 |
m_artitle = artitle.split('\n')
|
33 |
for i in range(len(m_artitle)):
|
34 |
if trans=='bib':
|
35 |
results.append(bib)
|
36 |
else:
|
37 |
+
pg = ProxyGenerator()
|
38 |
+
pg.FreeProxies()
|
39 |
+
scholarly.use_proxy(pg)
|
40 |
+
search_query = scholarly.search_pubs(str(m_artitle[i]))
|
41 |
+
pub = next(search_query)
|
42 |
+
bib = scholarly.bibtex(pub)
|
43 |
prompt = "请把以下bib格式转为"+str(trans)+"格式:"+str(bib)
|
44 |
completion = openai.ChatCompletion.create(
|
45 |
model="gpt-3.5-turbo",
|
|
|
81 |
outputs="text",
|
82 |
title=title,
|
83 |
description=description)
|
84 |
+
demo.launch(share=True)
|