Damien Benveniste commited on
Commit
b5f1f10
·
1 Parent(s): 5dd0e00
pages/__pycache__/page_base.cpython-312.pyc ADDED
Binary file (2.42 kB). View file
 
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 = "https://damienbenveniste-backend.hf.space/filtered_rag"
7
+ page_hash = get_script_run_ctx().page_script_hash
8
+
9
+ chat_interface(chat_title, page_hash, url, username='Damien3')
pages/formatted_page.py ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ from streamlit.runtime.scriptrunner import get_script_run_ctx
2
+ from pages.page_base import chat_interface
3
+
4
+
5
+
6
+ chat_title = "Formatted Chat App"
7
+ url = "https://damienbenveniste-backend.hf.space/formatted"
8
+ page_hash = get_script_run_ctx().page_script_hash
9
+
10
+ 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 = "https://damienbenveniste-backend.hf.space/history"
7
+ page_hash = get_script_run_ctx().page_script_hash
8
+
9
+ chat_interface(chat_title, page_hash, url, username='Damien')
pages/page_base.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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, username=None):
16
+ st.title(chat_title)
17
+
18
+ # Initialize page-specific chat history
19
+ if "chat_histories" not in st.session_state:
20
+ st.session_state.chat_histories = {}
21
+
22
+ if page_hash not in st.session_state.chat_histories:
23
+ st.session_state.chat_histories[page_hash] = []
24
+
25
+ # Display chat messages from history for the current page
26
+ for message in st.session_state.chat_histories[page_hash]:
27
+ with st.chat_message(message["role"]):
28
+ st.markdown(message["content"])
29
+
30
+ # React to user input
31
+ if prompt := st.chat_input("What is your message?"):
32
+ # Display user message in chat message container
33
+ st.chat_message("user").markdown(prompt)
34
+ # Add user message to chat history
35
+ st.session_state.chat_histories[page_hash].append({"role": "user", "content": prompt})
36
+
37
+ # Get streaming response
38
+ with st.chat_message("assistant"):
39
+ full_response = get_response(prompt, url, username)
40
+
41
+ # Add assistant response to chat history
42
+ st.session_state.chat_histories[page_hash].append({"role": "assistant", "content": full_response})
43
+
44
+ if __name__ == "__main__":
45
+ 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 = "https://damienbenveniste-backend.hf.space/rag"
7
+ page_hash = get_script_run_ctx().page_script_hash
8
+
9
+ chat_interface(chat_title, page_hash, url, username='Damien2')
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)