eagle0504 commited on
Commit
a02a252
·
1 Parent(s): abcdc0f

doc download added

Browse files
Files changed (1) hide show
  1. app.py +45 -3
app.py CHANGED
@@ -104,11 +104,17 @@ def main():
104
  image = Image.open(image)
105
 
106
  # Draw bounding boxes and labels
107
- image_with_boxes = draw_bounding_boxes_for_textract(image.copy(), result_dict)
 
 
108
  st.success("Bounding boxes drawn.")
109
-
110
  # Display annotated image
111
- st.image(image_with_boxes, caption="Annotated Image", use_column_width=True)
 
 
 
 
112
 
113
  except:
114
  st.warning("Check textract output!")
@@ -130,6 +136,42 @@ def main():
130
  with st.spinner("Wait for it..."):
131
  st.write(text_from_response)
132
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
133
  # Text input for the question
134
  input_prompt = st.text_input(
135
  "Type your question here:",
 
104
  image = Image.open(image)
105
 
106
  # Draw bounding boxes and labels
107
+ image_with_boxes = draw_bounding_boxes_for_textract(
108
+ image.copy(), result_dict
109
+ )
110
  st.success("Bounding boxes drawn.")
111
+
112
  # Display annotated image
113
+ st.image(
114
+ image_with_boxes,
115
+ caption="Annotated Image",
116
+ use_column_width=True,
117
+ )
118
 
119
  except:
120
  st.warning("Check textract output!")
 
136
  with st.spinner("Wait for it..."):
137
  st.write(text_from_response)
138
 
139
+ with st.spinner("Processing csv to download..."):
140
+ try:
141
+ keys = ["First Name", "Last Name", "Policy Number"]
142
+ values = []
143
+ for k in keys:
144
+ updated_text_from_response = call_gemini_api(
145
+ image_base64,
146
+ api_key,
147
+ prompt=f"What is {k} in this document?",
148
+ )
149
+ value = updated_text_from_response["candidates"][0][
150
+ "content"
151
+ ]["parts"][0]["text"]
152
+ values.append(value)
153
+
154
+ # Create dataframe to download
155
+ sample_payload_output = pd.DataFrame(
156
+ {"Key": keys, "Values": values}
157
+ )
158
+
159
+ # Convert DataFrame to CSV
160
+ csv = sample_payload_output.to_csv(index=False)
161
+
162
+ # To convert to CSV and encode for the download link
163
+ csv = sample_payload_output.to_csv(index=False).encode("utf-8")
164
+
165
+ # Streamlit download button
166
+ st.download_button(
167
+ label="Download data as CSV",
168
+ data=csv,
169
+ file_name="data.csv",
170
+ mime="text/csv",
171
+ )
172
+ except:
173
+ st.warning("Please verify document source.")
174
+
175
  # Text input for the question
176
  input_prompt = st.text_input(
177
  "Type your question here:",