File size: 1,013 Bytes
efa70de
e4e56de
 
b6950f1
dd4459d
 
e4e56de
bfb52c0
8901878
e4e56de
 
 
 
 
 
 
 
 
efa70de
e4e56de
 
8a9c29d
78d06a0
 
 
e4e56de
 
8901878
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
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()