Spaces:
Running
Running
Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -357,6 +357,54 @@ def preview_all_styles(text: str) -> str:
|
|
| 357 |
return '\n'.join(lines)
|
| 358 |
|
| 359 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 360 |
# =============================================================================
|
| 361 |
# Gradio Interface
|
| 362 |
# =============================================================================
|
|
@@ -385,8 +433,16 @@ def create_demo():
|
|
| 385 |
text_input = gr.Textbox(
|
| 386 |
label="Input Text",
|
| 387 |
lines=3,
|
| 388 |
-
placeholder="Enter a claim or statement
|
| 389 |
-
value="
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 390 |
)
|
| 391 |
|
| 392 |
with gr.Row():
|
|
@@ -422,6 +478,20 @@ def create_demo():
|
|
| 422 |
status_output = gr.Textbox(label="Result", lines=2)
|
| 423 |
result_state = gr.State("")
|
| 424 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 425 |
run_btn.click(
|
| 426 |
fn=run_attack,
|
| 427 |
inputs=[text_input, style_dropdown, model_dropdown, task_dropdown],
|
|
|
|
| 357 |
return '\n'.join(lines)
|
| 358 |
|
| 359 |
|
| 360 |
+
# =============================================================================
|
| 361 |
+
# Sample Sentences (from actual experiment datasets)
|
| 362 |
+
# =============================================================================
|
| 363 |
+
|
| 364 |
+
SAMPLE_SENTENCES = {
|
| 365 |
+
'fact_verification': [
|
| 366 |
+
"Sea level rise due to global warming is exaggerated.",
|
| 367 |
+
"CO2 is increasing rapidly, and is reaching levels not seen on the earth for millions of years.",
|
| 368 |
+
"Antarctica is too cold to lose ice.",
|
| 369 |
+
"Greenhouse gases have been the main contributor of warming since 1970.",
|
| 370 |
+
"The polar bear population has been growing.",
|
| 371 |
+
"Renewables can't provide baseload power",
|
| 372 |
+
"Sea ice has diminished much faster than scientists and climate models anticipated.",
|
| 373 |
+
"Arctic sea ice extent was lower in the past.",
|
| 374 |
+
"A large amount of warming is delayed, and if we don't act now we could pass tipping points.",
|
| 375 |
+
"Clouds provide negative feedback.",
|
| 376 |
+
],
|
| 377 |
+
'argument_mining': [
|
| 378 |
+
"proponents of concealed carry say that criminals are less likely to attack someone they believe to be armed .",
|
| 379 |
+
"the right to not be killed supersedes the right to not be pregnant .",
|
| 380 |
+
"marijuana is less addictive than tobacco or alcohol , and compares favorably to those drugs on nearly every health metric .",
|
| 381 |
+
"nuclear wastes as , or in , spent fuel are an unresolved problem .",
|
| 382 |
+
"humans should not be turned into an experimental playground .",
|
| 383 |
+
"higher prices lead to decreased demand , which can have a depressive effect on the economy .",
|
| 384 |
+
"abortion is condemnable for the same reasons that slavery and genocide are .",
|
| 385 |
+
"students can wear a variety of expressive items , such as buttons or jewlery .",
|
| 386 |
+
"so where does all of this leave us ?",
|
| 387 |
+
"diseases which have dogged us for generations could be wiped out due to our evolving faster than they could ever hope to .",
|
| 388 |
+
],
|
| 389 |
+
}
|
| 390 |
+
|
| 391 |
+
|
| 392 |
+
def get_sample_choices(task):
|
| 393 |
+
"""Return dropdown choices for the selected task."""
|
| 394 |
+
sentences = SAMPLE_SENTENCES.get(task, SAMPLE_SENTENCES['fact_verification'])
|
| 395 |
+
return gr.update(
|
| 396 |
+
choices=[(s[:80] + "..." if len(s) > 80 else s, s) for s in sentences],
|
| 397 |
+
value=None,
|
| 398 |
+
)
|
| 399 |
+
|
| 400 |
+
|
| 401 |
+
def fill_from_sample(sample):
|
| 402 |
+
"""Fill the text input when a sample is selected."""
|
| 403 |
+
if sample:
|
| 404 |
+
return sample
|
| 405 |
+
return gr.update()
|
| 406 |
+
|
| 407 |
+
|
| 408 |
# =============================================================================
|
| 409 |
# Gradio Interface
|
| 410 |
# =============================================================================
|
|
|
|
| 433 |
text_input = gr.Textbox(
|
| 434 |
label="Input Text",
|
| 435 |
lines=3,
|
| 436 |
+
placeholder="Enter a claim or statement, or pick one from the samples below...",
|
| 437 |
+
value="Sea level rise due to global warming is exaggerated.",
|
| 438 |
+
)
|
| 439 |
+
|
| 440 |
+
sample_dropdown = gr.Dropdown(
|
| 441 |
+
choices=[(s[:80] + "..." if len(s) > 80 else s, s)
|
| 442 |
+
for s in SAMPLE_SENTENCES['fact_verification']],
|
| 443 |
+
label="Sample Sentences (from experiment datasets)",
|
| 444 |
+
value=None,
|
| 445 |
+
interactive=True,
|
| 446 |
)
|
| 447 |
|
| 448 |
with gr.Row():
|
|
|
|
| 478 |
status_output = gr.Textbox(label="Result", lines=2)
|
| 479 |
result_state = gr.State("")
|
| 480 |
|
| 481 |
+
# Wire up sample dropdown → text input
|
| 482 |
+
sample_dropdown.change(
|
| 483 |
+
fn=fill_from_sample,
|
| 484 |
+
inputs=[sample_dropdown],
|
| 485 |
+
outputs=[text_input],
|
| 486 |
+
)
|
| 487 |
+
|
| 488 |
+
# Wire up task change → update sample dropdown choices
|
| 489 |
+
task_dropdown.change(
|
| 490 |
+
fn=get_sample_choices,
|
| 491 |
+
inputs=[task_dropdown],
|
| 492 |
+
outputs=[sample_dropdown],
|
| 493 |
+
)
|
| 494 |
+
|
| 495 |
run_btn.click(
|
| 496 |
fn=run_attack,
|
| 497 |
inputs=[text_input, style_dropdown, model_dropdown, task_dropdown],
|