pavansuresh commited on
Commit
41c136f
·
verified ·
1 Parent(s): ff0464f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -37
app.py CHANGED
@@ -8,45 +8,12 @@ from paddleocr import PaddleOCR
8
  import time
9
  from simple_salesforce import Salesforce
10
  from datetime import datetime
11
- import boto3
 
12
 
13
  # Initialize PaddleOCR once with updated parameters
14
  ocr_model = PaddleOCR(use_textline_orientation=True, lang='en')
15
 
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)}"
41
-
42
- # Upload the image to S3
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
-
50
  def analyze_uv_coverage(img, brightness_threshold=150, kernel_size=5, apply_blur=True, adaptive_thresh=False):
51
  """
52
  Analyze UV sterilization coverage by thresholding the grayscale image.
@@ -115,6 +82,15 @@ def create_pdf_report(coverage_percent, extracted_texts, annotated_image_path, o
115
 
116
  pdf.output(output_path)
117
 
 
 
 
 
 
 
 
 
 
118
  def save_record_to_salesforce(annotated_image_url, coverage_percent, original_image_pil, compliance_threshold=80):
119
  sf = Salesforce(
120
  username=os.environ['SF_USERNAME'],
@@ -157,7 +133,7 @@ def process_image(input_img, brightness_threshold=150):
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 = []
@@ -195,7 +171,7 @@ def process_image(input_img, brightness_threshold=150):
195
 
196
  iface = gr.Interface(
197
  fn=process_image,
198
- inputs=[
199
  gr.Image(type="pil", label="Upload Post-UV Sterilization Image"),
200
  gr.Slider(50, 255, value=150, step=1, label="Brightness Threshold")
201
  ],
 
8
  import time
9
  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
 
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'],
 
133
  img = cv2.resize(img, (int(w * scale), int(h * scale)))
134
 
135
  start_time = time.time()
136
+ ocr_result = ocr_model.ocr(img)
137
  ocr_time = time.time() - start_time
138
 
139
  extracted_texts = []
 
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
  ],