|
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() |
|
|