Spaces:
Running
Running
Jin Zhu
commited on
Commit
·
f9f0de2
1
Parent(s):
7ddbb03
Update app.py
Browse files- src/app.py +124 -59
src/app.py
CHANGED
|
@@ -231,7 +231,7 @@ if 'feedback_given' not in st.session_state:
|
|
| 231 |
# Streamlit Layout
|
| 232 |
# -----------------
|
| 233 |
st.markdown(
|
| 234 |
-
"<h1 style='text-align: center;'>
|
| 235 |
unsafe_allow_html=True,
|
| 236 |
)
|
| 237 |
|
|
@@ -249,9 +249,10 @@ if not model_loaded:
|
|
| 249 |
# -----------------
|
| 250 |
# --- Two columns: Input text & button | Result displays ---
|
| 251 |
text_input = st.text_area(
|
| 252 |
-
label="",
|
| 253 |
placeholder="Paste your text to be detected here. Typically, providing text with a longer content would get a more reliable result.",
|
| 254 |
height=240,
|
|
|
|
| 255 |
)
|
| 256 |
|
| 257 |
subcol11, subcol12, subcol13 = st.columns((1, 1, 1))
|
|
@@ -267,7 +268,7 @@ selected_domain = subcol11.selectbox(
|
|
| 267 |
detect_clicked = subcol12.button("🔍 Detect", type="primary", use_container_width=True)
|
| 268 |
|
| 269 |
selected_level = subcol13.slider(
|
| 270 |
-
label="Significance (α)",
|
| 271 |
min_value=0.01,
|
| 272 |
max_value=0.2,
|
| 273 |
value=0.05,
|
|
@@ -275,33 +276,33 @@ selected_level = subcol13.slider(
|
|
| 275 |
# label_visibility="collapsed",
|
| 276 |
)
|
| 277 |
|
| 278 |
-
col2, col3, col4 = st.columns((1, 1, 2))
|
| 279 |
-
with col2:
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
|
| 288 |
-
with col3:
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
|
| 297 |
-
with col4:
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
|
| 306 |
# -----------------
|
| 307 |
# Detection Logic
|
|
@@ -347,36 +348,67 @@ if detect_clicked:
|
|
| 347 |
'elapsed_time': elapsed_time
|
| 348 |
}
|
| 349 |
|
| 350 |
-
# Update score displays
|
| 351 |
-
statistics_ph.text_input(
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
|
| 356 |
-
)
|
| 357 |
|
| 358 |
-
pvalue_ph.text_input(
|
| 359 |
-
|
| 360 |
-
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
|
| 364 |
-
|
| 365 |
-
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
|
| 369 |
-
help="Conclusion will appear here after clicking Detect.",
|
| 370 |
-
)
|
| 371 |
|
| 372 |
st.info(
|
| 373 |
-
"""
|
| 374 |
-
|
| 375 |
-
|
| 376 |
-
|
|
|
|
|
|
|
| 377 |
""",
|
| 378 |
icon="💡"
|
| 379 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 380 |
|
| 381 |
# ========== 🆕 Feedback buttons (moved here for better UX) ==========
|
| 382 |
st.markdown("**📝 Result Feedback**: Does this detection result meet your expectations?")
|
|
@@ -440,20 +472,53 @@ if detect_clicked:
|
|
| 440 |
st.error(f"❌ Error during detection: {str(e)}")
|
| 441 |
st.exception(e)
|
| 442 |
|
| 443 |
-
|
| 444 |
-
# st.markdown("
|
| 445 |
# st.markdown(
|
| 446 |
# """
|
| 447 |
-
#
|
| 448 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 449 |
# )
|
| 450 |
-
# with st.expander("📋
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 451 |
# st.code(
|
| 452 |
# """
|
| 453 |
# @inproceedings{zhou2024adadetectgpt,
|
| 454 |
# title={AdaDetectGPT: Adaptive Detection of LLM-Generated Text with Statistical Guarantees},
|
| 455 |
# author={Hongyi Zhou and Jin Zhu and Pingfan Su and Kai Ye and Ying Yang and Shakeel A O B Gavioli-Akilagun and Chengchun Shi},
|
| 456 |
-
# booktitle={The Thirty-Ninth Annual Conference on Neural Information Processing Systems
|
| 457 |
# year={2025},
|
| 458 |
# }
|
| 459 |
# """,
|
|
@@ -485,7 +550,7 @@ st.markdown(
|
|
| 485 |
}
|
| 486 |
</style>
|
| 487 |
<div class='footer'>
|
| 488 |
-
<small>
|
| 489 |
</div>
|
| 490 |
""",
|
| 491 |
unsafe_allow_html=True
|
|
|
|
| 231 |
# Streamlit Layout
|
| 232 |
# -----------------
|
| 233 |
st.markdown(
|
| 234 |
+
"<h1 style='text-align: center;'> Detect AI-Generated Texts 🕵️ </h1>",
|
| 235 |
unsafe_allow_html=True,
|
| 236 |
)
|
| 237 |
|
|
|
|
| 249 |
# -----------------
|
| 250 |
# --- Two columns: Input text & button | Result displays ---
|
| 251 |
text_input = st.text_area(
|
| 252 |
+
label="📝 Input Text to be Detected",
|
| 253 |
placeholder="Paste your text to be detected here. Typically, providing text with a longer content would get a more reliable result.",
|
| 254 |
height=240,
|
| 255 |
+
label_visibility="hidden",
|
| 256 |
)
|
| 257 |
|
| 258 |
subcol11, subcol12, subcol13 = st.columns((1, 1, 1))
|
|
|
|
| 268 |
detect_clicked = subcol12.button("🔍 Detect", type="primary", use_container_width=True)
|
| 269 |
|
| 270 |
selected_level = subcol13.slider(
|
| 271 |
+
label="Significance level (α)",
|
| 272 |
min_value=0.01,
|
| 273 |
max_value=0.2,
|
| 274 |
value=0.05,
|
|
|
|
| 276 |
# label_visibility="collapsed",
|
| 277 |
)
|
| 278 |
|
| 279 |
+
# col2, col3, col4 = st.columns((1, 1, 2))
|
| 280 |
+
# with col2:
|
| 281 |
+
# statistics_ph = st.empty()
|
| 282 |
+
# statistics_ph.text_input(
|
| 283 |
+
# label="Statistic",
|
| 284 |
+
# value="",
|
| 285 |
+
# placeholder="",
|
| 286 |
+
# disabled=True,
|
| 287 |
+
# )
|
| 288 |
|
| 289 |
+
# with col3:
|
| 290 |
+
# pvalue_ph = st.empty()
|
| 291 |
+
# pvalue_ph.text_input(
|
| 292 |
+
# label="p-value",
|
| 293 |
+
# value="",
|
| 294 |
+
# placeholder="",
|
| 295 |
+
# disabled=True,
|
| 296 |
+
# )
|
| 297 |
|
| 298 |
+
# with col4:
|
| 299 |
+
# conclusion_ph = st.empty()
|
| 300 |
+
# conclusion_ph.text_input(
|
| 301 |
+
# label="Conclusion",
|
| 302 |
+
# value="",
|
| 303 |
+
# placeholder="",
|
| 304 |
+
# disabled=True,
|
| 305 |
+
# )
|
| 306 |
|
| 307 |
# -----------------
|
| 308 |
# Detection Logic
|
|
|
|
| 348 |
'elapsed_time': elapsed_time
|
| 349 |
}
|
| 350 |
|
| 351 |
+
# # Update score displays
|
| 352 |
+
# statistics_ph.text_input(
|
| 353 |
+
# label="Statistics",
|
| 354 |
+
# value=f"{crit:.6f}",
|
| 355 |
+
# disabled=True,
|
| 356 |
+
# )
|
|
|
|
| 357 |
|
| 358 |
+
# pvalue_ph.text_input(
|
| 359 |
+
# label="p-value",
|
| 360 |
+
# value=f"{p_value:.6f}",
|
| 361 |
+
# disabled=True,
|
| 362 |
+
# )
|
| 363 |
+
|
| 364 |
+
# conclusion_ph.text_input(
|
| 365 |
+
# label="Conclusion",
|
| 366 |
+
# value="Reject H0: Text is likely LLM-generated." if p_value < selected_level else "Fail to Reject H0: Text is likely human-written.",
|
| 367 |
+
# disabled=True,
|
| 368 |
+
# )
|
|
|
|
|
|
|
| 369 |
|
| 370 |
st.info(
|
| 371 |
+
f"""
|
| 372 |
+
**Conclusion**:
|
| 373 |
+
|
| 374 |
+
{'Text is likely LLM-generated.' if p_value < selected_level else 'Fail to reject hypothesis that text is human-written.'}
|
| 375 |
+
|
| 376 |
+
based on the observation that $p$-value {p_value:.3f} is {'less' if p_value < selected_level else 'greater'} than significance level {selected_level:.2f} 📊
|
| 377 |
""",
|
| 378 |
icon="💡"
|
| 379 |
)
|
| 380 |
+
st.markdown(
|
| 381 |
+
"""
|
| 382 |
+
<style>
|
| 383 |
+
/* Tighten spacing inside Clarification / Citation expanders */
|
| 384 |
+
div[data-testid="stExpander"] {
|
| 385 |
+
margin-top: -1.3rem;
|
| 386 |
+
}
|
| 387 |
+
div[data-testid="stExpander"] p,
|
| 388 |
+
div[data-testid="stExpander"] li {
|
| 389 |
+
line-height: 1.35;
|
| 390 |
+
margin-bottom: 0.1rem;
|
| 391 |
+
}
|
| 392 |
+
|
| 393 |
+
div[data-testid="stExpander"] ul {
|
| 394 |
+
margin-top: 0.1rem;
|
| 395 |
+
}
|
| 396 |
+
</style>
|
| 397 |
+
""",
|
| 398 |
+
unsafe_allow_html=True
|
| 399 |
+
)
|
| 400 |
+
with st.expander("📋 Illustration and Suggestions"):
|
| 401 |
+
st.markdown(
|
| 402 |
+
"""
|
| 403 |
+
+ Illustration:
|
| 404 |
+
- $p$-value: Lower $p$-value (closer to 0) indicates text is **more likely AI-generated**; Higher $p$-value (closer to 1) indicates text is **more likely human-written**.
|
| 405 |
+
- Significance Level (α): a threshold set by the user to determine the sensitivity of the detection. Lower α means stricter criteria for claiming the text is AI-generated.
|
| 406 |
+
|
| 407 |
+
+ Suggestions for better detection:
|
| 408 |
+
- Provide longer text inputs for more reliable detection results.
|
| 409 |
+
- Select the domain that best matches the content of your text to improve detection accuracy.
|
| 410 |
+
"""
|
| 411 |
+
)
|
| 412 |
|
| 413 |
# ========== 🆕 Feedback buttons (moved here for better UX) ==========
|
| 414 |
st.markdown("**📝 Result Feedback**: Does this detection result meet your expectations?")
|
|
|
|
| 472 |
st.error(f"❌ Error during detection: {str(e)}")
|
| 473 |
st.exception(e)
|
| 474 |
|
| 475 |
+
|
| 476 |
+
# st.markdown("<div style='height: 4rem;'></div>", unsafe_allow_html=True)
|
| 477 |
# st.markdown(
|
| 478 |
# """
|
| 479 |
+
# <style>
|
| 480 |
+
# /* Tighten spacing inside Clarification / Citation expanders */
|
| 481 |
+
# div[data-testid="stExpander"] p,
|
| 482 |
+
# div[data-testid="stExpander"] li {
|
| 483 |
+
# line-height: 1.35;
|
| 484 |
+
# margin-bottom: 0.3rem;
|
| 485 |
+
# }
|
| 486 |
+
|
| 487 |
+
# div[data-testid="stExpander"] ul {
|
| 488 |
+
# margin-top: 0.3rem;
|
| 489 |
+
# margin-bottom: 0.3rem;
|
| 490 |
+
# }
|
| 491 |
+
# </style>
|
| 492 |
+
# """,
|
| 493 |
+
# unsafe_allow_html=True
|
| 494 |
# )
|
| 495 |
+
# with st.expander("📋 Illustration and Suggestions"):
|
| 496 |
+
# st.markdown(
|
| 497 |
+
# """
|
| 498 |
+
# + Illustration:
|
| 499 |
+
# - Statistic: a numerical measure computed from the input text. Higher values typically indicate a greater likelihood of being AI-generated.
|
| 500 |
+
# - p-value: Lower p-value (closer to 0) indicates text is **more likely AI-generated**; Higher p-value (closer to 1) indicates text is **more likely human-written**.
|
| 501 |
+
# - Conclusion: when the p-value is less than the significance level (α), the text is classified as AI-generated.
|
| 502 |
+
# - Significance Level (α): a threshold set by the user to determine the sensitivity of the detection. Lower α means stricter criteria for claiming the text is AI-generated.
|
| 503 |
+
|
| 504 |
+
# + Suggestions for better detection:
|
| 505 |
+
# - Provide longer text inputs for more reliable detection results.
|
| 506 |
+
# - Select the domain that best matches the content of your text to improve detection accuracy.
|
| 507 |
+
# """
|
| 508 |
+
# )
|
| 509 |
+
|
| 510 |
+
# with st.expander("📋 Citation"):
|
| 511 |
+
# st.markdown(
|
| 512 |
+
# """
|
| 513 |
+
# If you find this tool useful for you, please cite our paper: **[AdaDetectGPT: Adaptive Detection of LLM-Generated Text with Statistical Guarantees](https://arxiv.org/abs/2510.01268)**
|
| 514 |
+
# """
|
| 515 |
+
# )
|
| 516 |
# st.code(
|
| 517 |
# """
|
| 518 |
# @inproceedings{zhou2024adadetectgpt,
|
| 519 |
# title={AdaDetectGPT: Adaptive Detection of LLM-Generated Text with Statistical Guarantees},
|
| 520 |
# author={Hongyi Zhou and Jin Zhu and Pingfan Su and Kai Ye and Ying Yang and Shakeel A O B Gavioli-Akilagun and Chengchun Shi},
|
| 521 |
+
# booktitle={The Thirty-Ninth Annual Conference on Neural Information Processing Systems},
|
| 522 |
# year={2025},
|
| 523 |
# }
|
| 524 |
# """,
|
|
|
|
| 550 |
}
|
| 551 |
</style>
|
| 552 |
<div class='footer'>
|
| 553 |
+
<small> This tool is developed for research purposes only. The detection results are not 100% accurate and should not be used as the sole basis for any critical decisions. Users are advised to use this tool responsibly and ethically. </small>
|
| 554 |
</div>
|
| 555 |
""",
|
| 556 |
unsafe_allow_html=True
|