thisisdev's picture
Application
d0ceb72 verified
raw
history blame
826 Bytes
import os
import streamlit as st
from langchain.chains import ConverstationChain
from langchain_openai import ChatOpenAI
from langchain.memory import ConversationBufferMemory
os.environ["OPENAI_API_KEY"] = ""
# Intialize the chatbot
@st.cache_resource
def init_chatbot():
memory = ConversationBufferMemory()
chatbot = ConverstationChain(
llm =ChatOpenAI(model = "gpt-4o-mini"),
memory = memory,
verbose = False
)
return chatbot
# Streamlit Application
st.title("Langchain Chatbot")
st.write("Hi, I'm a chatbot built with Langchain powered by GPT. How can I assist you today?")
user_input = st.text_input("You:", placeholder = "Ask me anything....")
if user_input:
with st.spinner("Thinking......"):
resp = chatbot.run(user_input)
st.write(f"Chatbot: {resp}")