File size: 2,565 Bytes
2864074
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import gradio as gr
from scholarly import scholarly
import openai

def process(key, choice, artitle, trans):
    openai.api_key = str(key)
    
    results = []
    if choice=='单个生成':
        search_query = scholarly.search_pubs(str(artitle))
        pub = next(search_query)
        bib = scholarly.bibtex(pub)
        
        if trans=='bib':
            results.append(bib)
        else:
            prompt = "请把以下bib格式转为"+str(trans)+"格式:"+str(bib)
            completion = openai.ChatCompletion.create(
            model="gpt-3.5-turbo",
            messages=[
                {"role": "system", "content": "You are a helpful assistant."},
                {"role": "user", "content": prompt}
            ]
            )
            results.append(completion.choices[0].message)
     if choice=='批量生成':
        m_artitle = artitle.split('\n')
        for i in range(len(m_artitle)):
            if trans=='bib':
                results.append(bib)
            else:
                prompt = "请把以下bib格式转为"+str(trans)+"格式:"+str(bib)
                completion = openai.ChatCompletion.create(
                model="gpt-3.5-turbo",
                messages=[
                    {"role": "system", "content": "You are a helpful assistant."},
                    {"role": "user", "content": prompt}
                ]
                )
                results.append(completion.choices[0].message+'\n')
    
    return results

# 标题
title = "ChatCitation"
# 描述
description = '''<div align='left'>
论文引用
</div>
'''

input_c = [
        gradio.inputs.Textbox(label="输入OpenAI的API-key",
                          default="",
                          type='password'),
        gradio.inputs.Radio(choices=["单个生成", "批量生成"],
                        default="单个生成",
                        label="题目生成(默认单个生成)"),
        gradio.inputs.Textbox(
                        label="输入论文标题(如果为批量则每行一个标题)",
                        default="Transfer learning based plant diseases detection using ResNet50"),
        gradio.inputs.Dropdown(
                        choices=["AMA", "MLA", "APA", "GB/T 7714", "bib"],
                        label="转化的格式(默认bib)",
                        default="APA"),
        ]

demo = gr.Interface(fn=process, 
                    inputs=input_c,
                    outputs="text",
                    title=title,
                    description=description)
demo.launch()