Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,102 +2,76 @@ import gradio as gr
|
|
| 2 |
import os
|
| 3 |
import requests
|
| 4 |
|
| 5 |
-
|
| 6 |
-
SENDGRID_KEY = os.environ["SENDGRID_API_KEY"]
|
| 7 |
FROM_EMAIL = "epicamp.response@gmail.com"
|
|
|
|
| 8 |
|
| 9 |
def send_report(to_email, pdf_b64, label, confidence, sequence):
|
|
|
|
|
|
|
|
|
|
| 10 |
html_content = f"""
|
| 11 |
-
<div style="font-family:
|
| 12 |
-
<
|
| 13 |
-
|
| 14 |
-
<
|
| 15 |
-
<p style="color:#a0c8ff; margin:6px 0 0; font-size:14px">
|
| 16 |
-
Explainable Antimicrobial Peptide Classification Platform
|
| 17 |
-
</p>
|
| 18 |
</div>
|
| 19 |
-
<
|
| 20 |
-
<div style="border:1px solid #d0daea; border-top:none; padding:24px; border-radius:0 0 10px 10px">
|
| 21 |
<p>Dear Researcher,</p>
|
| 22 |
-
<p>
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
<!-- Results Table -->
|
| 28 |
-
<table style="width:100%; border-collapse:collapse; margin:18px 0; font-size:14px; border-radius:6px; overflow:hidden">
|
| 29 |
-
<tr style="background:#00285a; color:#ffffff">
|
| 30 |
-
<td style="padding:10px 14px; font-weight:bold; width:40%">Metric</td>
|
| 31 |
-
<td style="padding:10px 14px; font-weight:bold">Result</td>
|
| 32 |
</tr>
|
| 33 |
<tr style="background:#f0f4fa">
|
| 34 |
-
<td style="padding:10px 14px;
|
| 35 |
-
<td style="padding:10px 14px;
|
| 36 |
</tr>
|
| 37 |
<tr>
|
| 38 |
-
<td style="padding:10px 14px;
|
| 39 |
<td style="padding:10px 14px">{confidence}</td>
|
| 40 |
</tr>
|
| 41 |
<tr style="background:#f0f4fa">
|
| 42 |
-
<td style="padding:10px 14px;
|
| 43 |
-
<td style="padding:10px 14px;
|
| 44 |
</tr>
|
| 45 |
</table>
|
| 46 |
-
<p>
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
<
|
| 51 |
-
<p>
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
<
|
| 55 |
-
</p>
|
| 56 |
-
<p style="margin-top:20px">
|
| 57 |
-
Best regards,<br>
|
| 58 |
-
<strong>The EPIC-AMP Team</strong><br>
|
| 59 |
-
<span style="color:#666; font-size:13px">Bioinformatics & Computational Biology Unit (BCBU)</span>
|
| 60 |
</p>
|
| 61 |
-
<!-- Footer -->
|
| 62 |
-
<hr style="border:none; border-top:1px solid #e0e6f0; margin:24px 0">
|
| 63 |
-
<div style="display:flex; justify-content:space-between; align-items:center; flex-wrap:wrap; gap:8px">
|
| 64 |
-
<p style="color:#888; font-size:11px; margin:0">
|
| 65 |
-
Zewail City of Science and Technology Β· BCBU<br>
|
| 66 |
-
Ahmed Zewail Street, October Gardens, Giza, Egypt
|
| 67 |
-
</p>
|
| 68 |
-
<p style="color:#888; font-size:11px; margin:0; text-align:right">
|
| 69 |
-
π§ <a href="mailto:epicamp.sup@gmail.com" style="color:#1a6fc4">epicamp.sup@gmail.com</a><br>
|
| 70 |
-
<span style="color:#bbb">This is an automated message β please do not reply directly.</span>
|
| 71 |
-
</p>
|
| 72 |
-
</div>
|
| 73 |
</div>
|
| 74 |
</div>
|
| 75 |
"""
|
| 76 |
|
| 77 |
resp = requests.post(
|
| 78 |
-
"https://api.
|
| 79 |
headers={
|
| 80 |
-
"
|
| 81 |
"Content-Type": "application/json"
|
| 82 |
},
|
| 83 |
json={
|
| 84 |
-
"
|
| 85 |
-
"
|
| 86 |
-
"subject":
|
| 87 |
-
"
|
| 88 |
-
"
|
| 89 |
-
"content":
|
| 90 |
-
"
|
| 91 |
-
"filename": "EPIC-AMP_Report.pdf",
|
| 92 |
-
"disposition": "attachment"
|
| 93 |
}]
|
| 94 |
},
|
| 95 |
timeout=20
|
| 96 |
)
|
| 97 |
-
return "sent" if resp.status_code ==
|
| 98 |
|
| 99 |
|
| 100 |
-
# ββ Gradio Blocks (fixes "Could not get API info" error) ββββββββββββββ
|
| 101 |
with gr.Blocks() as demo:
|
| 102 |
with gr.Row():
|
| 103 |
to_email = gr.Text(label="Recipient Email")
|
|
@@ -111,7 +85,7 @@ with gr.Blocks() as demo:
|
|
| 111 |
fn=send_report,
|
| 112 |
inputs=[to_email, pdf_b64, label_in, confidence, sequence],
|
| 113 |
outputs=result,
|
| 114 |
-
api_name="send"
|
| 115 |
)
|
| 116 |
|
| 117 |
-
demo.launch(ssr_mode=False)
|
|
|
|
| 2 |
import os
|
| 3 |
import requests
|
| 4 |
|
| 5 |
+
BREVO_KEY = os.environ["BREVO_API_KEY"]
|
|
|
|
| 6 |
FROM_EMAIL = "epicamp.response@gmail.com"
|
| 7 |
+
FROM_NAME = "EPIC-AMP"
|
| 8 |
|
| 9 |
def send_report(to_email, pdf_b64, label, confidence, sequence):
|
| 10 |
+
is_amp = 'AMP' in label and 'Non' not in label
|
| 11 |
+
label_color = '#2e7d32' if is_amp else '#c62828'
|
| 12 |
+
|
| 13 |
html_content = f"""
|
| 14 |
+
<div style="font-family:'Segoe UI',Arial,sans-serif;max-width:600px;margin:auto;color:#1a2540;line-height:1.6">
|
| 15 |
+
<div style="background:#00285a;padding:22px;border-radius:10px 10px 0 0">
|
| 16 |
+
<h2 style="color:#fff;margin:0">EPIC-AMP Analysis Report</h2>
|
| 17 |
+
<p style="color:#a0c8ff;margin:6px 0 0;font-size:14px">Explainable Antimicrobial Peptide Classification Platform</p>
|
|
|
|
|
|
|
|
|
|
| 18 |
</div>
|
| 19 |
+
<div style="border:1px solid #d0daea;border-top:none;padding:24px;border-radius:0 0 10px 10px">
|
|
|
|
| 20 |
<p>Dear Researcher,</p>
|
| 21 |
+
<p>Your peptide sequence has been successfully analyzed using the <strong>EPIC-AMP platform</strong>. Please find your detailed PDF report attached.</p>
|
| 22 |
+
<table style="width:100%;border-collapse:collapse;margin:18px 0;font-size:14px">
|
| 23 |
+
<tr style="background:#00285a;color:#fff">
|
| 24 |
+
<td style="padding:10px 14px;font-weight:bold;width:40%">Metric</td>
|
| 25 |
+
<td style="padding:10px 14px;font-weight:bold">Result</td>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
</tr>
|
| 27 |
<tr style="background:#f0f4fa">
|
| 28 |
+
<td style="padding:10px 14px;font-weight:bold">Classification</td>
|
| 29 |
+
<td style="padding:10px 14px;font-weight:bold;color:{label_color}">{label}</td>
|
| 30 |
</tr>
|
| 31 |
<tr>
|
| 32 |
+
<td style="padding:10px 14px;font-weight:bold">Confidence Score</td>
|
| 33 |
<td style="padding:10px 14px">{confidence}</td>
|
| 34 |
</tr>
|
| 35 |
<tr style="background:#f0f4fa">
|
| 36 |
+
<td style="padding:10px 14px;font-weight:bold">Input Sequence</td>
|
| 37 |
+
<td style="padding:10px 14px;font-family:monospace;font-size:12px;word-break:break-all;color:#003f7d">{sequence}</td>
|
| 38 |
</tr>
|
| 39 |
</table>
|
| 40 |
+
<p>The attached PDF includes LIME feature attributions, MIC predictions, and global SHAP feature importance.</p>
|
| 41 |
+
<p>For questions reach us at <a href="mailto:epicamp.sup@gmail.com" style="color:#1a6fc4">epicamp.sup@gmail.com</a>.</p>
|
| 42 |
+
<p style="margin-top:20px">Best regards,<br><strong>The EPIC-AMP Team</strong><br>
|
| 43 |
+
<span style="color:#666;font-size:13px">Bioinformatics & Computational Biology Unit (BCBU)</span></p>
|
| 44 |
+
<hr style="border:none;border-top:1px solid #e0e6f0;margin:24px 0">
|
| 45 |
+
<p style="color:#888;font-size:11px;margin:0">
|
| 46 |
+
Zewail City of Science and Technology Β· BCBU Β· Giza, Egypt<br>
|
| 47 |
+
π§ <a href="mailto:epicamp.sup@gmail.com" style="color:#1a6fc4">epicamp.sup@gmail.com</a><br>
|
| 48 |
+
<span style="color:#bbb">This is an automated message β please do not reply directly.</span>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
</div>
|
| 51 |
</div>
|
| 52 |
"""
|
| 53 |
|
| 54 |
resp = requests.post(
|
| 55 |
+
"https://api.brevo.com/v3/smtp/email",
|
| 56 |
headers={
|
| 57 |
+
"api-key": BREVO_KEY,
|
| 58 |
"Content-Type": "application/json"
|
| 59 |
},
|
| 60 |
json={
|
| 61 |
+
"sender": {"email": FROM_EMAIL, "name": FROM_NAME},
|
| 62 |
+
"to": [{"email": to_email}],
|
| 63 |
+
"subject": f"EPIC-AMP Analysis Report β {label}",
|
| 64 |
+
"htmlContent": html_content,
|
| 65 |
+
"attachment": [{
|
| 66 |
+
"content": pdf_b64,
|
| 67 |
+
"name": "EPIC-AMP_Report.pdf"
|
|
|
|
|
|
|
| 68 |
}]
|
| 69 |
},
|
| 70 |
timeout=20
|
| 71 |
)
|
| 72 |
+
return "sent" if resp.status_code == 201 else f"error:{resp.status_code}:{resp.text}"
|
| 73 |
|
| 74 |
|
|
|
|
| 75 |
with gr.Blocks() as demo:
|
| 76 |
with gr.Row():
|
| 77 |
to_email = gr.Text(label="Recipient Email")
|
|
|
|
| 85 |
fn=send_report,
|
| 86 |
inputs=[to_email, pdf_b64, label_in, confidence, sequence],
|
| 87 |
outputs=result,
|
| 88 |
+
api_name="send"
|
| 89 |
)
|
| 90 |
|
| 91 |
+
demo.launch(ssr_mode=False)
|