Spaces:
Sleeping
Sleeping
requirements.txt
Browse files
app.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Load summarization pipeline
|
| 5 |
+
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
| 6 |
+
|
| 7 |
+
# Simple keyword-based action classifier
|
| 8 |
+
def classify_action(email_text):
|
| 9 |
+
email_lower = email_text.lower()
|
| 10 |
+
if "meeting" in email_lower or "schedule" in email_lower:
|
| 11 |
+
return "Schedule a meeting"
|
| 12 |
+
elif "question" in email_lower or "reply" in email_lower or "can you" in email_lower:
|
| 13 |
+
return "Reply"
|
| 14 |
+
elif "unsubscribe" in email_lower or "spam" in email_lower:
|
| 15 |
+
return "Delete or Mark as Spam"
|
| 16 |
+
else:
|
| 17 |
+
return "Read and Archive"
|
| 18 |
+
|
| 19 |
+
# Main function
|
| 20 |
+
def summarize_and_recommend(email_text):
|
| 21 |
+
if not email_text.strip():
|
| 22 |
+
return "No content provided.", "No action"
|
| 23 |
+
|
| 24 |
+
# Summarize
|
| 25 |
+
summary = summarizer(email_text, max_length=130, min_length=30, do_sample=False)[0]['summary_text']
|
| 26 |
+
|
| 27 |
+
# Recommend action
|
| 28 |
+
action = classify_action(email_text)
|
| 29 |
+
|
| 30 |
+
return summary, action
|
| 31 |
+
|
| 32 |
+
# Gradio UI
|
| 33 |
+
iface = gr.Interface(
|
| 34 |
+
fn=summarize_and_recommend,
|
| 35 |
+
inputs=gr.Textbox(lines=15, placeholder="Paste your email content here..."),
|
| 36 |
+
outputs=[
|
| 37 |
+
gr.Textbox(label="Summary"),
|
| 38 |
+
gr.Textbox(label="Suggested Action")
|
| 39 |
+
],
|
| 40 |
+
title="📩 Smart Email Summarizer & Action Recommender",
|
| 41 |
+
description="Paste an email to get a quick summary and an action suggestion. Uses Hugging Face's BART model for summarization.",
|
| 42 |
+
theme="default"
|
| 43 |
+
)
|
| 44 |
+
|
| 45 |
+
iface.launch()
|