Aditya Bakshi commited on
Commit
50f6065
·
unverified ·
1 Parent(s): 2f30b33

refactor: remove CSS and simplify reset_chat_history cleanup

Browse files

- Remove unsafe HTML styling per PR feedback
- Simplify temp file deletion without exception handling
- Use native Streamlit layout for button positioning

Files changed (1) hide show
  1. app.py +5 -28
app.py CHANGED
@@ -142,19 +142,12 @@ def reset_chat_history():
142
  st.session_state.pop(ADDITIONAL_INFO, None)
143
  st.session_state.pop(PDF_FILE_KEY, None)
144
 
145
- # Safely remove previously generated temp PPTX file
146
  temp_pptx_path = st.session_state.pop(DOWNLOAD_FILE_KEY, None)
147
  if temp_pptx_path:
148
- try:
149
- pptx_path = pathlib.Path(temp_pptx_path)
150
- if pptx_path.exists() and pptx_path.is_file():
151
- pptx_path.unlink()
152
- logger.info(f"Removed temporary PPTX file: {pptx_path}")
153
- except Exception as e:
154
- logger.warning(f"Failed to remove temporary PPTX file {temp_pptx_path}: {e}")
155
-
156
- st.rerun() # Reload the app
157
-
158
 
159
 
160
  APP_TEXT = _load_strings()
@@ -172,28 +165,14 @@ logger = logging.getLogger(__name__)
172
  texts = list(GlobalConfig.PPTX_TEMPLATE_FILES.keys())
173
  captions = [GlobalConfig.PPTX_TEMPLATE_FILES[x]['caption'] for x in texts]
174
 
175
- # CSS to reduce spacing around the new chat button
176
- st.markdown(
177
- """
178
- <style>
179
- div[data-testid="stHorizontalBlock"] {
180
- position: absolute;
181
- top: -25px !important;
182
- width: 100% !important;
183
- }
184
- </style>
185
- """,
186
- unsafe_allow_html=True)
187
 
188
  with st.sidebar:
189
  # New Chat button at the top of sidebar
190
- col1, col2, col3 = st.columns([1, 2, 1])
191
  with col2:
192
  if st.button('New Chat 💬', help='Start a new conversation', key='new_chat_button'):
193
  reset_chat_history() # Reset the chat history when the button is clicked
194
 
195
- st.markdown('---') # Separator
196
-
197
  # The PPT templates
198
  pptx_template = st.sidebar.radio(
199
  '1: Select a presentation template:',
@@ -359,8 +338,6 @@ def set_up_chat_ui():
359
  accept_file=True,
360
  file_type=['pdf', ],
361
  )
362
-
363
-
364
 
365
  if prompt:
366
  prompt_text = prompt.text or ''
 
142
  st.session_state.pop(ADDITIONAL_INFO, None)
143
  st.session_state.pop(PDF_FILE_KEY, None)
144
 
145
+ # Remove previously generated temp PPTX file
146
  temp_pptx_path = st.session_state.pop(DOWNLOAD_FILE_KEY, None)
147
  if temp_pptx_path:
148
+ pptx_path = pathlib.Path(temp_pptx_path)
149
+ if pptx_path.exists() and pptx_path.is_file():
150
+ pptx_path.unlink()
 
 
 
 
 
 
 
151
 
152
 
153
  APP_TEXT = _load_strings()
 
165
  texts = list(GlobalConfig.PPTX_TEMPLATE_FILES.keys())
166
  captions = [GlobalConfig.PPTX_TEMPLATE_FILES[x]['caption'] for x in texts]
167
 
 
 
 
 
 
 
 
 
 
 
 
 
168
 
169
  with st.sidebar:
170
  # New Chat button at the top of sidebar
171
+ col1, col2, col3 = st.columns([.17, 0.8, .1])
172
  with col2:
173
  if st.button('New Chat 💬', help='Start a new conversation', key='new_chat_button'):
174
  reset_chat_history() # Reset the chat history when the button is clicked
175
 
 
 
176
  # The PPT templates
177
  pptx_template = st.sidebar.radio(
178
  '1: Select a presentation template:',
 
338
  accept_file=True,
339
  file_type=['pdf', ],
340
  )
 
 
341
 
342
  if prompt:
343
  prompt_text = prompt.text or ''