Spaces:
Sleeping
Sleeping
done
Browse files
app.py
CHANGED
@@ -2,6 +2,7 @@ from fastapi import FastAPI, File, UploadFile, Response, HTTPException
|
|
2 |
from fastapi.responses import JSONResponse, FileResponse, StreamingResponse
|
3 |
from fastapi.middleware.cors import CORSMiddleware
|
4 |
from PIL import Image
|
|
|
5 |
import io
|
6 |
from io import BytesIO
|
7 |
import requests
|
@@ -287,22 +288,25 @@ async def generate_excel(predictions: List[Prediction]):
|
|
287 |
# sheet.add_image(img, img_cell)
|
288 |
|
289 |
|
290 |
-
#
|
291 |
-
|
|
|
|
|
|
|
292 |
workbook.save(excel_file_path)
|
293 |
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
else:
|
305 |
-
|
306 |
|
307 |
|
308 |
'''
|
|
|
2 |
from fastapi.responses import JSONResponse, FileResponse, StreamingResponse
|
3 |
from fastapi.middleware.cors import CORSMiddleware
|
4 |
from PIL import Image
|
5 |
+
from datetime import datetime
|
6 |
import io
|
7 |
from io import BytesIO
|
8 |
import requests
|
|
|
288 |
# sheet.add_image(img, img_cell)
|
289 |
|
290 |
|
291 |
+
# Create a unique filename based on the current timestamp or index
|
292 |
+
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
293 |
+
excel_file_path = f"/predictions_with_images_{timestamp}.xlsx"
|
294 |
+
|
295 |
+
# Save the Excel file to the specified path
|
296 |
workbook.save(excel_file_path)
|
297 |
|
298 |
+
# Check if the directory exists, if not, create it (to store multiple files)
|
299 |
+
if not os.path.exists("/predictions"):
|
300 |
+
os.makedirs("/predictions")
|
301 |
+
|
302 |
+
# Move the file to a new directory
|
303 |
+
os.rename(excel_file_path, f"/predictions/{os.path.basename(excel_file_path)}")
|
304 |
+
hf_path = "https://huggingface.co/spaces/root-sajjan/whatisit/resolve/main"
|
305 |
+
excel_file_path = hf_path + f"/predictions/{os.path.basename(excel_file_path)}"+"?download=True"
|
306 |
+
|
307 |
+
return JSONResponse(content={"download_link": excel_file_path})
|
308 |
+
# else:
|
309 |
+
# return JSONResponse(status_code=500, content={"error": "File upload failed"})
|
310 |
|
311 |
|
312 |
'''
|