Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,10 +10,36 @@ from simple_salesforce import Salesforce
|
|
| 10 |
from datetime import datetime
|
| 11 |
import base64
|
| 12 |
import io
|
|
|
|
| 13 |
|
| 14 |
# Initialize PaddleOCR once with updated parameters
|
| 15 |
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 thresholding the grayscale image.
|
|
@@ -82,15 +108,6 @@ def create_pdf_report(coverage_percent, extracted_texts, annotated_image_path, o
|
|
| 82 |
|
| 83 |
pdf.output(output_path)
|
| 84 |
|
| 85 |
-
def upload_image_and_get_url(image_path):
|
| 86 |
-
"""
|
| 87 |
-
TODO: Implement your image upload to public storage here.
|
| 88 |
-
For now, returns a placeholder URL.
|
| 89 |
-
"""
|
| 90 |
-
# Example: upload to AWS S3, Azure Blob Storage, or other service
|
| 91 |
-
# Return the public URL to the uploaded image
|
| 92 |
-
return "https://example.com/path/to/your/annotated_image.jpg"
|
| 93 |
-
|
| 94 |
def save_record_to_salesforce(annotated_image_url, coverage_percent, original_image_pil, compliance_threshold=80):
|
| 95 |
sf = Salesforce(
|
| 96 |
username=os.environ['SF_USERNAME'],
|
|
@@ -164,6 +181,7 @@ def process_image(input_img, brightness_threshold=150):
|
|
| 164 |
|
| 165 |
report_text = f"UV Sterilization Coverage: {coverage_percent:.2f}%"
|
| 166 |
|
|
|
|
| 167 |
# Clean up temp image file after PDF generation
|
| 168 |
os.unlink(annotated_img_path)
|
| 169 |
|
|
@@ -171,7 +189,7 @@ def process_image(input_img, brightness_threshold=150):
|
|
| 171 |
|
| 172 |
iface = gr.Interface(
|
| 173 |
fn=process_image,
|
| 174 |
-
inputs=[
|
| 175 |
gr.Image(type="pil", label="Upload Post-UV Sterilization Image"),
|
| 176 |
gr.Slider(50, 255, value=150, step=1, label="Brightness Threshold")
|
| 177 |
],
|
|
|
|
| 10 |
from datetime import datetime
|
| 11 |
import base64
|
| 12 |
import io
|
| 13 |
+
import boto3
|
| 14 |
|
| 15 |
# Initialize PaddleOCR once with updated parameters
|
| 16 |
ocr_model = PaddleOCR(use_textline_orientation=True, lang='en')
|
| 17 |
|
| 18 |
+
def upload_image_and_get_url(image_path):
|
| 19 |
+
"""
|
| 20 |
+
Upload the image to AWS S3 and return the public URL.
|
| 21 |
+
"""
|
| 22 |
+
s3_client = boto3.client(
|
| 23 |
+
's3',
|
| 24 |
+
aws_access_key_id=os.environ['AWS_ACCESS_KEY_ID'],
|
| 25 |
+
aws_secret_access_key=os.environ['AWS_SECRET_ACCESS_KEY'],
|
| 26 |
+
region_name='your-region'
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
# Define the S3 bucket name
|
| 30 |
+
bucket_name = 'your-bucket-name'
|
| 31 |
+
|
| 32 |
+
# Generate a unique key for the image (e.g., using the file name)
|
| 33 |
+
image_key = f"images/{os.path.basename(image_path)}"
|
| 34 |
+
|
| 35 |
+
# Upload the image to S3
|
| 36 |
+
s3_client.upload_file(image_path, bucket_name, image_key)
|
| 37 |
+
|
| 38 |
+
# Construct the public URL for the uploaded image
|
| 39 |
+
image_url = f"https://{bucket_name}.s3.{os.environ['AWS_REGION']}.amazonaws.com/{image_key}"
|
| 40 |
+
|
| 41 |
+
return image_url
|
| 42 |
+
|
| 43 |
def analyze_uv_coverage(img, brightness_threshold=150, kernel_size=5, apply_blur=True, adaptive_thresh=False):
|
| 44 |
"""
|
| 45 |
Analyze UV sterilization coverage by thresholding the grayscale image.
|
|
|
|
| 108 |
|
| 109 |
pdf.output(output_path)
|
| 110 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
def save_record_to_salesforce(annotated_image_url, coverage_percent, original_image_pil, compliance_threshold=80):
|
| 112 |
sf = Salesforce(
|
| 113 |
username=os.environ['SF_USERNAME'],
|
|
|
|
| 181 |
|
| 182 |
report_text = f"UV Sterilization Coverage: {coverage_percent:.2f}%"
|
| 183 |
|
| 184 |
+
|
| 185 |
# Clean up temp image file after PDF generation
|
| 186 |
os.unlink(annotated_img_path)
|
| 187 |
|
|
|
|
| 189 |
|
| 190 |
iface = gr.Interface(
|
| 191 |
fn=process_image,
|
| 192 |
+
inputs=[
|
| 193 |
gr.Image(type="pil", label="Upload Post-UV Sterilization Image"),
|
| 194 |
gr.Slider(50, 255, value=150, step=1, label="Brightness Threshold")
|
| 195 |
],
|