Update app.py
Browse files
app.py
CHANGED
@@ -12,20 +12,17 @@ import zipfile
|
|
12 |
from PIL import Image
|
13 |
|
14 |
EXCLUDED_FILES = ['app.py', 'requirements.txt', 'pre-requirements.txt', 'packages.txt', 'README.md','.gitattributes', "backup.py","Dockerfile"]
|
15 |
-
# Emoji mapping for different file types
|
16 |
FILE_EMOJIS = {
|
17 |
".jpg": "πΌοΈ", ".jpeg": "πΌοΈ", ".png": "πΌοΈ",
|
18 |
".html": "π", ".htm": "π", ".txt": "π",
|
19 |
".pdf": "π", ".doc": "π", ".docx": "π",
|
20 |
".xls": "π", ".xlsx": "π", ".ppt": "π", ".pptx": "π",
|
21 |
-
# Add more mappings as needed
|
22 |
}
|
23 |
URLS = {
|
24 |
"Lumiere": "https://lumiere-video.github.io/",
|
25 |
"ChatDev": "https://github.com/OpenBMB/ChatDev",
|
26 |
"Autogen": "https://microsoft.github.io/autogen/",
|
27 |
"Mixtral": "https://github.com/open-compass/MixtralKit",
|
28 |
-
|
29 |
"World Health Organization": "https://www.who.int/",
|
30 |
"CMS - Centers for Medicare & Medicaid Services": "https://www.cms.gov/",
|
31 |
"Mayo Clinic": "https://www.mayoclinic.org/",
|
@@ -105,7 +102,6 @@ def download_html_and_files(url, subdir):
|
|
105 |
file.write(str(soup))
|
106 |
return file_urls
|
107 |
|
108 |
-
|
109 |
def list_files(directory_path='.'):
|
110 |
files = [f for f in os.listdir(directory_path) if os.path.isfile(os.path.join(directory_path, f))]
|
111 |
return [f for f in files if f not in EXCLUDED_FILES]
|
@@ -147,8 +143,6 @@ def show_file_operations(file_path, sequence_number):
|
|
147 |
os.remove(file_path)
|
148 |
st.markdown(f"File deleted!")
|
149 |
|
150 |
-
file_sequence_numbers = {}
|
151 |
-
|
152 |
def show_file_content(file_path, original_url):
|
153 |
_, file_extension = os.path.splitext(file_path)
|
154 |
emoji = FILE_EMOJIS.get(file_extension, "π") # Default emoji for unknown file types
|
@@ -167,6 +161,7 @@ def show_file_content(file_path, original_url):
|
|
167 |
except Exception as e:
|
168 |
st.error(f"Error reading file {file_path}: {e}")
|
169 |
|
|
|
170 |
def show_download_links(subdir):
|
171 |
global file_sequence_numbers
|
172 |
for file in list_files(subdir):
|
@@ -218,19 +213,14 @@ def main():
|
|
218 |
else:
|
219 |
selected_site = st.sidebar.selectbox("Select a Website", list(URLS.keys()), index=0)
|
220 |
url = URLS[selected_site]
|
221 |
-
|
222 |
-
# Reading or creating history.json
|
223 |
if not os.path.exists("history.json"):
|
224 |
with open("history.json", "w") as f:
|
225 |
json.dump({}, f)
|
226 |
-
|
227 |
with open("history.json", "r") as f:
|
228 |
try:
|
229 |
history = json.load(f)
|
230 |
except:
|
231 |
print('error')
|
232 |
-
|
233 |
-
# Handling URL submission
|
234 |
if url:
|
235 |
subdir = hashlib.md5(url.encode()).hexdigest()
|
236 |
if not os.path.exists(subdir):
|
@@ -264,11 +254,13 @@ def main():
|
|
264 |
st.write(f"Deleted: {file_path}")
|
265 |
os.rmdir(subdir) # Remove the empty directory
|
266 |
st.experimental_rerun()
|
|
|
267 |
if st.sidebar.button("β¬οΈ Download All", help="Download all files in a zip"):
|
268 |
start_directory = '.' # Current directory
|
269 |
for zip_file in zip_subdirs(start_directory):
|
270 |
st.sidebar.markdown(zip_file, unsafe_allow_html=True)
|
271 |
st.sidebar.markdown(get_zip_download_link(zip_file), unsafe_allow_html=True)
|
|
|
272 |
with st.expander("URL History and Downloaded Files"):
|
273 |
try:
|
274 |
for url, subdir in history.items():
|
|
|
12 |
from PIL import Image
|
13 |
|
14 |
EXCLUDED_FILES = ['app.py', 'requirements.txt', 'pre-requirements.txt', 'packages.txt', 'README.md','.gitattributes', "backup.py","Dockerfile"]
|
|
|
15 |
FILE_EMOJIS = {
|
16 |
".jpg": "πΌοΈ", ".jpeg": "πΌοΈ", ".png": "πΌοΈ",
|
17 |
".html": "π", ".htm": "π", ".txt": "π",
|
18 |
".pdf": "π", ".doc": "π", ".docx": "π",
|
19 |
".xls": "π", ".xlsx": "π", ".ppt": "π", ".pptx": "π",
|
|
|
20 |
}
|
21 |
URLS = {
|
22 |
"Lumiere": "https://lumiere-video.github.io/",
|
23 |
"ChatDev": "https://github.com/OpenBMB/ChatDev",
|
24 |
"Autogen": "https://microsoft.github.io/autogen/",
|
25 |
"Mixtral": "https://github.com/open-compass/MixtralKit",
|
|
|
26 |
"World Health Organization": "https://www.who.int/",
|
27 |
"CMS - Centers for Medicare & Medicaid Services": "https://www.cms.gov/",
|
28 |
"Mayo Clinic": "https://www.mayoclinic.org/",
|
|
|
102 |
file.write(str(soup))
|
103 |
return file_urls
|
104 |
|
|
|
105 |
def list_files(directory_path='.'):
|
106 |
files = [f for f in os.listdir(directory_path) if os.path.isfile(os.path.join(directory_path, f))]
|
107 |
return [f for f in files if f not in EXCLUDED_FILES]
|
|
|
143 |
os.remove(file_path)
|
144 |
st.markdown(f"File deleted!")
|
145 |
|
|
|
|
|
146 |
def show_file_content(file_path, original_url):
|
147 |
_, file_extension = os.path.splitext(file_path)
|
148 |
emoji = FILE_EMOJIS.get(file_extension, "π") # Default emoji for unknown file types
|
|
|
161 |
except Exception as e:
|
162 |
st.error(f"Error reading file {file_path}: {e}")
|
163 |
|
164 |
+
file_sequence_numbers = {}
|
165 |
def show_download_links(subdir):
|
166 |
global file_sequence_numbers
|
167 |
for file in list_files(subdir):
|
|
|
213 |
else:
|
214 |
selected_site = st.sidebar.selectbox("Select a Website", list(URLS.keys()), index=0)
|
215 |
url = URLS[selected_site]
|
|
|
|
|
216 |
if not os.path.exists("history.json"):
|
217 |
with open("history.json", "w") as f:
|
218 |
json.dump({}, f)
|
|
|
219 |
with open("history.json", "r") as f:
|
220 |
try:
|
221 |
history = json.load(f)
|
222 |
except:
|
223 |
print('error')
|
|
|
|
|
224 |
if url:
|
225 |
subdir = hashlib.md5(url.encode()).hexdigest()
|
226 |
if not os.path.exists(subdir):
|
|
|
254 |
st.write(f"Deleted: {file_path}")
|
255 |
os.rmdir(subdir) # Remove the empty directory
|
256 |
st.experimental_rerun()
|
257 |
+
|
258 |
if st.sidebar.button("β¬οΈ Download All", help="Download all files in a zip"):
|
259 |
start_directory = '.' # Current directory
|
260 |
for zip_file in zip_subdirs(start_directory):
|
261 |
st.sidebar.markdown(zip_file, unsafe_allow_html=True)
|
262 |
st.sidebar.markdown(get_zip_download_link(zip_file), unsafe_allow_html=True)
|
263 |
+
|
264 |
with st.expander("URL History and Downloaded Files"):
|
265 |
try:
|
266 |
for url, subdir in history.items():
|