Spaces:
Running
Running
Merge pull request #1 from AdiBak/reset_button_top_sidebar
Browse files- .DS_Store +0 -0
- app.py +44 -2
- requirements.txt +1 -0
.DS_Store
ADDED
|
Binary file (8.2 kB). View file
|
|
|
app.py
CHANGED
|
@@ -19,6 +19,7 @@ from dotenv import load_dotenv
|
|
| 19 |
from langchain_community.chat_message_histories import StreamlitChatMessageHistory
|
| 20 |
from langchain_core.messages import HumanMessage
|
| 21 |
from langchain_core.prompts import ChatPromptTemplate
|
|
|
|
| 22 |
|
| 23 |
import global_config as gcfg
|
| 24 |
import helpers.file_manager as filem
|
|
@@ -134,6 +135,23 @@ def reset_api_key():
|
|
| 134 |
st.session_state.api_key_input = ''
|
| 135 |
|
| 136 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 137 |
APP_TEXT = _load_strings()
|
| 138 |
|
| 139 |
# Session variables
|
|
@@ -148,7 +166,26 @@ logger = logging.getLogger(__name__)
|
|
| 148 |
texts = list(GlobalConfig.PPTX_TEMPLATE_FILES.keys())
|
| 149 |
captions = [GlobalConfig.PPTX_TEMPLATE_FILES[x]['caption'] for x in texts]
|
| 150 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 151 |
with st.sidebar:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 152 |
# The PPT templates
|
| 153 |
pptx_template = st.sidebar.radio(
|
| 154 |
'1: Select a presentation template:',
|
|
@@ -285,12 +322,17 @@ def set_up_chat_ui():
|
|
| 285 |
for msg in history.messages:
|
| 286 |
st.chat_message(msg.type).code(msg.content, language='json')
|
| 287 |
|
| 288 |
-
|
|
|
|
| 289 |
placeholder=APP_TEXT['chat_placeholder'],
|
| 290 |
max_chars=GlobalConfig.LLM_MODEL_MAX_INPUT_LENGTH,
|
| 291 |
accept_file=True,
|
| 292 |
file_type=['pdf', ],
|
| 293 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 294 |
prompt_text = prompt.text or ''
|
| 295 |
if prompt['files']:
|
| 296 |
# Store uploaded pdf in session state
|
|
|
|
| 19 |
from langchain_community.chat_message_histories import StreamlitChatMessageHistory
|
| 20 |
from langchain_core.messages import HumanMessage
|
| 21 |
from langchain_core.prompts import ChatPromptTemplate
|
| 22 |
+
from streamlit_extras.bottom_container import bottom
|
| 23 |
|
| 24 |
import global_config as gcfg
|
| 25 |
import helpers.file_manager as filem
|
|
|
|
| 135 |
st.session_state.api_key_input = ''
|
| 136 |
|
| 137 |
|
| 138 |
+
def reset_chat_history():
|
| 139 |
+
"""
|
| 140 |
+
Clear the chat history and related session state variables.
|
| 141 |
+
"""
|
| 142 |
+
if CHAT_MESSAGES in st.session_state:
|
| 143 |
+
del st.session_state[CHAT_MESSAGES]
|
| 144 |
+
if IS_IT_REFINEMENT in st.session_state:
|
| 145 |
+
del st.session_state[IS_IT_REFINEMENT]
|
| 146 |
+
if ADDITIONAL_INFO in st.session_state:
|
| 147 |
+
del st.session_state[ADDITIONAL_INFO]
|
| 148 |
+
if 'pdf_file' in st.session_state:
|
| 149 |
+
del st.session_state['pdf_file']
|
| 150 |
+
if DOWNLOAD_FILE_KEY in st.session_state:
|
| 151 |
+
del st.session_state[DOWNLOAD_FILE_KEY]
|
| 152 |
+
st.rerun()
|
| 153 |
+
|
| 154 |
+
|
| 155 |
APP_TEXT = _load_strings()
|
| 156 |
|
| 157 |
# Session variables
|
|
|
|
| 166 |
texts = list(GlobalConfig.PPTX_TEMPLATE_FILES.keys())
|
| 167 |
captions = [GlobalConfig.PPTX_TEMPLATE_FILES[x]['caption'] for x in texts]
|
| 168 |
|
| 169 |
+
# CSS to reduce spacing around the new chat button
|
| 170 |
+
st.markdown("""
|
| 171 |
+
<style>
|
| 172 |
+
div[data-testid="stHorizontalBlock"] {
|
| 173 |
+
position: absolute;
|
| 174 |
+
top: -25px !important;
|
| 175 |
+
width: 100% !important;
|
| 176 |
+
}
|
| 177 |
+
</style>
|
| 178 |
+
""", unsafe_allow_html=True)
|
| 179 |
+
|
| 180 |
with st.sidebar:
|
| 181 |
+
# New Chat button at the top of sidebar
|
| 182 |
+
col1, col2, col3 = st.columns([1, 2, 1])
|
| 183 |
+
with col2:
|
| 184 |
+
if st.button("New Chat 💬", help="Start a new conversation", key="new_chat_button"):
|
| 185 |
+
reset_chat_history()
|
| 186 |
+
|
| 187 |
+
st.markdown("---") # Separator
|
| 188 |
+
|
| 189 |
# The PPT templates
|
| 190 |
pptx_template = st.sidebar.radio(
|
| 191 |
'1: Select a presentation template:',
|
|
|
|
| 322 |
for msg in history.messages:
|
| 323 |
st.chat_message(msg.type).code(msg.content, language='json')
|
| 324 |
|
| 325 |
+
# Chat input at the bottom
|
| 326 |
+
prompt = st.chat_input(
|
| 327 |
placeholder=APP_TEXT['chat_placeholder'],
|
| 328 |
max_chars=GlobalConfig.LLM_MODEL_MAX_INPUT_LENGTH,
|
| 329 |
accept_file=True,
|
| 330 |
file_type=['pdf', ],
|
| 331 |
+
)
|
| 332 |
+
|
| 333 |
+
|
| 334 |
+
|
| 335 |
+
if prompt:
|
| 336 |
prompt_text = prompt.text or ''
|
| 337 |
if prompt['files']:
|
| 338 |
# Store uploaded pdf in session state
|
requirements.txt
CHANGED
|
@@ -18,6 +18,7 @@ langchain-together~=0.3.0
|
|
| 18 |
langchain-ollama~=0.3.6
|
| 19 |
langchain-openai~=0.3.28
|
| 20 |
streamlit==1.44.1
|
|
|
|
| 21 |
|
| 22 |
python-pptx~=1.0.2
|
| 23 |
json5~=0.9.14
|
|
|
|
| 18 |
langchain-ollama~=0.3.6
|
| 19 |
langchain-openai~=0.3.28
|
| 20 |
streamlit==1.44.1
|
| 21 |
+
streamlit-extras>=0.3.0
|
| 22 |
|
| 23 |
python-pptx~=1.0.2
|
| 24 |
json5~=0.9.14
|