Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -59,33 +59,33 @@ def list_files(directory_path='.'):
|
|
| 59 |
files = [f for f in os.listdir(directory_path) if os.path.isfile(os.path.join(directory_path, f))]
|
| 60 |
return [f for f in files if f not in EXCLUDED_FILES]
|
| 61 |
|
| 62 |
-
|
| 63 |
-
def show_file_operations(file_path):
|
| 64 |
st.write(f"File: {os.path.basename(file_path)}")
|
| 65 |
unique_key = hashlib.md5(file_path.encode()).hexdigest()
|
| 66 |
-
unique_call_id = str(uuid.uuid4()) # Use uuid module here
|
| 67 |
|
| 68 |
file_content = ""
|
| 69 |
|
| 70 |
col1, col2, col3 = st.columns(3)
|
| 71 |
|
| 72 |
with col1:
|
| 73 |
-
|
| 74 |
-
|
| 75 |
with open(file_path, "r") as f:
|
| 76 |
file_content = f.read()
|
| 77 |
-
|
| 78 |
-
|
| 79 |
|
| 80 |
with col2:
|
| 81 |
-
|
|
|
|
| 82 |
if file_content: # Ensure file_content is not empty
|
| 83 |
with open(file_path, "w") as f:
|
| 84 |
f.write(file_content)
|
| 85 |
st.success(f"File saved!")
|
| 86 |
|
| 87 |
with col3:
|
| 88 |
-
|
|
|
|
| 89 |
os.remove(file_path)
|
| 90 |
st.markdown(f"File deleted!")
|
| 91 |
|
|
|
|
| 59 |
files = [f for f in os.listdir(directory_path) if os.path.isfile(os.path.join(directory_path, f))]
|
| 60 |
return [f for f in files if f not in EXCLUDED_FILES]
|
| 61 |
|
| 62 |
+
def show_file_operations(file_path, sequence_number):
|
|
|
|
| 63 |
st.write(f"File: {os.path.basename(file_path)}")
|
| 64 |
unique_key = hashlib.md5(file_path.encode()).hexdigest()
|
|
|
|
| 65 |
|
| 66 |
file_content = ""
|
| 67 |
|
| 68 |
col1, col2, col3 = st.columns(3)
|
| 69 |
|
| 70 |
with col1:
|
| 71 |
+
edit_key = f"edit_{unique_key}_{sequence_number}"
|
| 72 |
+
if st.button(f"✏️ Edit", key=edit_key):
|
| 73 |
with open(file_path, "r") as f:
|
| 74 |
file_content = f.read()
|
| 75 |
+
text_area_key = f"text_area_{unique_key}_{sequence_number}"
|
| 76 |
+
file_content = st.text_area("Edit the file content:", value=file_content, height=250, key=text_area_key)
|
| 77 |
|
| 78 |
with col2:
|
| 79 |
+
save_key = f"save_{unique_key}_{sequence_number}"
|
| 80 |
+
if st.button(f"💾 Save", key=save_key):
|
| 81 |
if file_content: # Ensure file_content is not empty
|
| 82 |
with open(file_path, "w") as f:
|
| 83 |
f.write(file_content)
|
| 84 |
st.success(f"File saved!")
|
| 85 |
|
| 86 |
with col3:
|
| 87 |
+
delete_key = f"delete_{unique_key}_{sequence_number}"
|
| 88 |
+
if st.button(f"🗑️ Delete", key=delete_key):
|
| 89 |
os.remove(file_path)
|
| 90 |
st.markdown(f"File deleted!")
|
| 91 |
|