Spaces:
Runtime error
Runtime error
File size: 726 Bytes
0b9525a 179e5b8 0b9525a 08e5ea6 0b9525a 27bcfb5 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 |
import os
import openai
import gradio as gr
openai.api_key ="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"
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()
|