Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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
|
@@ -300,6 +302,28 @@ def divide_prompt(prompt, max_length):
|
|
300 |
current_length = len(word)
|
301 |
chunks.append(' '.join(current_chunk)) # Append the final chunk
|
302 |
return chunks
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
303 |
|
304 |
def main():
|
305 |
openai.api_key = os.getenv('OPENAI_API_KEY')
|
@@ -382,13 +406,18 @@ def main():
|
|
382 |
all_files = [file for file in all_files if len(os.path.splitext(file)[0]) >= 20] # exclude files with short names
|
383 |
all_files.sort(key=lambda x: (os.path.splitext(x)[1], x), reverse=True) # sort by file type and file name in descending order
|
384 |
|
385 |
-
# Sidebar of Files Saving History and surfacing files as context of prompts and responses
|
386 |
# Added "Delete All" button
|
387 |
if st.sidebar.button("๐ Delete All"):
|
388 |
for file in all_files:
|
389 |
os.remove(file)
|
390 |
st.experimental_rerun()
|
|
|
|
|
|
|
|
|
|
|
391 |
|
|
|
392 |
file_contents=''
|
393 |
next_action=''
|
394 |
for file in all_files:
|
|
|
11 |
import time
|
12 |
import re
|
13 |
import textract
|
14 |
+
import zipfile # New import for zipping files
|
15 |
+
|
16 |
|
17 |
from datetime import datetime
|
18 |
from openai import ChatCompletion
|
|
|
302 |
current_length = len(word)
|
303 |
chunks.append(' '.join(current_chunk)) # Append the final chunk
|
304 |
return chunks
|
305 |
+
|
306 |
+
def create_zip_of_files(files):
|
307 |
+
"""
|
308 |
+
Create a zip file from a list of files.
|
309 |
+
"""
|
310 |
+
zip_name = "all_files.zip"
|
311 |
+
with zipfile.ZipFile(zip_name, 'w') as zipf:
|
312 |
+
for file in files:
|
313 |
+
zipf.write(file)
|
314 |
+
return zip_name
|
315 |
+
|
316 |
+
|
317 |
+
def get_zip_download_link(zip_file):
|
318 |
+
"""
|
319 |
+
Generate a link to download the zip file.
|
320 |
+
"""
|
321 |
+
with open(zip_file, 'rb') as f:
|
322 |
+
data = f.read()
|
323 |
+
b64 = base64.b64encode(data).decode()
|
324 |
+
href = f'<a href="data:application/zip;base64,{b64}" download="{zip_file}">Download All</a>'
|
325 |
+
return href
|
326 |
+
|
327 |
|
328 |
def main():
|
329 |
openai.api_key = os.getenv('OPENAI_API_KEY')
|
|
|
406 |
all_files = [file for file in all_files if len(os.path.splitext(file)[0]) >= 20] # exclude files with short names
|
407 |
all_files.sort(key=lambda x: (os.path.splitext(x)[1], x), reverse=True) # sort by file type and file name in descending order
|
408 |
|
|
|
409 |
# Added "Delete All" button
|
410 |
if st.sidebar.button("๐ Delete All"):
|
411 |
for file in all_files:
|
412 |
os.remove(file)
|
413 |
st.experimental_rerun()
|
414 |
+
|
415 |
+
# Added "Download All" button
|
416 |
+
if st.sidebar.button("โฌ๏ธ Download All"):
|
417 |
+
zip_file = create_zip_of_files(all_files)
|
418 |
+
st.sidebar.markdown(get_zip_download_link(zip_file), unsafe_allow_html=True)
|
419 |
|
420 |
+
# Sidebar of Files Saving History and surfacing files as context of prompts and responses
|
421 |
file_contents=''
|
422 |
next_action=''
|
423 |
for file in all_files:
|