suthanhcong's picture
1st Demo
b2932f0
import gradio as gr
import openai
from langchain.chat_models import ChatOpenAI
from langchain.chains import ConversationChain
from langchain.memory import ConversationBufferMemory
from langchain.schema import (
AIMessage,
HumanMessage,
SystemMessage
)
# import random
# import time
llm = ChatOpenAI(temperature=0.0, openai_api_key="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")
memory = ConversationBufferMemory()
conversation = ConversationChain(
llm=llm,
memory = memory,
# verbose=True
)
with gr.Blocks() as demo:
chatbot = gr.Chatbot()
msg = gr.Textbox()
clear = gr.ClearButton([msg, chatbot])
def respond(message, chat_history):
bot_message = conversation.predict(input=message)
chat_history.append((message, bot_message))
return "", chat_history
msg.submit(respond, [msg, chatbot], [msg, chatbot])
if __name__ == "__main__":
demo.launch()