|
import gradio as gr |
|
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM |
|
import nltk |
|
nltk.download('punkt_tab') |
|
nltk.download('wordnet') |
|
nltk.download('omw-1.4') |
|
|
|
def generate_subject(email_body): |
|
model_name = 'anukvma/t5-base-medium-email-subject-generation-v2' |
|
tokenizer = AutoTokenizer.from_pretrained(model_name) |
|
model = AutoModelForSeq2SeqLM.from_pretrained(model_name) |
|
inputs = ["provide email subject: " + email_body] |
|
inputs = tokenizer(inputs, max_length=512, truncation=True, return_tensors="pt") |
|
output = model.generate(**inputs, num_beams=8, do_sample=True, min_length=1, max_length=10) |
|
decoded_output = tokenizer.batch_decode(output, skip_special_tokens=True)[0] |
|
predicted_title = nltk.sent_tokenize(decoded_output.strip())[0] |
|
return predicted_title |
|
|
|
|
|
iface = gr.Interface( |
|
fn=generate_subject, |
|
inputs="textbox", |
|
outputs="textbox", |
|
title="AIML Email Subject Generator", |
|
description="Given the email body, it generates the email subject" |
|
) |
|
|
|
iface.launch() |