RJ3vans commited on
Commit
2ebac58
Β·
verified Β·
1 Parent(s): 1757b7a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -29
app.py CHANGED
@@ -1972,41 +1972,31 @@ custom_css = """
1972
 
1973
  with gr.Blocks(title="Syntactic Sentence Simplifier") as demo:
1974
  gr.Markdown("# Syntactic Sentence Simplifier")
1975
- gr.Markdown("Paste text or pick an example, then click Process & Simplify.")
1976
-
1977
- # ↓↓↓ THIS BLOCK GOES HERE ↓↓↓
1978
- input_text = gr.Textbox(
1979
- lines=10,
1980
- label="Original text",
1981
- placeholder="Paste your text here, or pick an example below...",
1982
- elem_classes=["input-text"],
1983
- )
1984
-
1985
- output_text = gr.Textbox(
1986
- lines=10,
1987
- label="Simplified text",
1988
- elem_classes=["output-text"],
1989
  )
1990
 
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.",
@@ -2016,7 +2006,6 @@ with gr.Blocks(title="Syntactic Sentence Simplifier") as demo:
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 ""
@@ -2025,22 +2014,19 @@ with gr.Blocks(title="Syntactic Sentence Simplifier") as demo:
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...")
2046
 
 
1972
 
1973
  with gr.Blocks(title="Syntactic Sentence Simplifier") as demo:
1974
  gr.Markdown("# Syntactic Sentence Simplifier")
1975
+ gr.Markdown(
1976
+ "Paste text, or click examples to **add** them into the box below "
1977
+ "(you can edit the text afterwards)."
 
 
 
 
 
 
 
 
 
 
 
1978
  )
1979
 
1980
+ # --- ONLY input box (editable) ---
 
 
1981
  input_text = gr.Textbox(
1982
+ lines=12,
1983
  label="Original text",
1984
  placeholder="Paste your text here, or add examples below...",
1985
  elem_classes=["input-text"],
1986
  )
1987
 
1988
+ # --- ONLY output box ---
1989
  output_text = gr.Textbox(
1990
+ lines=12,
1991
  label="Simplified text",
1992
  elem_classes=["output-text"],
1993
  )
1994
 
1995
+ # --- ONLY process button ---
1996
  btn = gr.Button("Process & Simplify", variant="primary")
1997
  btn.click(fn=process_text, inputs=input_text, outputs=output_text)
1998
 
1999
+ # --- Examples: buttons that APPEND into input_text (same box) ---
2000
  EXAMPLE_SENTENCES = [
2001
  "John kicked the ball and walked to Leeds.",
2002
  "John is one test, Mary, who lives in London, loves exams, and Bill eats bread.",
 
2006
  ]
2007
 
2008
  def append_example(current_text, example):
 
2009
  example = (example or "").strip()
2010
  if not example:
2011
  return current_text or ""
 
2014
  return example
2015
  return current + "\n\n" + example
2016
 
2017
+ gr.Markdown("### Add an example to the box above (click to append; then edit freely)")
2018
 
2019
+ clear_btn = gr.Button("Clear input", size="sm")
2020
+ clear_btn.click(fn=lambda: "", outputs=input_text)
 
2021
 
2022
  for ex in EXAMPLE_SENTENCES:
2023
+ label = ex if len(ex) <= 100 else ex[:97] + "..."
2024
  ex_btn = gr.Button(label, size="sm")
 
2025
  ex_btn.click(
2026
  fn=lambda current, s=ex: append_example(current, s),
2027
+ inputs=input_text, # read current box
2028
+ outputs=input_text, # write back to SAME box
2029
  )
 
2030
 
2031
  print("Gradio interface ready. Starting web server...")
2032