Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -16,7 +16,7 @@ ocr_model = PaddleOCR(use_textline_orientation=True, lang='en')
|
|
| 16 |
|
| 17 |
def analyze_uv_coverage(img, brightness_threshold=150, kernel_size=5, apply_blur=True, adaptive_thresh=False):
|
| 18 |
"""
|
| 19 |
-
Analyze UV sterilization coverage by
|
| 20 |
Optional adaptive thresholding and Gaussian blur for noise reduction.
|
| 21 |
Morphological operations clean the mask for better accuracy.
|
| 22 |
"""
|
|
@@ -84,28 +84,27 @@ def create_pdf_report(coverage_percent, extracted_texts, annotated_image_path, o
|
|
| 84 |
|
| 85 |
def upload_image_and_get_url(image_path):
|
| 86 |
"""
|
| 87 |
-
Upload the image to
|
| 88 |
-
Assumes the app is hosted in a Hugging Face Space with a public /uploads folder.
|
| 89 |
"""
|
| 90 |
import shutil
|
| 91 |
import os
|
| 92 |
from datetime import datetime
|
| 93 |
import uuid
|
| 94 |
|
| 95 |
-
# Define the
|
| 96 |
-
public_dir = os.path.join("
|
| 97 |
os.makedirs(public_dir, exist_ok=True) # Create directory if it doesn't exist
|
| 98 |
|
| 99 |
# Generate a unique filename to avoid conflicts
|
| 100 |
unique_filename = f"{uuid.uuid4().hex}_{datetime.utcnow().strftime('%Y%m%d_%H%M%S')}.jpg"
|
| 101 |
destination_path = os.path.join(public_dir, unique_filename)
|
| 102 |
|
| 103 |
-
# Copy the image to the
|
| 104 |
shutil.copy(image_path, destination_path)
|
| 105 |
|
| 106 |
-
# Construct the public URL
|
| 107 |
-
space_url = os.environ.get('HF_SPACE_URL', 'https://
|
| 108 |
-
public_url = f"{space_url}/uploads/{unique_filename}"
|
| 109 |
|
| 110 |
return public_url
|
| 111 |
|
|
|
|
| 16 |
|
| 17 |
def analyze_uv_coverage(img, brightness_threshold=150, kernel_size=5, apply_blur=True, adaptive_thresh=False):
|
| 18 |
"""
|
| 19 |
+
Analyze UV sterilization coverage by multiplexing the grayscale image.
|
| 20 |
Optional adaptive thresholding and Gaussian blur for noise reduction.
|
| 21 |
Morphological operations clean the mask for better accuracy.
|
| 22 |
"""
|
|
|
|
| 84 |
|
| 85 |
def upload_image_and_get_url(image_path):
|
| 86 |
"""
|
| 87 |
+
Upload the image to the uploads directory in Hugging Face Space and return a public URL.
|
|
|
|
| 88 |
"""
|
| 89 |
import shutil
|
| 90 |
import os
|
| 91 |
from datetime import datetime
|
| 92 |
import uuid
|
| 93 |
|
| 94 |
+
# Define the uploads directory in the Hugging Face Space
|
| 95 |
+
public_dir = os.path.join(os.getcwd(), "uploads") # Use current working directory + uploads
|
| 96 |
os.makedirs(public_dir, exist_ok=True) # Create directory if it doesn't exist
|
| 97 |
|
| 98 |
# Generate a unique filename to avoid conflicts
|
| 99 |
unique_filename = f"{uuid.uuid4().hex}_{datetime.utcnow().strftime('%Y%m%d_%H%M%S')}.jpg"
|
| 100 |
destination_path = os.path.join(public_dir, unique_filename)
|
| 101 |
|
| 102 |
+
# Copy the image to the uploads directory
|
| 103 |
shutil.copy(image_path, destination_path)
|
| 104 |
|
| 105 |
+
# Construct the public URL using the HF_SPACE_URL from .env
|
| 106 |
+
space_url = os.environ.get('HF_SPACE_URL', 'https://huggingface.co/spaces/pavansuresh/Smartlab_tech')
|
| 107 |
+
public_url = f"{space_url.rstrip('/')}/uploads/{unique_filename}"
|
| 108 |
|
| 109 |
return public_url
|
| 110 |
|