awacke1 commited on
Commit
8ba2ed0
β€’
1 Parent(s): 1ed84e9

Update backup-1-app.py

Browse files
Files changed (1) hide show
  1. backup-1-app.py +59 -0
backup-1-app.py CHANGED
@@ -9,6 +9,7 @@ import json
9
  import uuid
10
  import glob
11
  import zipfile
 
12
 
13
  EXCLUDED_FILES = ['app.py', 'requirements.txt', 'pre-requirements.txt', 'packages.txt', 'README.md','.gitattributes', "backup.py","Dockerfile"]
14
  URLS = {
@@ -157,6 +158,22 @@ def show_file_operations(file_path, sequence_number):
157
  file_sequence_numbers = {}
158
 
159
  def show_download_links(subdir):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
160
  global file_sequence_numbers
161
  for file in list_files(subdir):
162
  file_path = os.path.join(subdir, file)
@@ -179,6 +196,48 @@ def get_download_link(file):
179
  b64 = base64.b64encode(bytes).decode()
180
  href = f'<a href="data:file/octet-stream;base64,{b64}" download=\'{os.path.basename(file)}\'>Download: {os.path.basename(file)}</a>'
181
  return href
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
182
 
183
  def main():
184
  st.sidebar.title('🌐 Web Datasets Bulk Downloader')
 
9
  import uuid
10
  import glob
11
  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
  URLS = {
 
158
  file_sequence_numbers = {}
159
 
160
  def show_download_links(subdir):
161
+ global file_sequence_numbers
162
+ for file in list_files(subdir):
163
+ file_path = os.path.join(subdir, file)
164
+ if file_path not in file_sequence_numbers:
165
+ file_sequence_numbers[file_path] = 1
166
+ else:
167
+ file_sequence_numbers[file_path] += 1
168
+ sequence_number = file_sequence_numbers[file_path]
169
+
170
+ if os.path.isfile(file_path):
171
+ st.markdown(file_path) # Display file path
172
+ show_file_content(file_path) # Display file content based on type
173
+ else:
174
+ st.write(f"File not found: {file}")
175
+
176
+ def show_download_links_backup(subdir):
177
  global file_sequence_numbers
178
  for file in list_files(subdir):
179
  file_path = os.path.join(subdir, file)
 
196
  b64 = base64.b64encode(bytes).decode()
197
  href = f'<a href="data:file/octet-stream;base64,{b64}" download=\'{os.path.basename(file)}\'>Download: {os.path.basename(file)}</a>'
198
  return href
199
+
200
+ def show_file_content(file_path):
201
+ _, file_extension = os.path.splitext(file_path)
202
+ try:
203
+
204
+ if file_extension in ['.png', '.jpg', '.jpeg']:
205
+ image_url = file_path.replace('File:','')
206
+ st.write('Image URL:' + image_url)
207
+ # Check if the base_url needs to be prepended
208
+ #if base_url and not file_path.startswith(("http://", "https://")):
209
+ #image_url = os.path.join(base_url, file_path)
210
+
211
+ # Create a Markdown link to view the image
212
+ markdown_link = f"[![Image]({image_url})]({image_url})" #file_path
213
+ st.markdown(markdown_link, unsafe_allow_html=True)
214
+
215
+ #if file_extension in ['.png', '.jpg', '.jpeg']:
216
+ # with open(file_path, "rb") as file:
217
+ # img = Image.open(file)
218
+ # st.image(img, caption=os.path.basename(file_path))
219
+ #if file_extension in ['.png', '.jpg', '.jpeg']:
220
+ # st.image(file_path)
221
+ elif file_extension in ['.md', '.markdown']:
222
+ with open(file_path, "r") as file:
223
+ content = file.read()
224
+ edited_content = st.text_area(f"Edit {os.path.basename(file_path)}", value=content, height=250)
225
+ if st.button(f"Save {os.path.basename(file_path)}"):
226
+ with open(file_path, "w") as file:
227
+ file.write(edited_content)
228
+ st.success(f"Saved {os.path.basename(file_path)}!")
229
+ elif file_extension in ['.html', '.txt']:
230
+ with open(file_path, "r") as file:
231
+ st.markdown(file.read(), unsafe_allow_html=True)
232
+ elif file_extension in ['.pdf']:
233
+ pdf_file = open(file_path, "rb")
234
+ base64_pdf = base64.b64encode(pdf_file.read()).decode('utf-8')
235
+ pdf_display = f'<iframe src="data:application/pdf;base64,{base64_pdf}" width="700" height="1000" type="application/pdf"></iframe>'
236
+ st.markdown(pdf_display, unsafe_allow_html=True)
237
+ except Exception as e:
238
+ st.error(f"Error reading file {file_path}: {e}")
239
+
240
+
241
 
242
  def main():
243
  st.sidebar.title('🌐 Web Datasets Bulk Downloader')