Update app.py
Browse files
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 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
st.
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
st.
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
|
|
|
| 134 |
|
| 135 |
if api_key:
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
st.
|
|
|
|
| 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:
|