Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -118,11 +118,45 @@ def show_download_links(subdir):
|
|
| 118 |
sequence_number = file_sequence_numbers[file_path]
|
| 119 |
|
| 120 |
if os.path.isfile(file_path):
|
| 121 |
-
|
| 122 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
else:
|
| 124 |
st.write(f"File not found: {file}")
|
| 125 |
|
|
|
|
| 126 |
def get_download_link(file):
|
| 127 |
with open(file, "rb") as f:
|
| 128 |
bytes = f.read()
|
|
|
|
| 118 |
sequence_number = file_sequence_numbers[file_path]
|
| 119 |
|
| 120 |
if os.path.isfile(file_path):
|
| 121 |
+
# Layout adjustment: 5 columns
|
| 122 |
+
col1, col2, col3, col4, col5 = st.columns(5)
|
| 123 |
+
|
| 124 |
+
with col1:
|
| 125 |
+
# Edit button
|
| 126 |
+
edit_key = f"edit_{unique_key}_{sequence_number}"
|
| 127 |
+
if st.button(f"✏️ Edit", key=edit_key):
|
| 128 |
+
with open(file_path, "r") as f:
|
| 129 |
+
file_content = f.read()
|
| 130 |
+
text_area_key = f"text_area_{unique_key}_{sequence_number}"
|
| 131 |
+
file_content = st.text_area("Edit the file content:", value=file_content, height=250, key=text_area_key)
|
| 132 |
+
|
| 133 |
+
with col2:
|
| 134 |
+
# Save button
|
| 135 |
+
save_key = f"save_{unique_key}_{sequence_number}"
|
| 136 |
+
if st.button(f"💾 Save", key=save_key):
|
| 137 |
+
if file_content: # Ensure file_content is not empty
|
| 138 |
+
with open(file_path, "w") as f:
|
| 139 |
+
f.write(file_content)
|
| 140 |
+
st.success(f"File saved!")
|
| 141 |
+
|
| 142 |
+
with col3:
|
| 143 |
+
# Delete button
|
| 144 |
+
delete_key = f"delete_{unique_key}_{sequence_number}"
|
| 145 |
+
if st.button(f"🗑️ Delete", key=delete_key):
|
| 146 |
+
os.remove(file_path)
|
| 147 |
+
st.markdown(f"File deleted!")
|
| 148 |
+
|
| 149 |
+
with col4:
|
| 150 |
+
# Click to download link
|
| 151 |
+
st.markdown(get_download_link(file_path), unsafe_allow_html=True)
|
| 152 |
+
|
| 153 |
+
with col5:
|
| 154 |
+
# Filename
|
| 155 |
+
st.text(os.path.basename(file_path))
|
| 156 |
else:
|
| 157 |
st.write(f"File not found: {file}")
|
| 158 |
|
| 159 |
+
|
| 160 |
def get_download_link(file):
|
| 161 |
with open(file, "rb") as f:
|
| 162 |
bytes = f.read()
|