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)