eagle0504 commited on
Commit
8abc334
·
1 Parent(s): 1a69f98

checkbox added

Browse files
Files changed (1) hide show
  1. app.py +69 -53
app.py CHANGED
@@ -142,69 +142,85 @@ def main():
142
  with st.spinner("Wait for it..."):
143
  st.write(text_from_response)
144
 
145
- st.markdown(
146
- "# Information Retrieval - use Gemini to extract the values for the keys required by the stakeholders"
 
147
  )
148
- with st.spinner("Processing csv to download..."):
149
- try:
150
- keys = ["First Name", "Last Name", "Policy Number"]
151
- values = []
152
- for k in keys:
153
- updated_text_from_response = call_gemini_api(
154
- image_base64,
155
- api_key,
156
- prompt=f"What is {k} in this document? Just answer the question directly using key words, don't say a complete sentence.",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
157
  )
158
- value = updated_text_from_response["candidates"][0][
159
- "content"
160
- ]["parts"][0]["text"]
161
- values.append(value)
162
 
163
- # Create dataframe to download
164
- sample_payload_output = pd.DataFrame(
165
- {"Key": keys, "Values": values}
166
- )
167
 
168
- # Display table
169
- with st.expander("Inspect table (before download)"):
170
- st.table(sample_payload_output)
171
 
172
- # Convert DataFrame to CSV
173
- csv = sample_payload_output.to_csv(index=False)
174
-
175
- # To convert to CSV and encode for the download link
176
- csv = sample_payload_output.to_csv(index=False).encode("utf-8")
177
 
178
- # Streamlit download button
179
- st.download_button(
180
- label="Download data as CSV",
181
- data=csv,
182
- file_name="data.csv",
183
- mime="text/csv",
184
- )
185
- except:
186
- st.warning("Please verify document source.")
187
 
188
- # Text input for the question
189
- input_prompt = st.text_input(
190
- "Type your question here:",
191
  )
192
-
193
- # Display the entered question
194
- if input_prompt:
195
- updated_text_from_response = call_gemini_api(
196
- image_base64, api_key, prompt=input_prompt
197
  )
198
 
199
- if updated_text_from_response is not None:
200
- # Do something with the text
201
- updated_ans = updated_text_from_response["candidates"][0][
202
- "content"
203
- ]["parts"][0]["text"]
204
- with st.spinner("Wait for it..."):
205
- st.write(f"Gemini: {updated_ans}")
206
- else:
207
- st.warning("Check gemini's API.")
 
 
 
 
 
 
208
 
209
  except:
210
  st.write("No response from API.")
 
142
  with st.spinner("Wait for it..."):
143
  st.write(text_from_response)
144
 
145
+ use_retrieval_tech = st.sidebar.checkbox(
146
+ "Check the box if you want to see a sample retrieved information to download (only use this if this is a document-based task)!",
147
+ value=False,
148
  )
149
+ if use_retrieval_tech:
150
+ st.markdown(
151
+ "# Information Retrieval - use Gemini to extract the values for the keys required by the stakeholders"
152
+ )
153
+ with st.spinner("Processing csv to download..."):
154
+ try:
155
+ keys = ["First Name", "Last Name", "Policy Number"]
156
+ values = []
157
+ for k in keys:
158
+ updated_text_from_response = call_gemini_api(
159
+ image_base64,
160
+ api_key,
161
+ prompt=f"""
162
+ What is {k} in this document? Just answer the question directly with a word or two, don't say a complete sentence.
163
+
164
+ If there is any special characters, rewrite it w
165
+ """,
166
+ )
167
+ value = updated_text_from_response["candidates"][0][
168
+ "content"
169
+ ]["parts"][0]["text"]
170
+ values.append(value)
171
+
172
+ # Create dataframe to download
173
+ sample_payload_output = pd.DataFrame(
174
+ {"Key": keys, "Values": values}
175
  )
 
 
 
 
176
 
177
+ # Display table
178
+ with st.expander("Inspect table (before download)"):
179
+ st.table(sample_payload_output)
 
180
 
181
+ # Convert DataFrame to CSV
182
+ csv = sample_payload_output.to_csv(index=False)
 
183
 
184
+ # To convert to CSV and encode for the download link
185
+ csv = sample_payload_output.to_csv(index=False).encode(
186
+ "utf-8"
187
+ )
 
188
 
189
+ # Streamlit download button
190
+ st.download_button(
191
+ label="Download data as CSV",
192
+ data=csv,
193
+ file_name="data.csv",
194
+ mime="text/csv",
195
+ )
196
+ except:
197
+ st.warning("Please verify document source.")
198
 
199
+ use_gemini_to_chat = st.sidebar.checkbox(
200
+ "Check the box if you want to chat with Gemini (do this if you want Gemini to answwer your questions)!",
201
+ value=False,
202
  )
203
+ if use_gemini_to_chat:
204
+ # Text input for the question
205
+ input_prompt = st.text_input(
206
+ "Type your question here:",
 
207
  )
208
 
209
+ # Display the entered question
210
+ if input_prompt:
211
+ updated_text_from_response = call_gemini_api(
212
+ image_base64, api_key, prompt=input_prompt
213
+ )
214
+
215
+ if updated_text_from_response is not None:
216
+ # Do something with the text
217
+ updated_ans = updated_text_from_response["candidates"][0][
218
+ "content"
219
+ ]["parts"][0]["text"]
220
+ with st.spinner("Wait for it..."):
221
+ st.write(f"Gemini: {updated_ans}")
222
+ else:
223
+ st.warning("Check gemini's API.")
224
 
225
  except:
226
  st.write("No response from API.")