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()