DSatishchandra commited on
Commit
88fdb4e
·
verified ·
1 Parent(s): 47a909e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -3
app.py CHANGED
@@ -28,11 +28,22 @@ def extract_patient_info(image):
28
 
29
  # Use EasyOCR to extract text from the image
30
  result = reader.readtext(image_rgb)
 
 
 
 
 
31
  extracted_text = " ".join([detection[1] for detection in result])
 
 
 
32
 
33
  # Extract relevant details (Name, Age, Gender, Phone number) from the extracted text
34
  details = extract_details_from_text(extracted_text)
35
 
 
 
 
36
  # Create a record in Salesforce using the extracted details
37
  create_salesforce_record(details)
38
 
@@ -48,21 +59,29 @@ def extract_details_from_text(extracted_text):
48
  name_match = re.search(r"Name[:\s]*([A-Za-z\s]+)", extracted_text)
49
  if name_match:
50
  details['Name'] = name_match.group(1)
 
 
51
 
52
  # Extract Age
53
  age_match = re.search(r"Age[:\s]*([\d]+)", extracted_text)
54
  if age_match:
55
  details['Age'] = age_match.group(1)
 
 
56
 
57
  # Extract Gender
58
  gender_match = re.search(r"Gender[:\s]*(Male|Female)", extracted_text, re.IGNORECASE)
59
  if gender_match:
60
  details['Gender'] = gender_match.group(1)
 
 
61
 
62
  # Extract Phone number
63
  phone_match = re.search(r"Phone number[:\s]*([\d]+)", extracted_text)
64
  if phone_match:
65
  details['Phone Number'] = phone_match.group(1)
 
 
66
 
67
  return details
68
 
@@ -76,9 +95,16 @@ def create_salesforce_record(details):
76
  'Phone_Number__c': details['Phone Number']
77
  }
78
 
79
- # Create a new record in Salesforce
80
- sf.Patient_Registration__c.create(data)
81
- print("Salesforce record created successfully!")
 
 
 
 
 
 
 
82
 
83
  # Gradio interface setup
84
  with gr.Blocks() as demo:
 
28
 
29
  # Use EasyOCR to extract text from the image
30
  result = reader.readtext(image_rgb)
31
+
32
+ # Debug: Print OCR result
33
+ print("OCR Result:", result)
34
+
35
+ # Extracted text from OCR
36
  extracted_text = " ".join([detection[1] for detection in result])
37
+
38
+ # Debug: Print the extracted text
39
+ print("Extracted Text:", extracted_text)
40
 
41
  # Extract relevant details (Name, Age, Gender, Phone number) from the extracted text
42
  details = extract_details_from_text(extracted_text)
43
 
44
+ # Debug: Print parsed details
45
+ print("Parsed Details:", details)
46
+
47
  # Create a record in Salesforce using the extracted details
48
  create_salesforce_record(details)
49
 
 
59
  name_match = re.search(r"Name[:\s]*([A-Za-z\s]+)", extracted_text)
60
  if name_match:
61
  details['Name'] = name_match.group(1)
62
+ else:
63
+ print("Error: Name not found!")
64
 
65
  # Extract Age
66
  age_match = re.search(r"Age[:\s]*([\d]+)", extracted_text)
67
  if age_match:
68
  details['Age'] = age_match.group(1)
69
+ else:
70
+ print("Error: Age not found!")
71
 
72
  # Extract Gender
73
  gender_match = re.search(r"Gender[:\s]*(Male|Female)", extracted_text, re.IGNORECASE)
74
  if gender_match:
75
  details['Gender'] = gender_match.group(1)
76
+ else:
77
+ print("Error: Gender not found!")
78
 
79
  # Extract Phone number
80
  phone_match = re.search(r"Phone number[:\s]*([\d]+)", extracted_text)
81
  if phone_match:
82
  details['Phone Number'] = phone_match.group(1)
83
+ else:
84
+ print("Error: Phone number not found!")
85
 
86
  return details
87
 
 
95
  'Phone_Number__c': details['Phone Number']
96
  }
97
 
98
+ # Debug: Print the data before inserting into Salesforce
99
+ print("Data to be inserted into Salesforce:", data)
100
+
101
+ try:
102
+ # Create a new record in Salesforce
103
+ sf.Patient_Registration__c.create(data)
104
+ print("Salesforce record created successfully!")
105
+ except Exception as e:
106
+ # Handle any exceptions during Salesforce record creation
107
+ print(f"Error creating Salesforce record: {e}")
108
 
109
  # Gradio interface setup
110
  with gr.Blocks() as demo: