Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,6 +6,7 @@ import base64
|
|
| 6 |
from bs4 import BeautifulSoup
|
| 7 |
import hashlib
|
| 8 |
import json
|
|
|
|
| 9 |
|
| 10 |
EXCLUDED_FILES = ['app.py', 'requirements.txt', 'pre-requirements.txt', 'packages.txt', 'README.md','.gitattributes', "backup.py","Dockerfile"]
|
| 11 |
URLS = {
|
|
@@ -52,27 +53,35 @@ def list_files(directory_path='.'):
|
|
| 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 |
with open(file_path, "w") as f:
|
| 68 |
f.write(file_content)
|
| 69 |
st.success(f"File saved!")
|
| 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):
|
|
|
|
| 6 |
from bs4 import BeautifulSoup
|
| 7 |
import hashlib
|
| 8 |
import json
|
| 9 |
+
import uuid
|
| 10 |
|
| 11 |
EXCLUDED_FILES = ['app.py', 'requirements.txt', 'pre-requirements.txt', 'packages.txt', 'README.md','.gitattributes', "backup.py","Dockerfile"]
|
| 12 |
URLS = {
|
|
|
|
| 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 |
+
# Create columns for Edit, Save, and Delete buttons
|
| 64 |
col1, col2, col3 = st.columns(3)
|
| 65 |
|
| 66 |
with col1:
|
| 67 |
+
if st.button(f"✏️ Edit", key=f"edit_{unique_key}_{unique_call_id}"):
|
| 68 |
file_content = ""
|
| 69 |
with open(file_path, "r") as f:
|
| 70 |
file_content = f.read()
|
| 71 |
+
file_content = st.text_area("Edit the file content:", value=file_content, height=250, key=f"text_area_{unique_key}_{unique_call_id}")
|
| 72 |
|
| 73 |
with col2:
|
| 74 |
+
if st.button(f"💾 Save", key=f"save_{unique_key}_{unique_call_id}"):
|
| 75 |
with open(file_path, "w") as f:
|
| 76 |
f.write(file_content)
|
| 77 |
st.success(f"File saved!")
|
| 78 |
|
| 79 |
with col3:
|
| 80 |
+
if st.button(f"🗑️ Delete", key=f"delete_{unique_key}_{unique_call_id}"):
|
| 81 |
os.remove(file_path)
|
| 82 |
st.markdown(f"File deleted!")
|
| 83 |
|
| 84 |
+
|
| 85 |
def show_download_links(subdir):
|
| 86 |
st.write(f'Files for {subdir}:')
|
| 87 |
for file in list_files(subdir):
|