Spaces:
Sleeping
Sleeping
File size: 4,189 Bytes
5136103 e123dab 5136103 e123dab 5136103 e123dab 5136103 e123dab 5136103 e123dab 6df1128 e123dab 6df1128 5136103 e123dab 5136103 e123dab 6df1128 5136103 e123dab 5136103 e123dab 5136103 e123dab 5136103 e123dab 5136103 e123dab 5136103 e123dab 5136103 6df1128 e123dab 6df1128 e123dab | 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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | import gradio as gr
import os
import requests
BREVO_KEY = os.environ["BREVO_API_KEY"]
FROM_EMAIL = "epicamp.response@gmail.com"
FROM_NAME = "EPIC-AMP"
def send_report(to_email, pdf_b64, label, confidence, sequence):
is_amp = 'AMP' in label and 'Non' not in label
label_color = '#2e7d32' if is_amp else '#c62828'
html_content = f"""
<div style="font-family:'Segoe UI',Arial,sans-serif;max-width:600px;margin:auto;color:#1a2540;line-height:1.6">
<div style="background:#00285a;padding:22px;border-radius:10px 10px 0 0">
<h2 style="color:#fff;margin:0">EPIC-AMP Analysis Report</h2>
<p style="color:#a0c8ff;margin:6px 0 0;font-size:14px">Explainable Antimicrobial Peptide Classification Platform</p>
</div>
<div style="border:1px solid #d0daea;border-top:none;padding:24px;border-radius:0 0 10px 10px">
<p>Dear Researcher,</p>
<p>Your peptide sequence has been successfully analyzed using the <strong>EPIC-AMP platform</strong>. Please find your detailed PDF report attached.</p>
<table style="width:100%;border-collapse:collapse;margin:18px 0;font-size:14px">
<tr style="background:#00285a;color:#fff">
<td style="padding:10px 14px;font-weight:bold;width:40%">Metric</td>
<td style="padding:10px 14px;font-weight:bold">Result</td>
</tr>
<tr style="background:#f0f4fa">
<td style="padding:10px 14px;font-weight:bold">Classification</td>
<td style="padding:10px 14px;font-weight:bold;color:{label_color}">{label}</td>
</tr>
<tr>
<td style="padding:10px 14px;font-weight:bold">Confidence Score</td>
<td style="padding:10px 14px">{confidence}</td>
</tr>
<tr style="background:#f0f4fa">
<td style="padding:10px 14px;font-weight:bold">Input Sequence</td>
<td style="padding:10px 14px;font-family:monospace;font-size:12px;word-break:break-all;color:#003f7d">{sequence}</td>
</tr>
</table>
<p>The attached PDF includes LIME feature attributions, MIC predictions, and global SHAP feature importance.</p>
<p>For questions reach us at <a href="mailto:epicamp.sup@gmail.com" style="color:#1a6fc4">epicamp.sup@gmail.com</a>.</p>
<p style="margin-top:20px">Best regards,<br><strong>The EPIC-AMP Team</strong><br>
<span style="color:#666;font-size:13px">Bioinformatics & Computational Biology Unit (BCBU)</span></p>
<hr style="border:none;border-top:1px solid #e0e6f0;margin:24px 0">
<p style="color:#888;font-size:11px;margin:0">
Zewail City of Science and Technology · BCBU · Giza, Egypt<br>
📧 <a href="mailto:epicamp.sup@gmail.com" style="color:#1a6fc4">epicamp.sup@gmail.com</a><br>
<span style="color:#bbb">This is an automated message — please do not reply directly.</span>
</p>
</div>
</div>
"""
resp = requests.post(
"https://api.brevo.com/v3/smtp/email",
headers={
"api-key": BREVO_KEY,
"Content-Type": "application/json"
},
json={
"sender": {"email": FROM_EMAIL, "name": FROM_NAME},
"to": [{"email": to_email}],
"subject": f"EPIC-AMP Analysis Report — {label}",
"htmlContent": html_content,
"attachment": [{
"content": pdf_b64,
"name": "EPIC-AMP_Report.pdf"
}]
},
timeout=20
)
return "sent" if resp.status_code == 201 else f"error:{resp.status_code}:{resp.text}"
with gr.Blocks() as demo:
with gr.Row():
to_email = gr.Text(label="Recipient Email")
pdf_b64 = gr.Text(label="PDF Base64")
label_in = gr.Text(label="Label")
confidence = gr.Text(label="Confidence")
sequence = gr.Text(label="Sequence")
result = gr.Text(label="Status")
btn = gr.Button("Send")
btn.click(
fn=send_report,
inputs=[to_email, pdf_b64, label_in, confidence, sequence],
outputs=result,
api_name="send"
)
demo.launch(ssr_mode=False) |