Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -27,6 +27,25 @@ if not os.path.exists("history.json"):
|
|
| 27 |
with open("history.json", "w") as f:
|
| 28 |
json.dump({}, f)
|
| 29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
def download_file(url, local_filename):
|
| 31 |
if url.startswith('http://') or url.startswith('https://'):
|
| 32 |
try:
|
|
@@ -182,6 +201,18 @@ def main():
|
|
| 182 |
for subdir in history.values():
|
| 183 |
show_download_links(subdir)
|
| 184 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 185 |
# Expander for showing URL history and download links
|
| 186 |
with st.expander("URL History and Downloaded Files"):
|
| 187 |
try:
|
|
|
|
| 27 |
with open("history.json", "w") as f:
|
| 28 |
json.dump({}, f)
|
| 29 |
|
| 30 |
+
|
| 31 |
+
@st.cache_resource
|
| 32 |
+
def create_zip_of_files(files):
|
| 33 |
+
zip_name = "all_files.zip"
|
| 34 |
+
with zipfile.ZipFile(zip_name, 'w') as zipf:
|
| 35 |
+
for file in files:
|
| 36 |
+
zipf.write(file)
|
| 37 |
+
return zip_name
|
| 38 |
+
|
| 39 |
+
@st.cache_resource
|
| 40 |
+
def get_zip_download_link(zip_file):
|
| 41 |
+
with open(zip_file, 'rb') as f:
|
| 42 |
+
data = f.read()
|
| 43 |
+
b64 = base64.b64encode(data).decode()
|
| 44 |
+
href = f'<a href="data:application/zip;base64,{b64}" download="{zip_file}">Download All</a>'
|
| 45 |
+
return href
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
|
| 49 |
def download_file(url, local_filename):
|
| 50 |
if url.startswith('http://') or url.startswith('https://'):
|
| 51 |
try:
|
|
|
|
| 201 |
for subdir in history.values():
|
| 202 |
show_download_links(subdir)
|
| 203 |
|
| 204 |
+
if st.sidebar.button("🗑 Delete All"):
|
| 205 |
+
for file in all_files:
|
| 206 |
+
os.remove(file)
|
| 207 |
+
st.experimental_rerun()
|
| 208 |
+
|
| 209 |
+
if st.sidebar.button("⬇️ Download All"):
|
| 210 |
+
zip_file = create_zip_of_files(all_files)
|
| 211 |
+
st.sidebar.markdown(get_zip_download_link(zip_file), unsafe_allow_html=True)
|
| 212 |
+
file_contents=''
|
| 213 |
+
next_action=''
|
| 214 |
+
|
| 215 |
+
|
| 216 |
# Expander for showing URL history and download links
|
| 217 |
with st.expander("URL History and Downloaded Files"):
|
| 218 |
try:
|