Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -73,98 +73,104 @@ def add_to_history(email, cat, pri, summ):
|
|
| 73 |
}
|
| 74 |
classification_history.append(entry)
|
| 75 |
|
| 76 |
-
|
| 77 |
-
body { background: linear-gradient(120deg, #
|
| 78 |
.gradio-container { background: transparent !important; }
|
| 79 |
-
|
| 80 |
.card-block {
|
| 81 |
-
background: rgba(
|
| 82 |
-
border-radius:
|
| 83 |
-
box-shadow: 0
|
| 84 |
-
padding:
|
| 85 |
-
margin:
|
| 86 |
-
color: #
|
| 87 |
-
border:
|
| 88 |
-
backdrop-filter: blur(
|
| 89 |
}
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
.badge {
|
| 94 |
-
display:inline-block;
|
| 95 |
-
border-radius:999px;
|
| 96 |
-
padding:4px 17px;
|
| 97 |
-
font-weight:600;
|
| 98 |
-
background:linear-gradient(90deg,#2875b5 70%,#17d8ff 120%);
|
| 99 |
-
box-shadow: 0 1px 12px #188ad938;
|
| 100 |
-
color:#fff;
|
| 101 |
-
margin-right:12px;
|
| 102 |
-
font-size:1.02em;
|
| 103 |
}
|
| 104 |
-
.
|
| 105 |
-
.priority-medium { background:linear-gradient(90deg,#f89e36 70%,#f7ea47 120%)!important;color:#222;}
|
| 106 |
-
.priority-low { background:linear-gradient(90deg,#23ac9b 60%,#17f3ad 150%)!important;color:#fff;}
|
| 107 |
.glass-btn {
|
| 108 |
border-radius: 18px !important;
|
| 109 |
-
box-shadow: 0 4px 18px #
|
| 110 |
-
background:linear-gradient(90deg,#336bc0
|
| 111 |
color: #fff !important;
|
| 112 |
letter-spacing: .04em;
|
| 113 |
border: none !important;
|
| 114 |
-
font-size: 1.
|
| 115 |
font-weight: 600;
|
|
|
|
| 116 |
}
|
| 117 |
-
.
|
| 118 |
-
|
| 119 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 120 |
}
|
| 121 |
-
.
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
border-left:
|
| 130 |
-
|
|
|
|
|
|
|
|
|
|
| 131 |
}
|
| 132 |
-
.
|
| 133 |
-
|
| 134 |
-
|
|
|
|
|
|
|
|
|
|
| 135 |
with gr.Row():
|
| 136 |
-
|
| 137 |
-
with gr.Column(scale=5, min_width=390):
|
| 138 |
with gr.Group(elem_id="input-card", elem_classes=["card-block"]):
|
| 139 |
-
gr.Markdown("<
|
| 140 |
-
gr.Markdown("Choose Example
|
| 141 |
with gr.Row():
|
| 142 |
support_button = gr.Button("Support Request")
|
| 143 |
sales_button = gr.Button("Sales Inquiry")
|
| 144 |
finance_button = gr.Button("Finance / Billing")
|
| 145 |
urgent_button = gr.Button("Urgent Incident")
|
| 146 |
spam_button = gr.Button("Spam / Marketing")
|
| 147 |
-
email_box = gr.Textbox(lines=8, label="", placeholder="From: ...\nSubject: ..."
|
| 148 |
-
classify_btn = gr.Button("Classify Email",
|
| 149 |
|
| 150 |
-
|
| 151 |
-
with gr.Column(scale=7, min_width=420):
|
| 152 |
with gr.Group(elem_id="output-card", elem_classes=["card-block"]):
|
| 153 |
-
gr.Markdown("<
|
| 154 |
-
result_labels = gr.Markdown(""
|
| 155 |
recipient = gr.Textbox(label="Suggested Recipient")
|
| 156 |
draft_response = gr.Textbox(lines=5, label="Generated Response Draft")
|
| 157 |
summary = gr.Textbox(label="Summary")
|
| 158 |
action_items = gr.Textbox(lines=3, label="Extracted Action Items")
|
| 159 |
|
| 160 |
-
# History Card
|
| 161 |
with gr.Group(elem_id="history-card", elem_classes=["card-block"]):
|
| 162 |
-
gr.Markdown("<
|
| 163 |
history_radio = gr.Radio([], label="", type="index")
|
| 164 |
load_btn = gr.Button("Load Selected", elem_classes=["glass-btn"])
|
| 165 |
-
copy_btn = gr.Button("Copy Selected", elem_classes=["glass-btn"])
|
| 166 |
|
| 167 |
-
# Example data
|
| 168 |
ex1 = "From: help@company.com\nSubject: Unable to Login\nHi, I can't access my dashboard. Can you help?"
|
| 169 |
ex2 = "From: sales@prospect.com\nSubject: Inquiry about pricing\nHi, Can you send over your latest pricing for enterprise?"
|
| 170 |
ex3 = "From: accounts@supplier.com\nSubject: Invoice #2024-00123 Due Date Reminder\nDear Valued Client, This is a reminder invoice #2024-00123 for $1,500.00 is due..."
|
|
@@ -188,7 +194,10 @@ body { background: linear-gradient(120deg, #131d47 0%, #28398f 50%, #101d42 100%
|
|
| 188 |
add_to_history(email_text, cat, pri, summ)
|
| 189 |
badge = f"<b>Category:</b> <span class='badge'>{cat}</span> <b>Priority:</b> <span class='badge priority-{pri.lower()}'>{pri}</span>"
|
| 190 |
display = [
|
| 191 |
-
f"{h['datetime']}
|
|
|
|
|
|
|
|
|
|
| 192 |
for h in classification_history
|
| 193 |
]
|
| 194 |
return badge, rec, dra, summ, acts, gr.update(choices=display, value=len(display)-1)
|
|
@@ -198,18 +207,12 @@ body { background: linear-gradient(120deg, #131d47 0%, #28398f 50%, #101d42 100%
|
|
| 198 |
return classification_history[idx]["email"]
|
| 199 |
return ""
|
| 200 |
|
| 201 |
-
def copy_history(idx):
|
| 202 |
-
if idx is not None and 0 <= idx < len(classification_history):
|
| 203 |
-
return classification_history[idx]["email"]
|
| 204 |
-
return ""
|
| 205 |
-
|
| 206 |
classify_btn.click(
|
| 207 |
classify_and_render,
|
| 208 |
inputs=[email_box],
|
| 209 |
outputs=[result_labels, recipient, draft_response, summary, action_items, history_radio]
|
| 210 |
)
|
| 211 |
load_btn.click(load_history, inputs=[history_radio], outputs=email_box)
|
| 212 |
-
copy_btn.click(copy_history, inputs=[history_radio], outputs=email_box)
|
| 213 |
|
| 214 |
if __name__ == "__main__":
|
| 215 |
demo.launch()
|
|
|
|
| 73 |
}
|
| 74 |
classification_history.append(entry)
|
| 75 |
|
| 76 |
+
css = """
|
| 77 |
+
body { background: linear-gradient(120deg, #10193a 0%, #175ad7 120%) !important; font-family: 'Inter', 'Segoe UI', Arial, sans-serif;}
|
| 78 |
.gradio-container { background: transparent !important; }
|
|
|
|
| 79 |
.card-block {
|
| 80 |
+
background: rgba(27,36,68,0.96);
|
| 81 |
+
border-radius: 30px;
|
| 82 |
+
box-shadow: 0 6px 42px #0b2269bb, 0 1.5px 0 #186fc055 inset;
|
| 83 |
+
padding: 38px 28px 29px 28px;
|
| 84 |
+
margin: 32px 0;
|
| 85 |
+
color: #fafeff;
|
| 86 |
+
border: 2px solid #2847a46c;
|
| 87 |
+
backdrop-filter: blur(8px);
|
| 88 |
}
|
| 89 |
+
input, textarea, .wrap.svelte-psy7la, .wrap.svelte-1ybjah6 {
|
| 90 |
+
background: rgba(21,28,56,0.91)!important; border:1.5px solid #345ca3e3!important; color:#def1ff!important;
|
| 91 |
+
border-radius: 14px !important; box-shadow: none !important;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
}
|
| 93 |
+
label, .label.svelte-1ybjah6 { color: #70acf8!important; font-size: 1em !important; font-weight: 400;}
|
|
|
|
|
|
|
| 94 |
.glass-btn {
|
| 95 |
border-radius: 18px !important;
|
| 96 |
+
box-shadow: 0 4px 18px #287bef25 !important;
|
| 97 |
+
background: linear-gradient(90deg,#336bc0 60%,#1ae6ff 140%)!important;
|
| 98 |
color: #fff !important;
|
| 99 |
letter-spacing: .04em;
|
| 100 |
border: none !important;
|
| 101 |
+
font-size: 1.11em !important;
|
| 102 |
font-weight: 600;
|
| 103 |
+
padding: 12px 0 10px 0 !important;
|
| 104 |
}
|
| 105 |
+
.card-header {
|
| 106 |
+
font-size: 1.32em;
|
| 107 |
+
font-weight: 800;
|
| 108 |
+
letter-spacing: 0.01em;
|
| 109 |
+
margin: 0 0 15px 0;
|
| 110 |
+
color: #ffffff;
|
| 111 |
+
text-shadow: 0 3px 24px #175ad799;
|
| 112 |
+
display: flex; align-items: center;
|
| 113 |
+
}
|
| 114 |
+
.badge {
|
| 115 |
+
display:inline-block;
|
| 116 |
+
border-radius:999px;
|
| 117 |
+
padding:4px 16px;
|
| 118 |
+
font-weight:600;
|
| 119 |
+
background:linear-gradient(90deg,#2870ee 70%,#13e4fc 140%);
|
| 120 |
+
box-shadow:0 1px 12px #0663fd29;
|
| 121 |
+
color:#fff;
|
| 122 |
+
margin-right:12px;
|
| 123 |
+
font-size:1.05em;
|
| 124 |
+
vertical-align:middle;
|
| 125 |
}
|
| 126 |
+
.priority-high { background:linear-gradient(90deg,#ed4864 60%,#fa4764 150%)!important; color:#fff;}
|
| 127 |
+
.priority-medium { background:linear-gradient(90deg,#f3aa36 70%,#f6ea48 120%)!important;color:#222;}
|
| 128 |
+
.priority-low { background:linear-gradient(90deg,#18cd67 60%,#27f8ac 150%)!important;color:#fff;}
|
| 129 |
+
.history-record {
|
| 130 |
+
background: rgba(35, 54, 90, 0.92);
|
| 131 |
+
color: #e2f5ff;
|
| 132 |
+
margin: 0 0 13px 0;
|
| 133 |
+
border-radius: 14px;
|
| 134 |
+
border-left: 5px solid #10baff;
|
| 135 |
+
padding: 13px 22px 12px 22px;
|
| 136 |
+
box-shadow: 0 2px 12px #08526733;
|
| 137 |
+
transition: box-shadow .2s;
|
| 138 |
+
font-size: 1.01em;
|
| 139 |
}
|
| 140 |
+
.history-record.selected { border-left:7px solid #22eef8; background: rgba(44,86,166,1);}
|
| 141 |
+
.history-record .small { color:#a6c5e7; font-size: .92em;}
|
| 142 |
+
"""
|
| 143 |
+
|
| 144 |
+
with gr.Blocks(css=css) as demo:
|
| 145 |
+
gr.Markdown("<div style='text-align:center; margin:10px 0 16px 0; font-size:2em; letter-spacing:.01em; font-weight:900;color:#fff;'><span style='margin-right:10px;'>📧</span>AI Email Classifier & Router</div>")
|
| 146 |
with gr.Row():
|
| 147 |
+
with gr.Column(scale=5, min_width=410):
|
|
|
|
| 148 |
with gr.Group(elem_id="input-card", elem_classes=["card-block"]):
|
| 149 |
+
gr.Markdown("<div class='card-header'>✉️ Paste Your Email</div>")
|
| 150 |
+
gr.Markdown("<span style='font-size:.95em; color:#a6c5e7;'>Choose Example:</span>")
|
| 151 |
with gr.Row():
|
| 152 |
support_button = gr.Button("Support Request")
|
| 153 |
sales_button = gr.Button("Sales Inquiry")
|
| 154 |
finance_button = gr.Button("Finance / Billing")
|
| 155 |
urgent_button = gr.Button("Urgent Incident")
|
| 156 |
spam_button = gr.Button("Spam / Marketing")
|
| 157 |
+
email_box = gr.Textbox(lines=8, label="", placeholder="From: ...\nSubject: ...")
|
| 158 |
+
classify_btn = gr.Button("Classify Email", elem_classes=["glass-btn"])
|
| 159 |
|
| 160 |
+
with gr.Column(scale=7, min_width=430):
|
|
|
|
| 161 |
with gr.Group(elem_id="output-card", elem_classes=["card-block"]):
|
| 162 |
+
gr.Markdown("""<div class='card-header'>🧮 Classification Results</div>""")
|
| 163 |
+
result_labels = gr.Markdown("")
|
| 164 |
recipient = gr.Textbox(label="Suggested Recipient")
|
| 165 |
draft_response = gr.Textbox(lines=5, label="Generated Response Draft")
|
| 166 |
summary = gr.Textbox(label="Summary")
|
| 167 |
action_items = gr.Textbox(lines=3, label="Extracted Action Items")
|
| 168 |
|
|
|
|
| 169 |
with gr.Group(elem_id="history-card", elem_classes=["card-block"]):
|
| 170 |
+
gr.Markdown("""<div class='card-header'>🕒 Classification History</div>""")
|
| 171 |
history_radio = gr.Radio([], label="", type="index")
|
| 172 |
load_btn = gr.Button("Load Selected", elem_classes=["glass-btn"])
|
|
|
|
| 173 |
|
|
|
|
| 174 |
ex1 = "From: help@company.com\nSubject: Unable to Login\nHi, I can't access my dashboard. Can you help?"
|
| 175 |
ex2 = "From: sales@prospect.com\nSubject: Inquiry about pricing\nHi, Can you send over your latest pricing for enterprise?"
|
| 176 |
ex3 = "From: accounts@supplier.com\nSubject: Invoice #2024-00123 Due Date Reminder\nDear Valued Client, This is a reminder invoice #2024-00123 for $1,500.00 is due..."
|
|
|
|
| 194 |
add_to_history(email_text, cat, pri, summ)
|
| 195 |
badge = f"<b>Category:</b> <span class='badge'>{cat}</span> <b>Priority:</b> <span class='badge priority-{pri.lower()}'>{pri}</span>"
|
| 196 |
display = [
|
| 197 |
+
f"**{h['datetime']}**\n"
|
| 198 |
+
f"**Category:** <span class='badge'>{h['category']}</span> \n"
|
| 199 |
+
f"**Priority:** <span class='badge priority-{h['priority'].lower()}'>{h['priority']}</span> \n"
|
| 200 |
+
f"<span class='small'>{h['summary']}</span>"
|
| 201 |
for h in classification_history
|
| 202 |
]
|
| 203 |
return badge, rec, dra, summ, acts, gr.update(choices=display, value=len(display)-1)
|
|
|
|
| 207 |
return classification_history[idx]["email"]
|
| 208 |
return ""
|
| 209 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 210 |
classify_btn.click(
|
| 211 |
classify_and_render,
|
| 212 |
inputs=[email_box],
|
| 213 |
outputs=[result_labels, recipient, draft_response, summary, action_items, history_radio]
|
| 214 |
)
|
| 215 |
load_btn.click(load_history, inputs=[history_radio], outputs=email_box)
|
|
|
|
| 216 |
|
| 217 |
if __name__ == "__main__":
|
| 218 |
demo.launch()
|