Wootang01's picture
Update app.py
060279d
import os
import openai
import gradio as gr
#openai.api_key ="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"
apikey = os.environ.get('myfirstsecret')
openai.api_key = apikey
start_sequence = "\nAI:"
restart_sequence = "\nHuman: "
def predict(input, history=[]):
s = list(sum(history, ()))
s.append(input)
response = openai.Completion.create(
model="text-davinci-003",
prompt= str(s),
temperature=0.9,
max_tokens=200,
top_p=1,
frequency_penalty=0,
presence_penalty=0.6,
stop=[" Human:", " AI:"])
# tokenize the new input sentence
response2 = response["choices"][0]["text"]
history.append((input, response2))
return history, history
gr.Interface(fn=predict, inputs=["text",'state'], outputs=["chatbot",'state']).launch()