File size: 696 Bytes
99570f5
 
 
18111a6
99570f5
 
 
 
 
 
 
 
 
 
 
 
003fa24
c076f0c
 
003fa24
 
99570f5
 
 
 
84a890c
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
import openai
import gradio as gr

openai.api_key = "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"

def chatbot(text):
    return openai.Completion.create(
        engine="text-davinci-003",
        prompt=text,
        max_tokens = 1024,
        n=1,
        temperature=0.5,
    ).choices[0].text.strip()

def gradio_interface(prompt, history=[]):
    output = chatbot(prompt)
    if history != []:
        history.append((prompt,output))
        history.reverse()
    else:
        history.append((prompt, output))
    return history, history

gr.Interface(fn = gradio_interface,
            inputs = ["text", 'state'],
            outputs = ["chatbot", 'state']).launch(debug = False)