awacke1 commited on
Commit
348291b
1 Parent(s): d56cde5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -1
app.py CHANGED
@@ -11,6 +11,8 @@ import requests
11
  import time
12
  import re
13
  import textract
 
 
14
 
15
  from datetime import datetime
16
  from openai import ChatCompletion
@@ -276,7 +278,31 @@ def process_user_input(user_question):
276
  create_file(filename, user_question, message.content)
277
 
278
  #st.sidebar.markdown(get_table_download_link(filename), unsafe_allow_html=True)
279
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
280
 
281
  def main():
282
  # Sidebar and global
@@ -295,6 +321,10 @@ def main():
295
  st.sidebar.markdown(get_table_download_link(filename), unsafe_allow_html=True)
296
  filename=None # since transcription is finished next time just use the saved transcript
297
 
 
 
 
 
298
  # prompt interfaces
299
  user_prompt = st.text_area("Enter prompts, instructions & questions:", '', height=100)
300
 
 
11
  import time
12
  import re
13
  import textract
14
+ import zipfile
15
+
16
 
17
  from datetime import datetime
18
  from openai import ChatCompletion
 
278
  create_file(filename, user_question, message.content)
279
 
280
  #st.sidebar.markdown(get_table_download_link(filename), unsafe_allow_html=True)
281
+
282
+ def create_zip_of_all_files():
283
+ # Get all files in the current directory
284
+ all_files = glob.glob("*.*")
285
+
286
+ # Name the zip file based on the current date and time
287
+ central = pytz.timezone('US/Central')
288
+ safe_date_time = datetime.now(central).strftime("%Y%m%d_%H%M%S")
289
+ zip_filename = f"all_files_{safe_date_time}.zip"
290
+
291
+ with zipfile.ZipFile(zip_filename, 'w') as zipf:
292
+ for file in all_files:
293
+ zipf.write(file)
294
+
295
+ return zip_filename
296
+
297
+ def get_zip_download_link(zip_filepath):
298
+ with open(zip_filepath, 'rb') as f:
299
+ data = f.read()
300
+
301
+ b64 = base64.b64encode(data).decode()
302
+ file_name = os.path.basename(zip_filepath)
303
+ href = f'<a href="data:application/zip;base64,{b64}" target="_blank" download="{file_name}">Download All Files</a>'
304
+ return href
305
+
306
 
307
  def main():
308
  # Sidebar and global
 
321
  st.sidebar.markdown(get_table_download_link(filename), unsafe_allow_html=True)
322
  filename=None # since transcription is finished next time just use the saved transcript
323
 
324
+ if st.sidebar.button("📦 Download All"):
325
+ zip_file_path = create_zip_of_all_files()
326
+ st.sidebar.markdown(get_zip_download_link(zip_file_path), unsafe_allow_html=True)
327
+
328
  # prompt interfaces
329
  user_prompt = st.text_area("Enter prompts, instructions & questions:", '', height=100)
330