Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,12 +3,10 @@ import requests
|
|
| 3 |
import os
|
| 4 |
import urllib
|
| 5 |
import base64
|
| 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 = {
|
| 13 |
"Chordify - Play Along Chords": "https://chordify.net/",
|
| 14 |
"National Guitar Academy - Guitar Learning": "https://www.guitaracademy.com/",
|
|
@@ -73,17 +71,13 @@ def file_editor(file_path):
|
|
| 73 |
f.write(file_content)
|
| 74 |
st.success(f"File '{os.path.basename(file_path)}' saved!")
|
| 75 |
|
| 76 |
-
|
| 77 |
def show_file_operations(file_path, sequence_number):
|
| 78 |
-
#st.write(f"File: {os.path.basename(file_path)}")
|
| 79 |
unique_key = hashlib.md5(file_path.encode()).hexdigest()
|
| 80 |
file_content = ""
|
| 81 |
|
| 82 |
col01, col02, col1, col2, col3 = st.columns(5)
|
| 83 |
with col01:
|
| 84 |
st.write(os.path.basename(file_path))
|
| 85 |
-
#with col02:
|
| 86 |
-
#st.write(file_path)
|
| 87 |
with col1:
|
| 88 |
edit_key = f"edit_{unique_key}_{sequence_number}"
|
| 89 |
if st.button(f"✏️ Edit", key=edit_key):
|
|
@@ -94,7 +88,7 @@ def show_file_operations(file_path, sequence_number):
|
|
| 94 |
|
| 95 |
with col2:
|
| 96 |
save_key = f"save_{unique_key}_{sequence_number}"
|
| 97 |
-
if st.button(f"💾 Save", key=save_key):
|
| 98 |
if file_content: # Ensure file_content is not empty
|
| 99 |
with open(file_path, "w") as f:
|
| 100 |
f.write(file_content)
|
|
@@ -106,7 +100,6 @@ def show_file_operations(file_path, sequence_number):
|
|
| 106 |
os.remove(file_path)
|
| 107 |
st.markdown(f"File deleted!")
|
| 108 |
|
| 109 |
-
|
| 110 |
file_sequence_numbers = {}
|
| 111 |
|
| 112 |
def show_download_links(subdir):
|
|
@@ -131,18 +124,16 @@ def get_download_link(file):
|
|
| 131 |
b64 = base64.b64encode(bytes).decode()
|
| 132 |
href = f'<a href="data:file/octet-stream;base64,{b64}" download=\'{os.path.basename(file)}\'>Download: {os.path.basename(file)}</a>'
|
| 133 |
return href
|
| 134 |
-
|
| 135 |
def main():
|
| 136 |
st.sidebar.title('Web Datasets Bulk Downloader')
|
| 137 |
|
| 138 |
-
# Check for query parameters for file editing
|
| 139 |
query_params = st.experimental_get_query_params()
|
| 140 |
file_to_edit = query_params.get('file_to_edit', [None])[0]
|
| 141 |
|
| 142 |
if file_to_edit and os.path.exists(file_to_edit):
|
| 143 |
file_editor(file_to_edit)
|
| 144 |
else:
|
| 145 |
-
# Selecting URL input method
|
| 146 |
url_input_method = st.sidebar.radio("Choose URL Input Method", ["Enter URL", "Select from List"])
|
| 147 |
url = ""
|
| 148 |
if url_input_method == "Enter URL":
|
|
@@ -151,7 +142,6 @@ def main():
|
|
| 151 |
selected_site = st.sidebar.selectbox("Select a Website", list(URLS.keys()))
|
| 152 |
url = URLS[selected_site]
|
| 153 |
|
| 154 |
-
# Reading or creating history.json
|
| 155 |
if not os.path.exists("history.json"):
|
| 156 |
with open("history.json", "w") as f:
|
| 157 |
json.dump({}, f)
|
|
@@ -159,10 +149,10 @@ def main():
|
|
| 159 |
with open("history.json", "r") as f:
|
| 160 |
try:
|
| 161 |
history = json.load(f)
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
if url:
|
| 167 |
subdir = hashlib.md5(url.encode()).hexdigest()
|
| 168 |
if not os.path.exists(subdir):
|
|
@@ -172,26 +162,24 @@ def main():
|
|
| 172 |
with open("history.json", "w") as f:
|
| 173 |
json.dump(history, f)
|
| 174 |
|
| 175 |
-
# Button for downloading content
|
| 176 |
if st.sidebar.button('📥 Get All the Content'):
|
| 177 |
download_html_and_files(url, history[url])
|
| 178 |
show_download_links(history[url])
|
| 179 |
|
| 180 |
-
# Button for showing download links
|
| 181 |
if st.sidebar.button('📂 Show Download Links'):
|
| 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:
|
| 188 |
for url, subdir in history.items():
|
| 189 |
st.markdown(f"#### {url}")
|
| 190 |
show_download_links(subdir)
|
| 191 |
-
except:
|
| 192 |
-
print('
|
| 193 |
-
|
| 194 |
for subdir in history.values():
|
| 195 |
show_download_links(subdir)
|
|
|
|
| 196 |
if __name__ == "__main__":
|
| 197 |
main()
|
|
|
|
| 3 |
import os
|
| 4 |
import urllib
|
| 5 |
import base64
|
|
|
|
| 6 |
import hashlib
|
| 7 |
import json
|
|
|
|
| 8 |
|
| 9 |
+
EXCLUDED_FILES = ['app.py', 'requirements.txt', 'pre-requirements.txt', 'packages.txt', 'README.md', '.gitattributes', "backup.py", "Dockerfile"]
|
| 10 |
URLS = {
|
| 11 |
"Chordify - Play Along Chords": "https://chordify.net/",
|
| 12 |
"National Guitar Academy - Guitar Learning": "https://www.guitaracademy.com/",
|
|
|
|
| 71 |
f.write(file_content)
|
| 72 |
st.success(f"File '{os.path.basename(file_path)}' saved!")
|
| 73 |
|
|
|
|
| 74 |
def show_file_operations(file_path, sequence_number):
|
|
|
|
| 75 |
unique_key = hashlib.md5(file_path.encode()).hexdigest()
|
| 76 |
file_content = ""
|
| 77 |
|
| 78 |
col01, col02, col1, col2, col3 = st.columns(5)
|
| 79 |
with col01:
|
| 80 |
st.write(os.path.basename(file_path))
|
|
|
|
|
|
|
| 81 |
with col1:
|
| 82 |
edit_key = f"edit_{unique_key}_{sequence_number}"
|
| 83 |
if st.button(f"✏️ Edit", key=edit_key):
|
|
|
|
| 88 |
|
| 89 |
with col2:
|
| 90 |
save_key = f"save_{unique_key}_{sequence_number}"
|
| 91 |
+
if st.button(f"💾 Save", key=save_key ):
|
| 92 |
if file_content: # Ensure file_content is not empty
|
| 93 |
with open(file_path, "w") as f:
|
| 94 |
f.write(file_content)
|
|
|
|
| 100 |
os.remove(file_path)
|
| 101 |
st.markdown(f"File deleted!")
|
| 102 |
|
|
|
|
| 103 |
file_sequence_numbers = {}
|
| 104 |
|
| 105 |
def show_download_links(subdir):
|
|
|
|
| 124 |
b64 = base64.b64encode(bytes).decode()
|
| 125 |
href = f'<a href="data:file/octet-stream;base64,{b64}" download=\'{os.path.basename(file)}\'>Download: {os.path.basename(file)}</a>'
|
| 126 |
return href
|
| 127 |
+
|
| 128 |
def main():
|
| 129 |
st.sidebar.title('Web Datasets Bulk Downloader')
|
| 130 |
|
|
|
|
| 131 |
query_params = st.experimental_get_query_params()
|
| 132 |
file_to_edit = query_params.get('file_to_edit', [None])[0]
|
| 133 |
|
| 134 |
if file_to_edit and os.path.exists(file_to_edit):
|
| 135 |
file_editor(file_to_edit)
|
| 136 |
else:
|
|
|
|
| 137 |
url_input_method = st.sidebar.radio("Choose URL Input Method", ["Enter URL", "Select from List"])
|
| 138 |
url = ""
|
| 139 |
if url_input_method == "Enter URL":
|
|
|
|
| 142 |
selected_site = st.sidebar.selectbox("Select a Website", list(URLS.keys()))
|
| 143 |
url = URLS[selected_site]
|
| 144 |
|
|
|
|
| 145 |
if not os.path.exists("history.json"):
|
| 146 |
with open("history.json", "w") as f:
|
| 147 |
json.dump({}, f)
|
|
|
|
| 149 |
with open("history.json", "r") as f:
|
| 150 |
try:
|
| 151 |
history = json.load(f)
|
| 152 |
+
print("History loaded:", history) # Debugging line
|
| 153 |
+
except Exception as e:
|
| 154 |
+
print('Error loading history:', e)
|
| 155 |
+
|
| 156 |
if url:
|
| 157 |
subdir = hashlib.md5(url.encode()).hexdigest()
|
| 158 |
if not os.path.exists(subdir):
|
|
|
|
| 162 |
with open("history.json", "w") as f:
|
| 163 |
json.dump(history, f)
|
| 164 |
|
|
|
|
| 165 |
if st.sidebar.button('📥 Get All the Content'):
|
| 166 |
download_html_and_files(url, history[url])
|
| 167 |
show_download_links(history[url])
|
| 168 |
|
|
|
|
| 169 |
if st.sidebar.button('📂 Show Download Links'):
|
| 170 |
for subdir in history.values():
|
| 171 |
show_download_links(subdir)
|
| 172 |
|
|
|
|
| 173 |
with st.expander("URL History and Downloaded Files"):
|
| 174 |
try:
|
| 175 |
for url, subdir in history.items():
|
| 176 |
st.markdown(f"#### {url}")
|
| 177 |
show_download_links(subdir)
|
| 178 |
+
except Exception as e:
|
| 179 |
+
print('Error displaying history:', e)
|
| 180 |
+
|
| 181 |
for subdir in history.values():
|
| 182 |
show_download_links(subdir)
|
| 183 |
+
|
| 184 |
if __name__ == "__main__":
|
| 185 |
main()
|