SiddarthaRachakonda commited on
Commit
91d2b07
1 Parent(s): 4c9da95

initial commit

Browse files
app.py ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+
3
+ pg = st.navigation([
4
+ st.Page("pages/simple_page.py"),
5
+ st.Page("pages/formatted_page.py"),
6
+ st.Page("pages/history_page.py"),
7
+ st.Page("pages/rag_page.py"),
8
+ st.Page("pages/filtered_rag_page.py"),
9
+ ])
10
+ pg.run()
11
+
12
+
pages/filtered_rag_page.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ from streamlit.runtime.scriptrunner import get_script_run_ctx
2
+ from pages.page_base import chat_interface
3
+
4
+
5
+ chat_title = "Filtered RAG Chat App"
6
+ url = "[YOUR FILTERED RAG URL]"
7
+ page_hash = get_script_run_ctx().page_script_hash
8
+
9
+ chat_interface(chat_title, page_hash, url)
pages/formatted_page.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ from streamlit.runtime.scriptrunner import get_script_run_ctx
2
+ from pages.page_base import chat_interface
3
+
4
+
5
+ chat_title = "Formatted Chat App"
6
+ url = "[YOUR FORMATTED CHAT URL]"
7
+ page_hash = get_script_run_ctx().page_script_hash
8
+
9
+ chat_interface(chat_title, page_hash, url)
pages/history_page.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ from streamlit.runtime.scriptrunner import get_script_run_ctx
2
+ from pages.page_base import chat_interface
3
+
4
+
5
+ chat_title = "History Chat App"
6
+ url = "[YOUR HISTORY CHAT URL]"
7
+ page_hash = get_script_run_ctx().page_script_hash
8
+
9
+ chat_interface(chat_title, page_hash, url)
pages/page_base.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from langserve.client import RemoteRunnable
3
+
4
+ def get_response(user_input, url, username):
5
+ response_placeholder = st.empty()
6
+ full_response = ""
7
+ chain = RemoteRunnable(url)
8
+ stream = chain.stream(input={'question': user_input, 'username': username})
9
+ for chunk in stream:
10
+ full_response += chunk
11
+ response_placeholder.markdown(full_response)
12
+
13
+ return full_response
14
+
15
+ def chat_interface(chat_title, page_hash ,url):
16
+ st.title(chat_title)
17
+
18
+ # Add username input at the top of the page
19
+ username = st.text_input("Enter your username:", key="username_input", value="Guest")
20
+
21
+ # Initialize page-specific chat history
22
+ if "chat_histories" not in st.session_state:
23
+ st.session_state.chat_histories = {}
24
+
25
+ if page_hash not in st.session_state.chat_histories:
26
+ st.session_state.chat_histories[page_hash] = []
27
+
28
+ # Display chat messages from history for the current page
29
+ for message in st.session_state.chat_histories[page_hash]:
30
+ with st.chat_message(message["role"]):
31
+ st.markdown(message["content"])
32
+
33
+ # React to user input
34
+ if prompt := st.chat_input("What is your message?"):
35
+ # Display user message in chat message container
36
+ st.chat_message("user").markdown(prompt)
37
+ # Add user message to chat history
38
+ st.session_state.chat_histories[page_hash].append({"role": "user", "content": prompt})
39
+
40
+ # Get streaming response
41
+ with st.chat_message("assistant"):
42
+ full_response = get_response(prompt, url, username)
43
+
44
+ # Add assistant response to chat history
45
+ st.session_state.chat_histories[page_hash].append({"role": "assistant", "content": full_response})
46
+
47
+ if __name__ == "__main__":
48
+ chat_interface()
pages/rag_page.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ from streamlit.runtime.scriptrunner import get_script_run_ctx
2
+ from pages.page_base import chat_interface
3
+
4
+
5
+ chat_title = "RAG Chat App"
6
+ url = "[YOUR RAG CHAT URL]"
7
+ page_hash = get_script_run_ctx().page_script_hash
8
+
9
+ chat_interface(chat_title, page_hash, url)
pages/simple_page.py ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # import streamlit as st
2
+ # import time
3
+ # from langserve import RemoteRunnable
4
+ from streamlit.runtime.scriptrunner import get_script_run_ctx
5
+ import streamlit as st
6
+ from pages.page_base import chat_interface
7
+
8
+ chat_title = "Simple Chat App"
9
+ url = "https://damienbenveniste-backend.hf.space/simple"
10
+ page_hash = get_script_run_ctx().page_script_hash
11
+
12
+ chat_interface(chat_title, page_hash, url)
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ langserve[client]