eagle0504 commited on
Commit
b8b0c3f
·
verified ·
1 Parent(s): 131eb49

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -48
app.py CHANGED
@@ -91,58 +91,62 @@ def main():
91
  # Convert the resized image to base64
92
  image_base64 = convert_image_to_base64(resized_image)
93
 
 
 
94
  # OCR by API Call of AWS Textract via Post Method
95
  if input_method == "Upload Image":
96
- st.markdown(
97
- "# OCR (Optical Character Recognition) - computer vision technology to locate letters/numbers from image."
98
- )
99
- st.success("Running textract!")
100
- url = "https://2tsig211e0.execute-api.us-east-1.amazonaws.com/my_textract"
101
- payload = {"image": image_base64}
102
- result_dict = post_request_and_parse_response(url, payload)
103
- output_data = extract_line_items(result_dict)
104
- df = pd.DataFrame(output_data)
105
-
106
- # Using an expander to hide the json
107
- with st.expander("Show/Hide Raw Json"):
108
- st.write(result_dict)
109
-
110
- # Using an expander to hide the table
111
- with st.expander("Show/Hide Table"):
112
- st.table(df)
113
-
114
- # Using an expander to hide the table
115
- st.success("Bounding boxes drawn!")
116
- with st.expander("Show/Hide Annotation"):
117
- try:
118
- image = Image.open(image)
119
-
120
- # Draw bounding boxes and labels
121
- image_with_boxes = draw_bounding_boxes_for_textract(
122
- image.copy(), result_dict
123
- )
124
-
125
- # Display annotated image
126
- st.image(
127
- image_with_boxes,
128
- caption="Annotated Image",
129
- use_column_width=True,
130
- )
131
-
132
- except:
133
- st.warning("Check textract output!")
 
134
 
135
  if api_key:
136
- # Make API call
137
- st.markdown(
138
- "# Gemini (Generative AI) - read the image content in a general form"
139
- )
140
- st.success("Running Gemini!")
141
- with st.spinner("Wait for it..."):
142
- response = call_gemini_api(image_base64, api_key)
143
-
144
- with st.expander("Raw output from Gemini"):
145
- st.write(response)
 
146
 
147
  # Display the response
148
  try:
 
91
  # Convert the resized image to base64
92
  image_base64 = convert_image_to_base64(resized_image)
93
 
94
+ col1, col2 = st.columns(2)
95
+
96
  # OCR by API Call of AWS Textract via Post Method
97
  if input_method == "Upload Image":
98
+ with col1:
99
+ st.markdown(
100
+ "# OCR (Optical Character Recognition) - computer vision technology to locate letters/numbers from image."
101
+ )
102
+ st.success("Running textract!")
103
+ url = "https://2tsig211e0.execute-api.us-east-1.amazonaws.com/my_textract"
104
+ payload = {"image": image_base64}
105
+ result_dict = post_request_and_parse_response(url, payload)
106
+ output_data = extract_line_items(result_dict)
107
+ df = pd.DataFrame(output_data)
108
+
109
+ # Using an expander to hide the json
110
+ with st.expander("Show/Hide Raw Json"):
111
+ st.write(result_dict)
112
+
113
+ # Using an expander to hide the table
114
+ with st.expander("Show/Hide Table"):
115
+ st.table(df)
116
+
117
+ # Using an expander to hide the table
118
+ st.success("Bounding boxes drawn!")
119
+ with st.expander("Show/Hide Annotation"):
120
+ try:
121
+ image = Image.open(image)
122
+
123
+ # Draw bounding boxes and labels
124
+ image_with_boxes = draw_bounding_boxes_for_textract(
125
+ image.copy(), result_dict
126
+ )
127
+
128
+ # Display annotated image
129
+ st.image(
130
+ image_with_boxes,
131
+ caption="Annotated Image",
132
+ use_column_width=True,
133
+ )
134
+
135
+ except:
136
+ st.warning("Check textract output!")
137
 
138
  if api_key:
139
+ with col2:
140
+ # Make API call
141
+ st.markdown(
142
+ "# Gemini (Generative AI) - read the image content in a general form"
143
+ )
144
+ st.success("Running Gemini!")
145
+ with st.spinner("Wait for it..."):
146
+ response = call_gemini_api(image_base64, api_key)
147
+
148
+ with st.expander("Raw output from Gemini"):
149
+ st.write(response)
150
 
151
  # Display the response
152
  try: