liamvbetts commited on
Commit
9b95b6c
1 Parent(s): 5d174b9

working interface

Browse files
Files changed (1) hide show
  1. app.py +14 -14
app.py CHANGED
@@ -17,22 +17,22 @@ def summarize(article):
17
  def get_random_article():
18
  random.seed()
19
  val_example = dataset["validation"].shuffle().select(range(1))
20
- val_article = val_example['article'][0][:512]
21
  return val_article
22
 
23
- def update_article_input():
24
  return get_random_article()
25
 
26
- # Create Gradio interface
27
- input_text = gr.Textbox(lines=10, label="Input Text", value="")
28
- output_text = gr.Textbox(label="Summary")
29
- load_article_button = gr.Button("Load Random Article")
 
 
 
 
 
 
 
30
 
31
- gr.Interface(
32
- fn=summarize,
33
- inputs=[input_text, load_article_button],
34
- outputs=output_text,
35
- title="News Summary App",
36
- description="Enter a news text and get its summary, or load a random article from the validation set.",
37
- live=True
38
- ).add_event("click", update_article_input, inputs=None, outputs=input_text, elem_id=load_article_button.elem_id).launch()
 
17
  def get_random_article():
18
  random.seed()
19
  val_example = dataset["validation"].shuffle().select(range(1))
20
+ val_article = val_example['article'][0][:1024]
21
  return val_article
22
 
23
+ def load_article():
24
  return get_random_article()
25
 
26
+ # Using Gradio Blocks
27
+ with gr.Blocks() as demo:
28
+ gr.Markdown("## News Summary App")
29
+ gr.Markdown("Enter a news text and get its summary, or load a random article from the validation set.")
30
+ with gr.Row():
31
+ input_text = gr.Textbox(lines=10, label="Input Text")
32
+ output_text = gr.Textbox(label="Summary")
33
+ load_article_button = gr.Button("Load Random Article")
34
+ load_article_button.click(fn=load_article, inputs=[], outputs=input_text)
35
+ summarize_button = gr.Button("Summarize")
36
+ summarize_button.click(fn=summarize, inputs=input_text, outputs=output_text)
37
 
38
+ demo.launch()