Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -50,29 +50,41 @@ def list_files(directory_path='.'):
|
|
| 50 |
files = [f for f in os.listdir(directory_path) if os.path.isfile(os.path.join(directory_path, f))]
|
| 51 |
return [f for f in files if f not in EXCLUDED_FILES]
|
| 52 |
|
|
|
|
| 53 |
def show_file_operations(file_path):
|
| 54 |
st.write(f"File: {os.path.basename(file_path)}")
|
|
|
|
|
|
|
| 55 |
unique_key = hashlib.md5(file_path.encode()).hexdigest()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
col1, col2, col3 = st.columns(3)
|
| 57 |
|
| 58 |
with col1:
|
| 59 |
-
if st.button(f"✏️ Edit", key=f"edit_{unique_key}"):
|
| 60 |
-
file_content = ""
|
| 61 |
with open(file_path, "r") as f:
|
| 62 |
file_content = f.read()
|
| 63 |
-
file_content = st.text_area("Edit the file content:", value=file_content, height=250, key=f"text_area_{unique_key}")
|
| 64 |
|
| 65 |
with col2:
|
| 66 |
-
if st.button(f"💾 Save", key=f"save_{unique_key}"):
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
|
|
|
| 70 |
|
| 71 |
with col3:
|
| 72 |
-
if st.button(f"🗑️ Delete", key=f"delete_{unique_key}"):
|
| 73 |
os.remove(file_path)
|
| 74 |
st.markdown(f"File deleted!")
|
| 75 |
|
|
|
|
| 76 |
def show_download_links(subdir):
|
| 77 |
st.write(f'Files for {subdir}:')
|
| 78 |
for file in list_files(subdir):
|
|
|
|
| 50 |
files = [f for f in os.listdir(directory_path) if os.path.isfile(os.path.join(directory_path, f))]
|
| 51 |
return [f for f in files if f not in EXCLUDED_FILES]
|
| 52 |
|
| 53 |
+
|
| 54 |
def show_file_operations(file_path):
|
| 55 |
st.write(f"File: {os.path.basename(file_path)}")
|
| 56 |
+
|
| 57 |
+
# Generate a unique key for each file
|
| 58 |
unique_key = hashlib.md5(file_path.encode()).hexdigest()
|
| 59 |
+
|
| 60 |
+
# Additional unique identifier for each function call
|
| 61 |
+
unique_call_id = str(uuid.uuid4())
|
| 62 |
+
|
| 63 |
+
# Initialize file_content outside the button blocks
|
| 64 |
+
file_content = ""
|
| 65 |
+
|
| 66 |
+
# Create columns for Edit, Save, and Delete buttons
|
| 67 |
col1, col2, col3 = st.columns(3)
|
| 68 |
|
| 69 |
with col1:
|
| 70 |
+
if st.button(f"✏️ Edit", key=f"edit_{unique_key}_{unique_call_id}"):
|
|
|
|
| 71 |
with open(file_path, "r") as f:
|
| 72 |
file_content = f.read()
|
| 73 |
+
file_content = st.text_area("Edit the file content:", value=file_content, height=250, key=f"text_area_{unique_key}_{unique_call_id}")
|
| 74 |
|
| 75 |
with col2:
|
| 76 |
+
if st.button(f"💾 Save", key=f"save_{unique_key}_{unique_call_id}"):
|
| 77 |
+
if file_content: # Ensure file_content is not empty
|
| 78 |
+
with open(file_path, "w") as f:
|
| 79 |
+
f.write(file_content)
|
| 80 |
+
st.success(f"File saved!")
|
| 81 |
|
| 82 |
with col3:
|
| 83 |
+
if st.button(f"🗑️ Delete", key=f"delete_{unique_key}_{unique_call_id}"):
|
| 84 |
os.remove(file_path)
|
| 85 |
st.markdown(f"File deleted!")
|
| 86 |
|
| 87 |
+
|
| 88 |
def show_download_links(subdir):
|
| 89 |
st.write(f'Files for {subdir}:')
|
| 90 |
for file in list_files(subdir):
|