Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
|
@@ -5,9 +5,8 @@ from PIL import Image
|
|
| 5 |
from fastapi import FastAPI, HTTPException
|
| 6 |
from fastapi.responses import JSONResponse
|
| 7 |
from io import BytesIO
|
| 8 |
-
from src.modules import FeatureExtractor
|
| 9 |
from fastapi.middleware.cors import CORSMiddleware
|
| 10 |
-
import zipfile
|
| 11 |
from pydantic import BaseModel, Field
|
| 12 |
import json
|
| 13 |
from dotenv import load_dotenv
|
|
@@ -83,6 +82,7 @@ def image_to_base64(image: Image.Image) -> str:
|
|
| 83 |
def extract_zip_file(zip_file_path, destination_folder):
|
| 84 |
"""
|
| 85 |
Extract a zip file to a destination folder
|
|
|
|
| 86 |
|
| 87 |
Args:
|
| 88 |
zip_file_path: str, path to the zip file
|
|
@@ -94,11 +94,16 @@ def extract_zip_file(zip_file_path, destination_folder):
|
|
| 94 |
import zipfile
|
| 95 |
import os
|
| 96 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
# Check if zip file exists
|
| 98 |
if not os.path.exists(zip_file_path):
|
| 99 |
raise FileNotFoundError(f"Zip file not found: {zip_file_path}")
|
| 100 |
|
| 101 |
-
# Create destination folder
|
| 102 |
os.makedirs(destination_folder, exist_ok=True)
|
| 103 |
|
| 104 |
# Extract the zip file
|
|
|
|
| 5 |
from fastapi import FastAPI, HTTPException
|
| 6 |
from fastapi.responses import JSONResponse
|
| 7 |
from io import BytesIO
|
| 8 |
+
from src.modules.feature_extractor import FeatureExtractor
|
| 9 |
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
| 10 |
from pydantic import BaseModel, Field
|
| 11 |
import json
|
| 12 |
from dotenv import load_dotenv
|
|
|
|
| 82 |
def extract_zip_file(zip_file_path, destination_folder):
|
| 83 |
"""
|
| 84 |
Extract a zip file to a destination folder
|
| 85 |
+
If destination folder already exists, extraction is skipped
|
| 86 |
|
| 87 |
Args:
|
| 88 |
zip_file_path: str, path to the zip file
|
|
|
|
| 94 |
import zipfile
|
| 95 |
import os
|
| 96 |
|
| 97 |
+
# Check if destination folder already exists
|
| 98 |
+
if os.path.exists(destination_folder):
|
| 99 |
+
print(f"Destination folder {destination_folder} already exists. Skipping extraction.")
|
| 100 |
+
return
|
| 101 |
+
|
| 102 |
# Check if zip file exists
|
| 103 |
if not os.path.exists(zip_file_path):
|
| 104 |
raise FileNotFoundError(f"Zip file not found: {zip_file_path}")
|
| 105 |
|
| 106 |
+
# Create destination folder
|
| 107 |
os.makedirs(destination_folder, exist_ok=True)
|
| 108 |
|
| 109 |
# Extract the zip file
|