RJ3vans commited on
Commit
76f1202
·
verified ·
1 Parent(s): 34042b9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +84 -16
app.py CHANGED
@@ -2454,7 +2454,7 @@ def process_text(input_text):
2454
  # Main processing function (encapsulates the pipeline)
2455
 
2456
  # ================== GRADIO INTERFACE ===================
2457
- print(" All three models loaded successfully!")
2458
  print("Creating Gradio interface...")
2459
 
2460
  custom_css = """
@@ -2495,37 +2495,105 @@ custom_css = """
2495
  }
2496
  """
2497
 
2498
- with gr.Blocks(
2499
- title="Syntactic Sentence Simplifier",
2500
- css=custom_css,
2501
- ) as demo:
2502
  gr.Markdown("# Syntactic Sentence Simplifier")
2503
  gr.Markdown(
2504
- "Paste or type your text below. Uses Hugging Face models + simplification logic."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2505
  )
2506
 
 
 
2507
  input_text = gr.Textbox(
2508
- lines=10,
2509
  label="Original text",
2510
- placeholder="Paste your text here...",
2511
  elem_classes=["input-text"],
2512
  )
2513
 
 
 
 
 
2514
  output_text = gr.Textbox(
2515
- lines=10,
2516
  label="Simplified text",
2517
  elem_classes=["output-text"],
2518
  )
2519
 
2520
- btn = gr.Button("Process & Simplify", variant="primary")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2521
 
2522
- btn.click(
2523
- fn=process_text,
2524
- inputs=input_text,
2525
- outputs=output_text,
2526
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2527
 
2528
- print(" Gradio interface ready. Starting web server...")
2529
 
2530
  if __name__ == "__main__":
2531
  demo.launch(
 
2454
  # Main processing function (encapsulates the pipeline)
2455
 
2456
  # ================== GRADIO INTERFACE ===================
2457
+ print(" All seven models loaded successfully!")
2458
  print("Creating Gradio interface...")
2459
 
2460
  custom_css = """
 
2495
  }
2496
  """
2497
 
2498
+ with gr.Blocks(title="Syntactic Sentence Simplifier") as demo:
 
 
 
2499
  gr.Markdown("# Syntactic Sentence Simplifier")
2500
  gr.Markdown(
2501
+ """
2502
+ This demo simplifies sentences containing compound constituents:
2503
+
2504
+ * *clauses*
2505
+ * *verb phrases*
2506
+ * *noun phrases*
2507
+ * *nouns*
2508
+
2509
+ and complex noun phrases modified by:
2510
+
2511
+ * *nominally bound non-restrictive finite relative clauses (subject relativised and verb/preposition object relativised)*
2512
+ * *nominally bound non-restrictive non-finite nominal clauses*
2513
+
2514
+ Paste text, or click examples to **add** them into the box below
2515
+ (you can edit the text afterwards).
2516
+ """
2517
  )
2518
 
2519
+
2520
+ # 1) Complex input
2521
  input_text = gr.Textbox(
2522
+ lines=12,
2523
  label="Original text",
2524
+ placeholder="Paste your text here, or add examples below...",
2525
  elem_classes=["input-text"],
2526
  )
2527
 
2528
+ # 2) Bridge button (directly under input)
2529
+ btn = gr.Button("Process & Simplify", variant="primary")
2530
+
2531
+ # 3) Simple output
2532
  output_text = gr.Textbox(
2533
+ lines=12,
2534
  label="Simplified text",
2535
  elem_classes=["output-text"],
2536
  )
2537
 
2538
+ btn.click(fn=process_text, inputs=input_text, outputs=output_text)
2539
+
2540
+ # Examples / clear (under the whole stack, or under input if you prefer)
2541
+ EXAMPLE_SENTENCES = [
2542
+ "John kicked the ball and walked to Leeds.",
2543
+ "John bought two apples and three oranges.",
2544
+ "John left early and Mary stayed late.",
2545
+ "John, who lives in London, went home.",
2546
+ "Peter, who Sam likes, went home.",
2547
+ "Fred bought a computer and a printer and switched them on.",
2548
+ "Fred bought a computer and a printer, and Mary bought a PS5.",
2549
+ "Mary, who lives in London, went home, and Peter stayed.",
2550
+ "John, who kicked the ball and walked away, went home.",
2551
+ "John, who bought a computer and a printer, went home.",
2552
+ "John, who Steven tolerated and who mary despised, went home.",
2553
+ "John, who lives in Shifnal, which is a town in the Black Country, went home.",
2554
+ "Mary, who lives in London, kicked the ball and walked to Leeds, and John stayed home.",
2555
+ "Jackie, who lives in Manchester, bought a computer and a monitor, and Fred bought bread.",
2556
+ "Count Binface bought two apples and three pears and ate them, and Nigel left.",
2557
+ "Count Binface, who bought two apples and three pears and ate them, went home.",
2558
+ "Hadric Wode, who bought a mace and a shield and used them, left early, and Fenric, who was tired, stayed home.",
2559
+ "John is one candidate, Mary ignores signals, and Bill eats grass.",
2560
+ "John went to Essex, Bill set out for Sussex, and Mary returned from Halifax.",
2561
+ "Joshua told me that John, who lives in New York, is going to London, Jack loves Norwich, and Mary, who is extremely confident, adores Milton Keynes, just as Fred predicted.",
2562
+ "John kicked the ball and walked to Leeds, and Peter stayed home.",
2563
+ "John is one test, Mary, who lives in London, loves exams, and Bill eats bread.",
2564
+ "John went to Wolverhampton, Bill set out for Coventry, and Mary returned from Birmingham.",
2565
+ "John, who lives in London, is going to Wolverhampton, and Mary, who is a bit nervous, adores Birmingham.",
2566
+ "John kicked the ball and walked to Leeds. Mary bought a laptop and a mousemat.",
2567
+ "I love France.",
2568
+ "John met the dog, the cat, and the tortoise.",
2569
+ "The Environment Agency said record winter rainfall had helped to replenish reservoirs and groundwater, but reservoir storage has now fallen to 7.4% below the average for this time of year.",
2570
+ "The man and his dog, who live in Wolverhampton, the English city, went home and Mary ran a marathon and smoked cigars and cigarettes.",
2571
+ ]
2572
 
2573
+ def append_example(current_text, example):
2574
+ example = (example or "").strip()
2575
+ if not example:
2576
+ return current_text or ""
2577
+ current = (current_text or "").strip()
2578
+ if not current:
2579
+ return example
2580
+ return current + "\n\n" + example
2581
+
2582
+ gr.Markdown("### Add an example to the box above (click to append; then edit freely)")
2583
+
2584
+ clear_btn = gr.Button("Clear input", size="sm")
2585
+ clear_btn.click(fn=lambda: "", outputs=input_text)
2586
+
2587
+ for ex in EXAMPLE_SENTENCES:
2588
+ label = ex if len(ex) <= 100 else ex[:97] + "..."
2589
+ ex_btn = gr.Button(label, size="sm")
2590
+ ex_btn.click(
2591
+ fn=lambda current, s=ex: append_example(current, s),
2592
+ inputs=input_text,
2593
+ outputs=input_text,
2594
+ )
2595
 
2596
+ print("Gradio interface ready. Starting web server...")
2597
 
2598
  if __name__ == "__main__":
2599
  demo.launch(