File size: 815 Bytes
a0c89bd 9560ced 08e111b | 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 | import gradio as gr
from transformers import pipeline, AutoTokenizer, AutoModelForSeq2SeqLM
model_name = "t5-base"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
summarization = pipeline("summarization", model=model, tokenizer=tokenizer)
def generate_summary(text):
summary = summarization(text, max_length=100, min_length=25, do_sample=False)
return summary[0]["summary_text"]
input_text = gr.inputs.Textbox(lines=5, placeholder="Enter your text here...")
output_text = gr.outputs.Textbox(label="Summary")
iface = gr.Interface(
fn=generate_summary,
inputs=input_text,
outputs=output_text,
title="Text Summarization",
description="Enter your text and get a summary using the Hugging Face T5 model.",
)
iface.launch()
|