Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -12,6 +12,8 @@ if 'selected_file' not in st.session_state:
|
|
12 |
st.session_state.selected_file = None
|
13 |
if 'view_mode' not in st.session_state:
|
14 |
st.session_state.view_mode = 'view'
|
|
|
|
|
15 |
|
16 |
# Define the markdown variables
|
17 |
Boxing_and_MMA_Commentary_and_Knowledge = """
|
@@ -171,6 +173,7 @@ def file_management_sidebar():
|
|
171 |
# Get list of .md files excluding README.md
|
172 |
md_files = [file for file in glob.glob("*.md") if os.path.basename(file).lower() != 'readme.md']
|
173 |
md_files.sort()
|
|
|
174 |
|
175 |
if md_files:
|
176 |
st.sidebar.markdown("### Markdown Files")
|
@@ -184,12 +187,10 @@ def file_management_sidebar():
|
|
184 |
if st.sidebar.button("📄", key=f"view_{key_base}"):
|
185 |
st.session_state.selected_file = file
|
186 |
st.session_state.view_mode = 'view'
|
187 |
-
st.experimental_rerun()
|
188 |
with col3:
|
189 |
if st.sidebar.button("✏️", key=f"edit_{key_base}"):
|
190 |
st.session_state.selected_file = file
|
191 |
st.session_state.view_mode = 'edit'
|
192 |
-
st.experimental_rerun()
|
193 |
# Option to create a new markdown file
|
194 |
if st.sidebar.button("Create New Markdown File"):
|
195 |
# Generate automatic filename
|
@@ -200,7 +201,6 @@ def file_management_sidebar():
|
|
200 |
st.sidebar.success(f"Created new file: {new_filename}")
|
201 |
st.session_state.selected_file = new_filename
|
202 |
st.session_state.view_mode = 'edit'
|
203 |
-
st.experimental_rerun()
|
204 |
else:
|
205 |
st.sidebar.write("No markdown files found.")
|
206 |
if st.sidebar.button("Create New Markdown File"):
|
@@ -212,7 +212,6 @@ def file_management_sidebar():
|
|
212 |
st.sidebar.success(f"Created new file: {new_filename}")
|
213 |
st.session_state.selected_file = new_filename
|
214 |
st.session_state.view_mode = 'edit'
|
215 |
-
st.experimental_rerun()
|
216 |
|
217 |
# Main application logic
|
218 |
def main():
|
@@ -251,8 +250,9 @@ def main():
|
|
251 |
st.write(f"Generated file **{filename}** with AI lookup results.")
|
252 |
# Clear the query parameters
|
253 |
st.experimental_set_query_params()
|
254 |
-
# Update
|
255 |
-
st.
|
|
|
256 |
except Exception as e:
|
257 |
st.write(f"An error occurred while processing query parameters: {e}")
|
258 |
|
@@ -267,7 +267,6 @@ def main():
|
|
267 |
elif action == 'clear':
|
268 |
# Clear query parameters
|
269 |
st.experimental_set_query_params()
|
270 |
-
st.experimental_rerun()
|
271 |
if 'query' in params:
|
272 |
query_list = params['query']
|
273 |
if query_list:
|
@@ -298,7 +297,8 @@ def main():
|
|
298 |
with open(selected_file, 'w', encoding='utf-8') as f:
|
299 |
f.write(edited_content)
|
300 |
st.success(f"Changes saved to {selected_file}")
|
301 |
-
|
|
|
302 |
else:
|
303 |
st.error("Selected file does not exist.")
|
304 |
else:
|
|
|
12 |
st.session_state.selected_file = None
|
13 |
if 'view_mode' not in st.session_state:
|
14 |
st.session_state.view_mode = 'view'
|
15 |
+
if 'files' not in st.session_state:
|
16 |
+
st.session_state.files = []
|
17 |
|
18 |
# Define the markdown variables
|
19 |
Boxing_and_MMA_Commentary_and_Knowledge = """
|
|
|
173 |
# Get list of .md files excluding README.md
|
174 |
md_files = [file for file in glob.glob("*.md") if os.path.basename(file).lower() != 'readme.md']
|
175 |
md_files.sort()
|
176 |
+
st.session_state.files = md_files # Update session state
|
177 |
|
178 |
if md_files:
|
179 |
st.sidebar.markdown("### Markdown Files")
|
|
|
187 |
if st.sidebar.button("📄", key=f"view_{key_base}"):
|
188 |
st.session_state.selected_file = file
|
189 |
st.session_state.view_mode = 'view'
|
|
|
190 |
with col3:
|
191 |
if st.sidebar.button("✏️", key=f"edit_{key_base}"):
|
192 |
st.session_state.selected_file = file
|
193 |
st.session_state.view_mode = 'edit'
|
|
|
194 |
# Option to create a new markdown file
|
195 |
if st.sidebar.button("Create New Markdown File"):
|
196 |
# Generate automatic filename
|
|
|
201 |
st.sidebar.success(f"Created new file: {new_filename}")
|
202 |
st.session_state.selected_file = new_filename
|
203 |
st.session_state.view_mode = 'edit'
|
|
|
204 |
else:
|
205 |
st.sidebar.write("No markdown files found.")
|
206 |
if st.sidebar.button("Create New Markdown File"):
|
|
|
212 |
st.sidebar.success(f"Created new file: {new_filename}")
|
213 |
st.session_state.selected_file = new_filename
|
214 |
st.session_state.view_mode = 'edit'
|
|
|
215 |
|
216 |
# Main application logic
|
217 |
def main():
|
|
|
250 |
st.write(f"Generated file **{filename}** with AI lookup results.")
|
251 |
# Clear the query parameters
|
252 |
st.experimental_set_query_params()
|
253 |
+
# Update session state
|
254 |
+
st.session_state.selected_file = filename
|
255 |
+
st.session_state.view_mode = 'view'
|
256 |
except Exception as e:
|
257 |
st.write(f"An error occurred while processing query parameters: {e}")
|
258 |
|
|
|
267 |
elif action == 'clear':
|
268 |
# Clear query parameters
|
269 |
st.experimental_set_query_params()
|
|
|
270 |
if 'query' in params:
|
271 |
query_list = params['query']
|
272 |
if query_list:
|
|
|
297 |
with open(selected_file, 'w', encoding='utf-8') as f:
|
298 |
f.write(edited_content)
|
299 |
st.success(f"Changes saved to {selected_file}")
|
300 |
+
# Update the file list in session state
|
301 |
+
st.session_state.files = [file for file in glob.glob("*.md") if os.path.basename(file).lower() != 'readme.md']
|
302 |
else:
|
303 |
st.error("Selected file does not exist.")
|
304 |
else:
|