checkbox added
Browse files
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.
|
146 |
-
"
|
|
|
147 |
)
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
157 |
)
|
158 |
-
value = updated_text_from_response["candidates"][0][
|
159 |
-
"content"
|
160 |
-
]["parts"][0]["text"]
|
161 |
-
values.append(value)
|
162 |
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
)
|
167 |
|
168 |
-
|
169 |
-
|
170 |
-
st.table(sample_payload_output)
|
171 |
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
csv = sample_payload_output.to_csv(index=False).encode("utf-8")
|
177 |
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
)
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
image_base64, api_key, prompt=input_prompt
|
197 |
)
|
198 |
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
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.")
|