|
import gradio as gr |
|
from huggingface_hub import InferenceClient |
|
import gradio as gr |
|
from transformers import pipeline |
|
|
|
|
|
pipe = pipeline("summarization", model="paramasivan27/t5small_for_email_summarization_enron") |
|
|
|
|
|
def summarize_email(email_body): |
|
|
|
pipeline = pipe |
|
input_tokens = pipeline.tokenizer(email_body, return_tensors='pt', truncation=False) |
|
input_length = input_tokens['input_ids'].shape[1] |
|
|
|
|
|
adjusted_max_length = max(10, int(input_length * 0.6)) |
|
|
|
|
|
gen_kwargs = { |
|
"length_penalty": 2.0, |
|
"num_beams": 4, |
|
"max_length": adjusted_max_length, |
|
"min_length": 3 |
|
} |
|
|
|
summary = pipeline(email_body, **gen_kwargs)[0]['summary_text'] |
|
return summary |
|
|
|
|
|
iface = gr.Interface( |
|
fn=summarize_email, |
|
inputs=gr.Textbox(lines=10, placeholder="Enter the email body here..."), |
|
outputs="text", |
|
title="Email Subject Line Generator", |
|
description="Generate a subject line from an email body using T5 Small" |
|
) |
|
|
|
|
|
iface.launch() |
|
|
|
if __name__ == "__main__": |
|
demo.launch() |