gradio_starter / app.py
kaseketsu
gradio demo gpt3.5
3a06677
import gradio as gr
import openai
openai.api_key = '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'
def chat(message,history):
history = history or []
messages = [{'role':'system','content':'you are a helpful assistant'}]
for user_ask,gpt_answer in history:
messages.append({'role':'user','content':user_ask})
messages.append({'role':'assistant','content':gpt_answer})
messages.append({'role':'user','content':message})
get_response = openai.ChatCompletion.create(
model = 'gpt-3.5-turbo',
messages = messages,
temperature = 0.7,
max_tokens = 1000
)
real_response = get_response['choices'][0]['message']['content']
history.append((message,real_response))
return history,history
# seafoam = gr.Theme.from_hub('gradio/seafoam')
with gr.Blocks() as demo:
gr.Markdown('<h1 style = text-align : center> ChatGPT Conversation <h1>')
chatbot = gr.Chatbot(elem_id = 'Chat_window')
input = gr.Textbox(label = 'Your message',placeholder = 'Type your message here',lines = 2,elem_id = 'message',interactive = True)
button = gr.Button('send')
state = gr.State()
button.click(fn = chat,inputs = [input,state],outputs = [chatbot,state])
demo.launch(auth = ('admin','123456'))