|
import gradio as gr |
|
from transformers import AutoTokenizer,MT5ForConditionalGeneration |
|
|
|
|
|
tokenizer = AutoTokenizer.from_pretrained("Adarsh203/Nepali_Abstractive_News_Summarizer_mT5") |
|
model = MT5ForConditionalGeneration.from_pretrained("Adarsh203/Nepali_Abstractive_News_Summarizer_mT5") |
|
|
|
|
|
def summary(text): |
|
|
|
input_ids = tokenizer(text, return_tensors="pt", max_length=1024, truncation=True).input_ids |
|
|
|
|
|
max_summary_length = 150 |
|
summary_ids = model.generate(input_ids, max_length=max_summary_length, max_new_tokens=max_summary_length) |
|
|
|
|
|
generated_summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True) |
|
|
|
return generated_summary |
|
|
|
|
|
gr.Interface( |
|
fn=summary, |
|
inputs="textbox", |
|
outputs="textbox", |
|
title="Nepali News Summarize", |
|
description="Summarize the Nepali News Articles", |
|
theme="compact" |
|
).launch() |