Spaces:
Sleeping
Sleeping
File size: 1,984 Bytes
d1d897c 2ee6023 d1d897c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
import gradio as gr
from transformers import pipeline
def summarizer(sentence, min_length, max_length):
model_name = "AirrStorm/T5-Small-XSUM-Summarizer"
# Create a summarization pipeline with the local model
summarizer = pipeline("summarization", model=model_name, tokenizer=model_name)
summary = summarizer(
sentence,
max_length=int(max_length), # Convert to int for Gradio input compatibility
min_length=int(min_length), # Convert to int for Gradio input compatibility
length_penalty=1.2, # Length penalty for beam search
num_beams=4, # Number of beams for beam search
early_stopping=True # Stop early when an optimal summary is found
)
return summary[0]["summary_text"]
# Define inputs for the Gradio interface with better layout and styling
inputs = [
gr.Textbox(
label="Input Text",
lines=10,
placeholder="Enter the text to summarize here...",
interactive=True,
elem_id="input_text_box"
),
gr.Number(
label="Minimum Length",
value=50,
precision=0,
interactive=True,
elem_id="min_length"
),
gr.Number(
label="Maximum Length",
value=200,
precision=0,
interactive=True,
elem_id="max_length"
),
]
# Define the Gradio interface
demo = gr.Interface(
fn=summarizer,
inputs=inputs,
outputs=gr.Textbox(
label="Summary",
lines=6,
placeholder="Your summary will appear here.",
interactive=False,
elem_id="output_summary"
),
title="Text Summarization Tool",
description="Provide a text input, specify the minimum and maximum lengths for the summary, and get a concise version of your text.",
theme="huggingface", # Optional, you can change to other themes like 'compact'
allow_flagging="never", # Disable flagging
)
# Launch the interface with shareable link
demo.launch(share=True)
|