nlp01 / app.py
hyuan5040's picture
Update app.py
a322db1
raw
history blame
749 Bytes
import openai
import gradio as gr
#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
openai.api_key = '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'
def openai_chat(prompt):
completions = openai.Completion.create(
engine="text-davinci-003",
prompt=prompt,
max_tokens=2048,
n=1,
temperature=0.5,
)
message = completions.choices[0].text
return message.strip()
def chatbot(input, history=[]):
output = openai_chat(input)
history.append((input, output))
return history, history
gr.Interface( title = 'An Alternative to chatGPT - Built by Hrishikesh', fn = chatbot,
inputs = ["text",'state'],
outputs = ["chatbot",'state']).launch(debug = True )