Spaces:
Runtime error
Runtime error
File size: 931 Bytes
bd9be51 b2932f0 |
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 31 32 33 34 35 36 |
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()
|