awacke1 commited on
Commit
fbdb4ed
β€’
1 Parent(s): b517657

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -0
app.py CHANGED
@@ -157,6 +157,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 +195,28 @@ 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')
 
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)
163
+ if file_path not in file_sequence_numbers:
164
+ file_sequence_numbers[file_path] = 1
165
+ else:
166
+ file_sequence_numbers[file_path] += 1
167
+ sequence_number = file_sequence_numbers[file_path]
168
+
169
+ if os.path.isfile(file_path):
170
+ st.markdown(file_path) # Display file path
171
+ show_file_content(file_path) # Display file content based on type
172
+ else:
173
+ st.write(f"File not found: {file}")
174
+
175
+ def show_download_links_backup(subdir):
176
  global file_sequence_numbers
177
  for file in list_files(subdir):
178
  file_path = os.path.join(subdir, file)
 
195
  b64 = base64.b64encode(bytes).decode()
196
  href = f'<a href="data:file/octet-stream;base64,{b64}" download=\'{os.path.basename(file)}\'>Download: {os.path.basename(file)}</a>'
197
  return href
198
+
199
+
200
+ def show_file_content(file_path):
201
+ _, file_extension = os.path.splitext(file_path)
202
+ try:
203
+ if file_extension in ['.png', '.jpg', '.jpeg']:
204
+ st.image(file_path)
205
+ elif file_extension in ['.md', '.markdown']:
206
+ with open(file_path, "r") as file:
207
+ content = file.read()
208
+ edited_content = st.text_area(f"Edit {os.path.basename(file_path)}", value=content, height=250)
209
+ if st.button(f"Save {os.path.basename(file_path)}"):
210
+ with open(file_path, "w") as file:
211
+ file.write(edited_content)
212
+ st.success(f"Saved {os.path.basename(file_path)}!")
213
+ elif file_extension in ['.html', '.txt']:
214
+ with open(file_path, "r") as file:
215
+ st.markdown(file.read(), unsafe_allow_html=True)
216
+ except Exception as e:
217
+ st.error(f"Error reading file {file_path}: {e}")
218
+
219
+
220
 
221
  def main():
222
  st.sidebar.title('🌐 Web Datasets Bulk Downloader')