RJ3vans commited on
Commit
a4edf26
Β·
verified Β·
1 Parent(s): a188c54

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -10
app.py CHANGED
@@ -1991,17 +1991,55 @@ with gr.Blocks(title="Syntactic Sentence Simplifier") as demo:
1991
  btn = gr.Button("Process & Simplify", variant="primary")
1992
  btn.click(fn=process_text, inputs=input_text, outputs=output_text)
1993
 
1994
- gr.Examples(
1995
- examples=[
1996
- ["John kicked the ball and walked to Leeds."],
1997
- ["John is one test, Mary, who lives in London, loves exams, and Bill eats bread."],
1998
- ["John went to Wolverhampton, Bill set out for Coventry, and Mary returned from Birmingham."],
1999
- ["John, who lives in London, is going to Wolverhampton, and Mary, who is a bit nervous, adores Birmingham."],
2000
- ["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."],
2001
- ],
2002
- inputs=input_text,
2003
- label="Try an example",
 
2004
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2005
  # ↑↑↑ END OF UI ↑↑↑
2006
 
2007
  print("Gradio interface ready. Starting web server...")
 
1991
  btn = gr.Button("Process & Simplify", variant="primary")
1992
  btn.click(fn=process_text, inputs=input_text, outputs=output_text)
1993
 
1994
+ input_text = gr.Textbox(
1995
+ lines=10,
1996
+ label="Original text",
1997
+ placeholder="Paste your text here, or add examples below...",
1998
+ elem_classes=["input-text"],
1999
+ )
2000
+
2001
+ output_text = gr.Textbox(
2002
+ lines=10,
2003
+ label="Simplified text",
2004
+ elem_classes=["output-text"],
2005
  )
2006
+
2007
+ btn = gr.Button("Process & Simplify", variant="primary")
2008
+ btn.click(fn=process_text, inputs=input_text, outputs=output_text)
2009
+
2010
+ EXAMPLE_SENTENCES = [
2011
+ "John kicked the ball and walked to Leeds.",
2012
+ "John is one test, Mary, who lives in London, loves exams, and Bill eats bread.",
2013
+ "John went to Wolverhampton, Bill set out for Coventry, and Mary returned from Birmingham.",
2014
+ "John, who lives in London, is going to Wolverhampton, and Mary, who is a bit nervous, adores Birmingham.",
2015
+ "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.",
2016
+ ]
2017
+
2018
+ def append_example(current_text, example):
2019
+ """Add example to the box; separate multiple examples with a blank line."""
2020
+ example = (example or "").strip()
2021
+ if not example:
2022
+ return current_text or ""
2023
+ current = (current_text or "").strip()
2024
+ if not current:
2025
+ return example
2026
+ return current + "\n\n" + example
2027
+
2028
+ gr.Markdown("### Try an example (each click **adds** it to the box)")
2029
+
2030
+ with gr.Row():
2031
+ clear_btn = gr.Button("Clear input", size="sm")
2032
+ clear_btn.click(fn=lambda: "", inputs=None, outputs=input_text)
2033
+
2034
+ for ex in EXAMPLE_SENTENCES:
2035
+ label = ex if len(ex) <= 90 else ex[:87] + "..."
2036
+ ex_btn = gr.Button(label, size="sm")
2037
+ # default-arg captures this sentence (avoids classic loop-closure bug)
2038
+ ex_btn.click(
2039
+ fn=lambda current, s=ex: append_example(current, s),
2040
+ inputs=input_text,
2041
+ outputs=input_text,
2042
+ )
2043
  # ↑↑↑ END OF UI ↑↑↑
2044
 
2045
  print("Gradio interface ready. Starting web server...")