Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -34,19 +34,79 @@ def scan_and_load_files():
|
|
34 |
|
35 |
# Special handling for markdown files
|
36 |
if file_type == 'md':
|
|
|
|
|
|
|
|
|
37 |
if filepath not in [f["filename"] for f in st.session_state.md_files_history]:
|
38 |
-
|
39 |
-
|
40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
|
42 |
loaded_files.append(filepath)
|
43 |
except Exception as e:
|
44 |
st.error(f"π¨ Error loading {filepath}: {str(e)}")
|
45 |
|
|
|
|
|
|
|
|
|
46 |
return loaded_files
|
47 |
|
|
|
|
|
|
|
48 |
# Modify the main function to include initial file scanning
|
49 |
def main():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
st.title("πβ¨ Super Smart File Handler with Markdown Magic! β¨π")
|
51 |
|
52 |
# Scan for existing files on startup
|
|
|
34 |
|
35 |
# Special handling for markdown files
|
36 |
if file_type == 'md':
|
37 |
+
st.session_state.md_outline[filepath] = parse_markdown_outline(content)
|
38 |
+
st.session_state.rendered_content[filepath] = content
|
39 |
+
|
40 |
+
# Add to markdown files history if not already present
|
41 |
if filepath not in [f["filename"] for f in st.session_state.md_files_history]:
|
42 |
+
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
43 |
+
encoded_content = encode_content(content)
|
44 |
+
st.session_state.md_files_history.append({
|
45 |
+
"filename": filepath,
|
46 |
+
"timestamp": timestamp,
|
47 |
+
"content": encoded_content
|
48 |
+
})
|
49 |
+
|
50 |
+
# Create initial version history
|
51 |
+
if filepath not in st.session_state.md_versions:
|
52 |
+
st.session_state.md_versions[filepath] = []
|
53 |
+
st.session_state.md_versions[filepath].append({
|
54 |
+
"timestamp": timestamp,
|
55 |
+
"content": encoded_content,
|
56 |
+
"action": "auto-loaded"
|
57 |
+
})
|
58 |
|
59 |
loaded_files.append(filepath)
|
60 |
except Exception as e:
|
61 |
st.error(f"π¨ Error loading {filepath}: {str(e)}")
|
62 |
|
63 |
+
# Update combined markdown after loading all files
|
64 |
+
if loaded_files:
|
65 |
+
st.session_state.combined_markdown = combine_markdown_files()
|
66 |
+
|
67 |
return loaded_files
|
68 |
|
69 |
+
|
70 |
+
|
71 |
+
|
72 |
# Modify the main function to include initial file scanning
|
73 |
def main():
|
74 |
+
|
75 |
+
# Add a reset button in sidebar
|
76 |
+
if st.sidebar.button("π Reset & Rescan Files"):
|
77 |
+
# Clear all session state
|
78 |
+
for key in list(st.session_state.keys()):
|
79 |
+
del st.session_state[key]
|
80 |
+
st.experimental_rerun()
|
81 |
+
|
82 |
+
st.title("πβ¨ Super Smart File Handler with Markdown Magic! β¨π")
|
83 |
+
|
84 |
+
# Initialize session state
|
85 |
+
if 'file_data' not in st.session_state:
|
86 |
+
st.session_state.file_data = {}
|
87 |
+
if 'file_types' not in st.session_state:
|
88 |
+
st.session_state.file_types = {}
|
89 |
+
if 'md_outline' not in st.session_state:
|
90 |
+
st.session_state.md_outline = {}
|
91 |
+
if 'rendered_content' not in st.session_state:
|
92 |
+
st.session_state.rendered_content = {}
|
93 |
+
if 'file_history' not in st.session_state:
|
94 |
+
st.session_state.file_history = []
|
95 |
+
if 'md_versions' not in st.session_state:
|
96 |
+
st.session_state.md_versions = {}
|
97 |
+
if 'md_files_history' not in st.session_state:
|
98 |
+
st.session_state.md_files_history = []
|
99 |
+
if 'combined_markdown' not in st.session_state:
|
100 |
+
st.session_state.combined_markdown = ""
|
101 |
+
|
102 |
+
# Scan for existing files on startup
|
103 |
+
if 'files_scanned' not in st.session_state:
|
104 |
+
loaded_files = scan_and_load_files()
|
105 |
+
if loaded_files:
|
106 |
+
st.success(f"π Auto-loaded {len(loaded_files)} existing files: {', '.join(loaded_files)}")
|
107 |
+
st.session_state.files_scanned = True
|
108 |
+
|
109 |
+
|
110 |
st.title("πβ¨ Super Smart File Handler with Markdown Magic! β¨π")
|
111 |
|
112 |
# Scan for existing files on startup
|