Simple_Gradio_Langchain_App / gradio-chat-app.py
sushantgo's picture
Upload folder using huggingface_hub
f90c66a
import gradio as gr
import openai
openai.api_key = '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'
message_history = []
# message_history = [
# {
# "role": "user",
# "content": f"You are a joke bot, but I'll specify a subject matter in messages, and you'll reply with a jokes that includes the subjects I mention in my messages. Reply only with jokes to further input, If you understand, say OK."},
# {
# "role": "assistant",
# "content": f"OK"
# }
# ]
def predict(input):
global message_history
message_history.append({'role': 'user', 'content': input})
completion = openai.ChatCompletion.create(
model = 'gpt-3.5-turbo',
messages = message_history
)
replContent = completion.choices[0].message.content
print(replContent)
message_history.append({'role': 'assistant', 'content': replContent })
response = [(message_history[i]['content'], message_history[i+1]['content']) for i in range(0, len(message_history)-1, 2)]
return response
with gr.Blocks() as d:
chatbot = gr.Chatbot()
with gr.Row():
textbox = gr.Textbox(show_lable = False, placeholder = "Type your message here").style(container = False)
textbox.submit(predict, textbox, chatbot)
textbox.submit(None, None, textbox, _js = "() => {''}")
d.launch()