Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -48,25 +48,6 @@ 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 |
-
|
| 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):
|
|
@@ -82,9 +63,31 @@ def get_download_link(file):
|
|
| 82 |
with open(file, "rb") as f:
|
| 83 |
bytes = f.read()
|
| 84 |
b64 = base64.b64encode(bytes).decode()
|
| 85 |
-
href = f'<a href="data:file/octet-stream;base64,{b64}" download=\'{os.path.basename(file)}\'>
|
| 86 |
return href
|
| 87 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
|
| 89 |
def main():
|
| 90 |
st.sidebar.title('Web Datasets Bulk Downloader')
|
|
|
|
| 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):
|
|
|
|
| 63 |
with open(file, "rb") as f:
|
| 64 |
bytes = f.read()
|
| 65 |
b64 = base64.b64encode(bytes).decode()
|
| 66 |
+
href = f'<a href="data:file/octet-stream;base64,{b64}" download=\'{os.path.basename(file)}\'>download the latest revision</a>'
|
| 67 |
return href
|
| 68 |
|
| 69 |
+
def show_file_operations(file_path):
|
| 70 |
+
st.write(f"File: {os.path.basename(file_path)}")
|
| 71 |
+
|
| 72 |
+
# Edit button and text area for file content
|
| 73 |
+
if st.button(f"✏️ Edit {os.path.basename(file_path)}"):
|
| 74 |
+
with open(file_path, "r") as f:
|
| 75 |
+
file_content = f.read()
|
| 76 |
+
file_content = st.text_area("Edit the file content:", value=file_content, height=250)
|
| 77 |
+
|
| 78 |
+
# Save button
|
| 79 |
+
if st.button(f"💾 Save {os.path.basename(file_path)}"):
|
| 80 |
+
with open(file_path, "w") as f:
|
| 81 |
+
f.write(file_content)
|
| 82 |
+
new_file_size = os.path.getsize(file_path)
|
| 83 |
+
download_link = get_download_link(file_path)
|
| 84 |
+
st.markdown(f"✅ File **{os.path.basename(file_path)}** saved! ([{download_link}]) - New size: {new_file_size} bytes", unsafe_allow_html=True)
|
| 85 |
+
|
| 86 |
+
# Delete button
|
| 87 |
+
if st.button(f"🗑️ Delete {os.path.basename(file_path)}"):
|
| 88 |
+
os.remove(file_path)
|
| 89 |
+
st.markdown(f"🎉 File {os.path.basename(file_path)} deleted!")
|
| 90 |
+
|
| 91 |
|
| 92 |
def main():
|
| 93 |
st.sidebar.title('Web Datasets Bulk Downloader')
|