Spaces:
Sleeping
Sleeping
download img csv
Browse files
app.py
CHANGED
|
@@ -19,7 +19,7 @@ import pandas as pd
|
|
| 19 |
from itertools import zip_longest
|
| 20 |
import inspect
|
| 21 |
from threading import Lock
|
| 22 |
-
|
| 23 |
import warnings
|
| 24 |
|
| 25 |
# Ignore SourceChangeWarning
|
|
@@ -202,17 +202,29 @@ def create_csv():
|
|
| 202 |
def get_data():
|
| 203 |
return send_from_directory('inferenced','output.csv', as_attachment=False)
|
| 204 |
|
| 205 |
-
from flask import jsonify
|
| 206 |
|
| 207 |
@app.route('/download_csv', methods=['GET'])
|
| 208 |
def download_csv():
|
| 209 |
try:
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 214 |
else:
|
| 215 |
-
return jsonify({"error": "
|
| 216 |
except Exception as e:
|
| 217 |
return jsonify({"error": f"Download failed: {str(e)}"})
|
| 218 |
|
|
|
|
| 19 |
from itertools import zip_longest
|
| 20 |
import inspect
|
| 21 |
from threading import Lock
|
| 22 |
+
import zipfile
|
| 23 |
import warnings
|
| 24 |
|
| 25 |
# Ignore SourceChangeWarning
|
|
|
|
| 202 |
def get_data():
|
| 203 |
return send_from_directory('inferenced','output.csv', as_attachment=False)
|
| 204 |
|
|
|
|
| 205 |
|
| 206 |
@app.route('/download_csv', methods=['GET'])
|
| 207 |
def download_csv():
|
| 208 |
try:
|
| 209 |
+
folder_path = r"inferenced" # path to the folder
|
| 210 |
+
|
| 211 |
+
# Get a list of all files in the folder
|
| 212 |
+
files = [f for f in os.listdir(folder_path) if os.path.isfile(os.path.join(folder_path, f))]
|
| 213 |
+
|
| 214 |
+
# Check if there are any files in the folder
|
| 215 |
+
if files:
|
| 216 |
+
# Create a ZIP file containing all files
|
| 217 |
+
zip_filename = 'inferenced_files.zip'
|
| 218 |
+
zip_file_path = os.path.join(folder_path, zip_filename)
|
| 219 |
+
with zipfile.ZipFile(zip_file_path, 'w') as zipf:
|
| 220 |
+
for file in files:
|
| 221 |
+
file_path = os.path.join(folder_path, file)
|
| 222 |
+
zipf.write(file_path, os.path.basename(file_path))
|
| 223 |
+
|
| 224 |
+
# Send the ZIP file as an attachment
|
| 225 |
+
return send_file(zip_file_path, as_attachment=True, download_name=zip_filename)
|
| 226 |
else:
|
| 227 |
+
return jsonify({"error": "No files found in the folder"})
|
| 228 |
except Exception as e:
|
| 229 |
return jsonify({"error": f"Download failed: {str(e)}"})
|
| 230 |
|