Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -200,66 +200,67 @@ with st.container():
|
|
200 |
# Placeholder for displaying result/loading
|
201 |
with st.spinner("Verifying..."):
|
202 |
start_time = time.time()
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
221 |
"cuda" if torch.cuda.is_available() else "cpu"
|
222 |
)
|
223 |
-
if
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
"evidence_time": evidence_time,
|
257 |
-
"verdict_time": verdict_time,
|
258 |
-
"details": details
|
259 |
-
}
|
260 |
-
|
261 |
-
if torch.cuda.is_available():
|
262 |
-
torch.cuda.empty_cache()
|
263 |
|
264 |
# Display the result after verification
|
265 |
res = st.session_state.latest_result
|
|
|
200 |
# Placeholder for displaying result/loading
|
201 |
with st.spinner("Verifying..."):
|
202 |
start_time = time.time()
|
203 |
+
|
204 |
+
# Extract evidence
|
205 |
+
evidence_start_time = time.time()
|
206 |
+
evidence = extract_evidence_tfidf_qatc(
|
207 |
+
claim, context, model_qatc, tokenizer_qatc,
|
208 |
+
"cuda" if torch.cuda.is_available() else "cpu",
|
209 |
+
confidence_threshold=tfidf_threshold,
|
210 |
+
length_ratio_threshold=length_ratio_threshold
|
211 |
+
)
|
212 |
+
evidence_time = time.time() - evidence_start_time
|
213 |
+
|
214 |
+
# Classify the claim
|
215 |
+
verdict_start_time = time.time()
|
216 |
+
verdict = "NEI"
|
217 |
+
details = ""
|
218 |
+
prob3class, pred_tc = classify_claim(
|
219 |
+
claim, evidence, model_tc, tokenizer_tc,
|
220 |
+
"cuda" if torch.cuda.is_available() else "cpu"
|
221 |
+
)
|
222 |
+
if pred_tc == 1:
|
223 |
+
verdict = "SUPPORTED"
|
224 |
+
elif pred_tc == 2:
|
225 |
+
verdict = "REFUTED"
|
226 |
+
else:
|
227 |
+
prob2class, pred_bc = classify_claim(
|
228 |
+
claim, evidence, model_bc, tokenizer_bc,
|
229 |
"cuda" if torch.cuda.is_available() else "cpu"
|
230 |
)
|
231 |
+
if pred_bc == 0:
|
232 |
+
verdict = "SUPPORTED"
|
233 |
+
else:
|
234 |
+
verdict = "REFUTED"
|
235 |
+
if show_details:
|
236 |
+
details = f"""
|
237 |
+
<p><strong>3-Class Probability:</strong> {prob3class.item():.2f}</p>
|
238 |
+
<p><strong>3-Class Predicted Label:</strong> {['NEI', 'SUPPORTED', 'REFUTED'][pred_tc]}</p>
|
239 |
+
<p><strong>2-Class Probability:</strong> {prob2class.item():.2f}</p>
|
240 |
+
<p><strong>2-Class Predicted Label:</strong> {['SUPPORTED', 'REFUTED'][pred_bc]}</p>
|
241 |
+
"""
|
242 |
+
verdict_time = time.time() - verdict_start_time
|
243 |
+
|
244 |
+
# Store verification history and the latest result
|
245 |
+
st.session_state.history.append({
|
246 |
+
"claim": claim,
|
247 |
+
"evidence": evidence,
|
248 |
+
"verdict": verdict,
|
249 |
+
"evidence_time": evidence_time,
|
250 |
+
"verdict_time": verdict_time,
|
251 |
+
"details": details
|
252 |
+
})
|
253 |
+
st.session_state.latest_result = {
|
254 |
+
"claim": claim,
|
255 |
+
"evidence": evidence,
|
256 |
+
"verdict": verdict,
|
257 |
+
"evidence_time": evidence_time,
|
258 |
+
"verdict_time": verdict_time,
|
259 |
+
"details": details
|
260 |
+
}
|
261 |
+
|
262 |
+
if torch.cuda.is_available():
|
263 |
+
torch.cuda.empty_cache()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
264 |
|
265 |
# Display the result after verification
|
266 |
res = st.session_state.latest_result
|