Spaces:
Sleeping
Sleeping
Application
Browse files
app.py
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import streamlit as st
|
3 |
+
from langchain.chains import ConverstationChain
|
4 |
+
from langchain_openai import ChatOpenAI
|
5 |
+
from langchain.memory import ConversationBufferMemory
|
6 |
+
|
7 |
+
os.environ["OPENAI_API_KEY"] = ""
|
8 |
+
|
9 |
+
# Intialize the chatbot
|
10 |
+
@st.cache_resource
|
11 |
+
def init_chatbot():
|
12 |
+
memory = ConversationBufferMemory()
|
13 |
+
chatbot = ConverstationChain(
|
14 |
+
llm =ChatOpenAI(model = "gpt-4o-mini"),
|
15 |
+
memory = memory,
|
16 |
+
verbose = False
|
17 |
+
)
|
18 |
+
|
19 |
+
return chatbot
|
20 |
+
|
21 |
+
# Streamlit Application
|
22 |
+
st.title("Langchain Chatbot")
|
23 |
+
st.write("Hi, I'm a chatbot built with Langchain powered by GPT. How can I assist you today?")
|
24 |
+
|
25 |
+
user_input = st.text_input("You:", placeholder = "Ask me anything....")
|
26 |
+
|
27 |
+
if user_input:
|
28 |
+
with st.spinner("Thinking......"):
|
29 |
+
resp = chatbot.run(user_input)
|
30 |
+
st.write(f"Chatbot: {resp}")
|