Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -48,15 +48,36 @@ def list_files(directory_path='.'):
|
|
| 48 |
files = [f for f in os.listdir(directory_path) if os.path.isfile(os.path.join(directory_path, f))]
|
| 49 |
return [f for f in files if f not in EXCLUDED_FILES]
|
| 50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
def show_download_links(subdir):
|
| 52 |
st.write(f'Files for {subdir}:')
|
| 53 |
for file in list_files(subdir):
|
| 54 |
file_path = os.path.join(subdir, file)
|
| 55 |
if os.path.isfile(file_path):
|
| 56 |
st.markdown(get_download_link(file_path), unsafe_allow_html=True)
|
|
|
|
| 57 |
else:
|
| 58 |
st.write(f"File not found: {file}")
|
| 59 |
|
|
|
|
| 60 |
def get_download_link(file):
|
| 61 |
with open(file, "rb") as f:
|
| 62 |
bytes = f.read()
|
|
|
|
| 48 |
files = [f for f in os.listdir(directory_path) if os.path.isfile(os.path.join(directory_path, f))]
|
| 49 |
return [f for f in files if f not in EXCLUDED_FILES]
|
| 50 |
|
| 51 |
+
|
| 52 |
+
def show_file_operations(file_path):
|
| 53 |
+
st.write(f"File: {os.path.basename(file_path)}")
|
| 54 |
+
|
| 55 |
+
# Edit button
|
| 56 |
+
if st.button(f"✏️ Edit {os.path.basename(file_path)}"):
|
| 57 |
+
with open(file_path, "r") as f:
|
| 58 |
+
file_content = f.read()
|
| 59 |
+
file_content = st.text_area("Edit the file content:", value=file_content, height=250)
|
| 60 |
+
if st.button(f"💾 Save {os.path.basename(file_path)}"):
|
| 61 |
+
with open(file_path, "w") as f:
|
| 62 |
+
f.write(file_content)
|
| 63 |
+
st.success(f"File {os.path.basename(file_path)} saved!")
|
| 64 |
+
|
| 65 |
+
# Delete button
|
| 66 |
+
if st.button(f"🗑️ Delete {os.path.basename(file_path)}"):
|
| 67 |
+
os.remove(file_path)
|
| 68 |
+
st.markdown(f"🎉 File {os.path.basename(file_path)} deleted!")
|
| 69 |
+
|
| 70 |
def show_download_links(subdir):
|
| 71 |
st.write(f'Files for {subdir}:')
|
| 72 |
for file in list_files(subdir):
|
| 73 |
file_path = os.path.join(subdir, file)
|
| 74 |
if os.path.isfile(file_path):
|
| 75 |
st.markdown(get_download_link(file_path), unsafe_allow_html=True)
|
| 76 |
+
show_file_operations(file_path)
|
| 77 |
else:
|
| 78 |
st.write(f"File not found: {file}")
|
| 79 |
|
| 80 |
+
|
| 81 |
def get_download_link(file):
|
| 82 |
with open(file, "rb") as f:
|
| 83 |
bytes = f.read()
|