DnDItem / app.py
stale2000's picture
Create app.py
7b664dc
raw
history blame
1.2 kB
#!/usr/bin/env python
# coding: utf-8
# In[ ]:
import os
import openai
import gradio as gr
openai.api_key = "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"
start_sequence = "\nAI:"
restart_sequence = "\nHuman: "
def predict(input,initial_prompt, history=[]):
s = list(sum(history, ()))
s.append(input)
# initial_prompt="The following is a conversation with an AI movie recommendation assistant. The assistant is helpful, creative, clever, and very friendly.Along with movie recommendation it also talks about general topics"
# \n\nHuman: Hello, who are you?\nAI: I am an AI created by OpenAI. How can I help you today?\nHuman: "
response = openai.Completion.create(
model="text-davinci-003",
prompt= initial_prompt + "\n" + str(s),
temperature=0.9,
max_tokens=150,
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","text",'state'],
outputs=["chatbot",'state']).launch()