Spaces:
Runtime error
Runtime error
File size: 792 Bytes
0b9525a 09cef80 060279d 0b9525a 9313e85 0b9525a 08e5ea6 0b9525a 31d6505 0b9525a 6a3cc6f |
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 |
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()
|