GSridhar1982/EmailSubjectGenerationDemo
0
1import gradio as gr2from transformers import AutoTokenizer, AutoModelForSeq2SeqLM3import nltk4nltk.download('punkt_tab')5nltk.download('wordnet')6nltk.download('omw-1.4')7 8def generate_subject(email_body):9 model_name = 'anukvma/t5-base-medium-email-subject-generation-v2'10 tokenizer = AutoTokenizer.from_pretrained(model_name)11 model = AutoModelForSeq2SeqLM.from_pretrained(model_name)12 inputs = ["provide email subject: " + email_body]13 inputs = tokenizer(inputs, max_length=512, truncation=True, return_tensors="pt")14 output = model.generate(**inputs, num_beams=8, do_sample=True, min_length=1, max_length=10)15 decoded_output = tokenizer.batch_decode(output, skip_special_tokens=True)[0]16 predicted_title = nltk.sent_tokenize(decoded_output.strip())[0]17 return predicted_title18 19 20iface = gr.Interface(21 fn=generate_subject,22 inputs="textbox",23 outputs="textbox",24 title="AIML Email Subject Generator",25 description="Given the email body, it generates the email subject"26)27 28iface.launch()