| | import gradio as gr |
| | from transformers import pipeline, AutoModelForSeq2SeqLM, AutoTokenizer |
| |
|
| | |
| | model_name = "t5-base" |
| | model = AutoModelForSeq2SeqLM.from_pretrained(model_name) |
| | tokenizer = AutoTokenizer.from_pretrained(model_name) |
| |
|
| | |
| | summarizer = pipeline('text2text-generation', model=model, tokenizer=tokenizer) |
| |
|
| | |
| | def summarize_text(text): |
| | result = summarizer(text, max_length=100, min_length=30, do_sample=False)[0] |
| | summary = result['generated_text'].strip() |
| | return summary |
| |
|
| | iface = gr.Interface(fn=summarize_text, inputs="text", outputs="text", |
| | title="Text Summarization with Hugging Face and Gradio", |
| | description="Enter text to summarize.") |
| |
|
| | |
| | iface.launch() |
| |
|