AroojImtiaz commited on
Commit
97f7894
1 Parent(s): e6de700

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -18
app.py CHANGED
@@ -1,25 +1,37 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
- # Initialize the summarization pipeline with a specified model
5
- text_summary = pipeline("summarization", model="sshleifer/distilbart-cnn-12-6")
6
 
7
- def summarize_text(input_text):
8
- """Function to summarize the input text."""
9
- summary_result = text_summary(input_text)
10
- return summary_result[0]['summary_text']
 
 
 
 
 
 
 
 
 
11
 
12
- # Close any existing Gradio interfaces
13
- gr.close_all()
14
-
15
- # Define a Gradio interface for the summarization function
16
- demo = gr.Interface(
17
- fn=summarize_text,
18
- inputs=gr.Textbox(label="Input text to summarize", lines=10, placeholder="Enter your text here..."),
19
- outputs=gr.Textbox(label="Summarized text", lines=4),
20
- title="Text Summarizer",
21
- description="This application summarizes text. Just paste your text and get a summary!"
 
 
 
 
22
  )
23
 
24
- # Launch the Gradio interface
25
- demo.launch()
 
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
+ # Model options available for summarization
5
+ model_names = ["Falconsai/text_summarization"]
6
 
7
+ def summarize_article(article, model_name, max_length, temperature, top_k, top_p):
8
+ """ Summarize the provided article text using the specified model and hyperparameters. """
9
+ summarizer = pipeline("summarization", model=model_name)
10
+ summary = summarizer(
11
+ article,
12
+ max_length=int(round(max_length)),
13
+ min_length=30,
14
+ do_sample=True,
15
+ temperature=temperature,
16
+ top_k=int(round(top_k)),
17
+ top_p=top_p
18
+ )
19
+ return summary[0]['summary_text']
20
 
21
+ # Gradio interface setup
22
+ iface = gr.Interface(
23
+ fn=summarize_article,
24
+ inputs=[
25
+ gr.Textbox(lines=10, placeholder="Enter the article text here..."),
26
+ gr.Dropdown(choices=model_names, label="Select Model"),
27
+ gr.Slider(minimum=10, maximum=200, step=10, label="Max Length of Summary"),
28
+ gr.Slider(minimum=0.1, maximum=2, step=0.1, label="Temperature for Sampling"),
29
+ gr.Slider(minimum=1, maximum=100, step=1, label="Top-k"),
30
+ gr.Slider(minimum=0.1, maximum=1, step=0.1, label="Top-p")
31
+ ],
32
+ outputs="text",
33
+ title="Text Summarization",
34
+ description="Adjust the parameters below to summarize the article."
35
  )
36
 
37
+ iface.launch(debug=True, share=True)