|
import gradio as gr |
|
from transformers import pipeline |
|
|
|
import re |
|
|
|
pipe = pipeline("summarization", model="kkasiviswanath/bart_summarizer_deploy_v1") |
|
|
|
def summarize_email(email_body, pipe): |
|
|
|
input_tokens = pipe.tokenizer(email_body, return_tensors='pt', truncation=False) |
|
input_length = input_tokens['input_ids'].shape[1] |
|
|
|
|
|
adjusted_max_length = max(3, int(input_length * 0.6)) |
|
|
|
gen_kwargs = { |
|
"length_penalty": 2.0, |
|
"num_beams": 5, |
|
"max_length": adjusted_max_length, |
|
"min_length": 3 |
|
} |
|
|
|
summary = pipe(email_body, **gen_kwargs)[0]['summary_text'] |
|
return summary |
|
|
|
|
|
def generate_summary(text): |
|
email_body = re.sub(r'\s+', ' ', re.sub(r'[^\w\s]', '', text).strip()) |
|
summary = summarize_email(email_body, pipe) |
|
return summary |
|
|
|
def greet(name): |
|
return "Hello " + name + "!!" |
|
|
|
demo = gr.Interface(fn=generate_summary, inputs="text", outputs="text") |
|
demo.launch(share=True) |