File size: 1,491 Bytes
14aa639
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
29
30
31
32
33
34
35
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()