File size: 826 Bytes
d0ceb72
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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}")