Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,84 +1,31 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
import os
|
| 3 |
-
from langchain_core.prompts import ChatPromptTemplate
|
| 4 |
-
from langchain_google_genai import ChatGoogleGenerativeAI
|
| 5 |
-
from langchain_core.prompts import MessagesPlaceholder
|
| 6 |
-
from langchain.memory import ConversationBufferWindowMemory
|
| 7 |
-
from operator import itemgetter
|
| 8 |
-
from langchain_core.runnables import RunnableLambda, RunnablePassthrough
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
[
|
| 16 |
-
('system', 'you are a good assistant.'),
|
| 17 |
-
MessagesPlaceholder(variable_name='history'),
|
| 18 |
-
("human", "{input}")
|
| 19 |
-
]
|
| 20 |
-
)
|
| 21 |
|
| 22 |
-
#
|
| 23 |
-
|
| 24 |
-
st.session_state.memory = ConversationBufferWindowMemory(k=10, return_messages=True)
|
| 25 |
|
| 26 |
-
# Define the
|
| 27 |
-
|
| 28 |
-
|
| 29 |
|
| 30 |
-
#
|
| 31 |
-
|
| 32 |
-
st.
|
| 33 |
-
st.header('Interactive Chatbot')
|
| 34 |
-
st.write('''An interactive chatbot is designed to engage in dynamic, back-and-forth conversations with users.
|
| 35 |
-
These chatbots can understand and retain context from previous interactions, making their responses more
|
| 36 |
-
relevant and coherent as the conversation progresses. Interactive chatbots often use advanced natural language
|
| 37 |
-
processing (NLP) techniques and memory management to provide a more human-like experience. They are commonly used
|
| 38 |
-
in applications where ongoing interaction and context awareness are crucial, such as customer support, virtual
|
| 39 |
-
assistants, and personalized recommendations.''')
|
| 40 |
-
st.header('Non-Interactive Chatbot')
|
| 41 |
-
st.write('''A non-interactive chatbot, on the other hand, is designed for more straightforward, single-turn interactions.
|
| 42 |
-
These chatbots do not retain context from previous interactions, meaning each user query is treated independently.
|
| 43 |
-
Non-interactive chatbots are typically used for simple, transactional tasks where context is not required. They are
|
| 44 |
-
easier to develop and deploy and are suitable for scenarios where the interaction is brief and to the point.''')
|
| 45 |
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
if st.button("Submit"):
|
| 52 |
-
response = chain.invoke({"input": user_input})
|
| 53 |
-
st.write(f"Assistant: {response.content}")
|
| 54 |
-
st.session_state.memory.save_context({"input": user_input}, {"output": response.content})
|
| 55 |
-
st.session_state.user_input = "" # Clear the input box
|
| 56 |
-
if st.checkbox("Show Chat History"):
|
| 57 |
-
chat_history = st.session_state.memory.load_memory_variables({})
|
| 58 |
-
st.write(chat_history)
|
| 59 |
-
|
| 60 |
-
def page2():
|
| 61 |
-
st.title("Interactive Chatbot")
|
| 62 |
-
if 'user_input' not in st.session_state:
|
| 63 |
-
st.session_state.user_input = ""
|
| 64 |
-
user_input = st.text_area("User: ", st.session_state.user_input, height=100)
|
| 65 |
-
if st.button("Submit"):
|
| 66 |
-
response = chain.invoke({"input": user_input})
|
| 67 |
-
st.write(f"Assistant: {response.content}")
|
| 68 |
-
st.session_state.memory.save_context({"input": user_input}, {"output": response.content})
|
| 69 |
-
st.session_state.user_input = "" # Clear the input box
|
| 70 |
-
if st.checkbox("Show Chat History"):
|
| 71 |
-
chat_history = st.session_state.memory.load_memory_variables({})
|
| 72 |
-
st.write(chat_history)
|
| 73 |
|
| 74 |
-
#
|
| 75 |
-
|
| 76 |
-
page
|
| 77 |
|
| 78 |
-
#
|
| 79 |
-
|
| 80 |
-
home()
|
| 81 |
-
elif page == "Page 1":
|
| 82 |
-
page1()
|
| 83 |
-
elif page == "Page 2":
|
| 84 |
-
page2()
|
|
|
|
| 1 |
import streamlit as st
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
+
def page1():
|
| 4 |
+
st.write("This is Page 1!")
|
| 5 |
|
| 6 |
+
def page2():
|
| 7 |
+
st.write("This is Page 2!")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
+
# Create a Streamlit app
|
| 10 |
+
app = st.StreamlitApp()
|
|
|
|
| 11 |
|
| 12 |
+
# Define the main app logic
|
| 13 |
+
def main():
|
| 14 |
+
st.title("Welcome to My App")
|
| 15 |
|
| 16 |
+
# Create two buttons
|
| 17 |
+
button1 = st.button("Go to Page 1")
|
| 18 |
+
button2 = st.button("Go to Page 2")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
+
# Use Streamlit's routing feature to navigate between pages
|
| 21 |
+
if button1:
|
| 22 |
+
app.page("page1")
|
| 23 |
+
elif button2:
|
| 24 |
+
app.page("page2")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
+
# Register the pages with Streamlit
|
| 27 |
+
app.page("page1", page1)
|
| 28 |
+
app.page("page2", page2)
|
| 29 |
|
| 30 |
+
# Run the main app logic
|
| 31 |
+
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|