|
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
|
import nltk
|
|
nltk.download('punkt')
|
|
|
|
tokenizer = AutoTokenizer.from_pretrained("anukvma/bart-base-medium-email-subject-generation-v5")
|
|
model = AutoModelForSeq2SeqLM.from_pretrained("anukvma/bart-base-medium-email-subject-generation-v5")
|
|
|
|
text = """
|
|
Harry - I got kicked out of the system, so I'm sending this from Tom's account.
|
|
He can fill you in on the potential deal with STEAG.
|
|
I left my resume on your chair.
|
|
I'll e-mail a copy when I have my home account running.
|
|
My contact info is:
|
|
"""
|
|
|
|
inputs = ["provide email subject: " + text]
|
|
|
|
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]
|
|
|
|
print(predicted_title)
|
|
|
|
def generate_subject(text):
|
|
inputs = ["provide email subject: " + text]
|
|
|
|
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
|
|
|
|
import gradio as gr
|
|
gr.Interface(fn = generate_subject, inputs="text",outputs="text").launch() |