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