rexarski commited on
Commit
08a14f0
1 Parent(s): 5d10b71

[ADD] add radio button to switch between examples and inputs

Browse files
Files changed (1) hide show
  1. app.py +52 -32
app.py CHANGED
@@ -146,47 +146,67 @@ See the [GitHub repo](https://github.com/rexarski/climate-plus) for more details
146
 
147
  st.markdown("## Factchecking")
148
 
149
- ex1_selected = st.selectbox(
150
- "Select a climate claim-evidence pair", df1["example"]
 
151
  )
152
- selected_row1 = df1[df1["example"] == ex1_selected]
153
 
154
- ex_claim = selected_row1["claim"].values[0]
155
- ex_evidence = selected_row1["evidence"].values[0]
156
- ex_label = selected_row1["label"].values[0]
157
- ex_pred = factcheck(
158
- selected_row1["claim"].values[0], selected_row1["evidence"].values[0]
159
- )
160
- st.markdown(f"**Claim**: {ex_claim}")
161
- st.markdown(f"**Evidence**: {ex_evidence}")
162
- st.markdown(f"**Label**: {ex_label}")
163
- st.markdown(
164
- f'**Prediction**: {ex_pred} {get_pred_emoji(ex_label, ex_pred, mode="factcheck")}'
165
- )
166
 
167
- custom_claim = st.text_input(label="Or enter your own claim below:")
168
- custom_evidence = st.text_input(label="And the evidence:")
169
- st.markdown(f"**Prediction**: {factcheck(custom_claim, custom_evidence)}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
170
 
171
  st.markdown("---")
172
 
173
  st.markdown("## TCFD disclosure classification")
174
 
175
- ex2_selected = st.selectbox("Select a TCFD disclosure example", df2["example"])
176
- selected_row2 = df2[df2["example"] == ex2_selected]
 
 
177
 
178
- ex_text = selected_row2["text"].values[0]
179
- ex_label2 = selected_row2["label"].values[0]
180
- ex_pred2 = tcfd_classify(selected_row2["text"].values[0])
 
 
181
 
182
- st.markdown(f"**Text**: {ex_text}")
183
- st.markdown(f"**Label**: {ex_label2}")
184
- st.markdown(
185
- f'**Prediction**: {ex_pred2} {get_pred_emoji(ex_label2, ex_pred2, mode="tcfd")}'
186
- )
187
 
188
- custom_text = st.text_input(
189
- label="Or enter your own sentence to see if it belongs to any specific TCFD disclosure category:"
190
- )
191
- st.markdown(f"**Prediction**: {tcfd_classify(custom_text)}")
 
 
 
 
 
 
 
 
192
 
 
146
 
147
  st.markdown("## Factchecking")
148
 
149
+ factchecking_demo = st.radio(
150
+ "What examples do you want to see?",
151
+ ("Preloaded examples", "Custom examples"),
152
  )
 
153
 
154
+ if factchecking_demo == "Preloaded examples":
155
+ ex1_selected = st.selectbox(
156
+ "Select a climate claim-evidence pair", df1["example"]
157
+ )
158
+ selected_row1 = df1[df1["example"] == ex1_selected]
 
 
 
 
 
 
 
159
 
160
+ ex_claim = selected_row1["claim"].values[0]
161
+ ex_evidence = selected_row1["evidence"].values[0]
162
+ ex_label = selected_row1["label"].values[0]
163
+ ex_pred = factcheck(
164
+ selected_row1["claim"].values[0], selected_row1["evidence"].values[0]
165
+ )
166
+ st.markdown(f"**Claim**: {ex_claim}")
167
+ st.markdown(f"**Evidence**: {ex_evidence}")
168
+ st.markdown(f"**Label**: {ex_label}")
169
+ st.markdown(
170
+ f'**Prediction**: {ex_pred} {get_pred_emoji(ex_label, ex_pred, mode="factcheck")}'
171
+ )
172
+ else:
173
+ st.markdown("Or enter your own claim and evidence below:")
174
+ custom_claim = st.text_input(label="Enter your claim.")
175
+ custom_evidence = st.text_input(label="Enter your evidence.")
176
+ if custom_claim != "" and custom_evidence != "":
177
+ st.markdown(
178
+ f"**Prediction**: {factcheck(custom_claim, custom_evidence)}"
179
+ )
180
 
181
  st.markdown("---")
182
 
183
  st.markdown("## TCFD disclosure classification")
184
 
185
+ tcfd_demo = st.radio(
186
+ "What examples do you want to see?",
187
+ ("Preloaded examples", "Custom examples"),
188
+ )
189
 
190
+ if tcfd_demo == "Preloaded examples":
191
+ ex2_selected = st.selectbox(
192
+ "Select a TCFD disclosure example", df2["example"]
193
+ )
194
+ selected_row2 = df2[df2["example"] == ex2_selected]
195
 
196
+ ex_text = selected_row2["text"].values[0]
197
+ ex_label2 = selected_row2["label"].values[0]
198
+ ex_pred2 = tcfd_classify(selected_row2["text"].values[0])
 
 
199
 
200
+ st.markdown(f"**Text**: {ex_text}")
201
+ st.markdown(f"**Label**: {ex_label2}")
202
+ st.markdown(
203
+ f'**Prediction**: {ex_pred2} {get_pred_emoji(ex_label2, ex_pred2, mode="tcfd")}'
204
+ )
205
+ else:
206
+ st.markdown(
207
+ "Or enter your own sentence to see if it belongs to any specific TCFD disclosure category:"
208
+ )
209
+ custom_text = st.text_input(label="Enter your text.")
210
+ if custom_text != "":
211
+ st.markdown(f"**Prediction**: {tcfd_classify(custom_text)}")
212