File size: 1,044 Bytes
643664d 964dcd3 643664d 964dcd3 254780b 964dcd3 |
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 26 27 28 29 30 |
import gradio as gr
from transformers import AutoTokenizer,MT5ForConditionalGeneration
#loading tokenzier and model
tokenizer = AutoTokenizer.from_pretrained("Adarsh203/Nepali_Abstractive_News_Summarizer_mT5")
model = MT5ForConditionalGeneration.from_pretrained("Adarsh203/Nepali_Abstractive_News_Summarizer_mT5")
# Define the summary function
def summary(text):
# Tokenize the input text
input_ids = tokenizer(text, return_tensors="pt", max_length=1024, truncation=True).input_ids
# Generate the summary
max_summary_length = 150
summary_ids = model.generate(input_ids, max_length=max_summary_length, max_new_tokens=max_summary_length)
# Decode the generated summary
generated_summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
return generated_summary
#create and launch the gradio interface
gr.Interface(
fn=summary,
inputs="textbox",
outputs="textbox",
title="Nepali News Summarize",
description="Summarize the Nepali News Articles",
theme="compact"
).launch() |