Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Load the BART model for summarization
|
| 5 |
+
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
| 6 |
+
|
| 7 |
+
# Function to summarize text based on the min and max length
|
| 8 |
+
def summarize_text(text, min_length, max_length):
|
| 9 |
+
# Summarize the input text with the specified min and max length
|
| 10 |
+
summary = summarizer(text, min_length=min_length, max_length=max_length)
|
| 11 |
+
return summary[0]['summary_text']
|
| 12 |
+
|
| 13 |
+
# Create Gradio Interface
|
| 14 |
+
iface = gr.Interface(
|
| 15 |
+
fn=summarize_text, # Function to call for summarization
|
| 16 |
+
inputs=[
|
| 17 |
+
gr.Textbox(label="Enter Text", placeholder="Type or paste a long text here...", lines=10),
|
| 18 |
+
gr.Slider(minimum=10, maximum=50, step=1, label="Minimum Length", value=10),
|
| 19 |
+
gr.Slider(minimum=50, maximum=150, step=1, label="Maximum Length", value=100),
|
| 20 |
+
],
|
| 21 |
+
outputs=gr.Textbox(label="Summarized Text"),
|
| 22 |
+
live=False, # Disable live preview while typing
|
| 23 |
+
description="Text Summarization using BART model. Set minimum and maximum token lengths for the summary."
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
# Launch the interface
|
| 27 |
+
iface.launch()
|