Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -16,16 +16,25 @@ ocr_model = PaddleOCR(use_textline_orientation=True, lang='en')
|
|
| 16 |
def upload_image_and_get_url(image_path):
|
| 17 |
"""
|
| 18 |
Upload the image to AWS S3 and return the public URL.
|
|
|
|
| 19 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
s3_client = boto3.client(
|
| 21 |
's3',
|
| 22 |
-
aws_access_key_id=
|
| 23 |
-
aws_secret_access_key=
|
| 24 |
-
region_name=
|
| 25 |
)
|
| 26 |
|
| 27 |
# Define the S3 bucket name
|
| 28 |
-
bucket_name = 'your-bucket-name'
|
| 29 |
|
| 30 |
# Generate a unique key for the image (e.g., using the file name)
|
| 31 |
image_key = f"images/{os.path.basename(image_path)}"
|
|
@@ -34,7 +43,7 @@ def upload_image_and_get_url(image_path):
|
|
| 34 |
s3_client.upload_file(image_path, bucket_name, image_key)
|
| 35 |
|
| 36 |
# Construct the public URL for the uploaded image
|
| 37 |
-
image_url = f"https://{bucket_name}.s3.{
|
| 38 |
|
| 39 |
return image_url
|
| 40 |
|
|
@@ -148,7 +157,7 @@ def process_image(input_img, brightness_threshold=150):
|
|
| 148 |
img = cv2.resize(img, (int(w * scale), int(h * scale)))
|
| 149 |
|
| 150 |
start_time = time.time()
|
| 151 |
-
ocr_result = ocr_model.ocr(img)
|
| 152 |
ocr_time = time.time() - start_time
|
| 153 |
|
| 154 |
extracted_texts = []
|
|
@@ -179,7 +188,6 @@ def process_image(input_img, brightness_threshold=150):
|
|
| 179 |
|
| 180 |
report_text = f"UV Sterilization Coverage: {coverage_percent:.2f}%"
|
| 181 |
|
| 182 |
-
|
| 183 |
# Clean up temp image file after PDF generation
|
| 184 |
os.unlink(annotated_img_path)
|
| 185 |
|
|
|
|
| 16 |
def upload_image_and_get_url(image_path):
|
| 17 |
"""
|
| 18 |
Upload the image to AWS S3 and return the public URL.
|
| 19 |
+
The AWS credentials must be set in the environment variables.
|
| 20 |
"""
|
| 21 |
+
# Ensure that AWS credentials are set in the environment variables
|
| 22 |
+
aws_access_key_id = os.environ.get('AWS_ACCESS_KEY_ID')
|
| 23 |
+
aws_secret_access_key = os.environ.get('AWS_SECRET_ACCESS_KEY')
|
| 24 |
+
aws_region = os.environ.get('AWS_REGION')
|
| 25 |
+
|
| 26 |
+
if not aws_access_key_id or not aws_secret_access_key or not aws_region:
|
| 27 |
+
raise ValueError("AWS credentials (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION) are missing in environment variables.")
|
| 28 |
+
|
| 29 |
s3_client = boto3.client(
|
| 30 |
's3',
|
| 31 |
+
aws_access_key_id=aws_access_key_id,
|
| 32 |
+
aws_secret_access_key=aws_secret_access_key,
|
| 33 |
+
region_name=aws_region
|
| 34 |
)
|
| 35 |
|
| 36 |
# Define the S3 bucket name
|
| 37 |
+
bucket_name = 'your-bucket-name' # Replace with your S3 bucket name
|
| 38 |
|
| 39 |
# Generate a unique key for the image (e.g., using the file name)
|
| 40 |
image_key = f"images/{os.path.basename(image_path)}"
|
|
|
|
| 43 |
s3_client.upload_file(image_path, bucket_name, image_key)
|
| 44 |
|
| 45 |
# Construct the public URL for the uploaded image
|
| 46 |
+
image_url = f"https://{bucket_name}.s3.{aws_region}.amazonaws.com/{image_key}"
|
| 47 |
|
| 48 |
return image_url
|
| 49 |
|
|
|
|
| 157 |
img = cv2.resize(img, (int(w * scale), int(h * scale)))
|
| 158 |
|
| 159 |
start_time = time.time()
|
| 160 |
+
ocr_result = ocr_model.ocr(img) # DeprecationWarning: Use 'predict' instead of 'ocr'
|
| 161 |
ocr_time = time.time() - start_time
|
| 162 |
|
| 163 |
extracted_texts = []
|
|
|
|
| 188 |
|
| 189 |
report_text = f"UV Sterilization Coverage: {coverage_percent:.2f}%"
|
| 190 |
|
|
|
|
| 191 |
# Clean up temp image file after PDF generation
|
| 192 |
os.unlink(annotated_img_path)
|
| 193 |
|