File size: 1,470 Bytes
4ebd421
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
36
37
38
39
40
41
42
43
44
45
46
import gradio as gr
from transformers import pipeline

# Load summarization pipeline
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")

# Simple keyword-based action classifier
def classify_action(email_text):
    email_lower = email_text.lower()
    if "meeting" in email_lower or "schedule" in email_lower:
        return "Schedule a meeting"
    elif "question" in email_lower or "reply" in email_lower or "can you" in email_lower:
        return "Reply"
    elif "unsubscribe" in email_lower or "spam" in email_lower:
        return "Delete or Mark as Spam"
    else:
        return "Read and Archive"

# Main function
def summarize_and_recommend(email_text):
    if not email_text.strip():
        return "No content provided.", "No action"

    # Summarize
    summary = summarizer(email_text, max_length=130, min_length=30, do_sample=False)[0]['summary_text']
    
    # Recommend action
    action = classify_action(email_text)

    return summary, action

# Gradio UI
iface = gr.Interface(
    fn=summarize_and_recommend,
    inputs=gr.Textbox(lines=15, placeholder="Paste your email content here..."),
    outputs=[
        gr.Textbox(label="Summary"),
        gr.Textbox(label="Suggested Action")
    ],
    title="📩 Smart Email Summarizer & Action Recommender",
    description="Paste an email to get a quick summary and an action suggestion. Uses Hugging Face's BART model for summarization.",
    theme="default"
)

iface.launch()