import gradio as gr import transformers model_name = "t5-small" tokenizer = transformers.T5Tokenizer.from_pretrained(model_name) model = transformers.T5ForCausalLM.from_pretrained(model_name) def summarize_text(text, max_length): input_ids = tokenizer.encode(text, return_tensors='pt', max_length=512) summary_ids = model.generate(input_ids, max_length=max_length, num_beams=4, early_stopping=True) return tokenizer.decode(summary_ids[0], skip_special_tokens=True) iface = gr.Interface( fn=summarize_text, inputs=gr.inputs.Textbox(lines=5, default="Enter your text here"), outputs=gr.outputs.Textbox(lines=3, default="Summary will appear here"), parameters={ "max_length": gr.inputs.Slider(default=50, min_value=20, max_value=200, step=10, label="Summary Length") }, title="Text Summarization with T5", description="Generate a brief summary of the input text using the T5 model." ) iface.launch()