nonzeroexit commited on
Commit
6df1128
Β·
verified Β·
1 Parent(s): 5136103

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -49
app.py CHANGED
@@ -1,7 +1,6 @@
1
  import gradio as gr
2
  import os
3
  import requests
4
- import base64
5
 
6
  # Environment variables
7
  SENDGRID_KEY = os.environ["SENDGRID_API_KEY"]
@@ -10,7 +9,6 @@ FROM_EMAIL = "epicamp.response@gmail.com"
10
  def send_report(to_email, pdf_b64, label, confidence, sequence):
11
  html_content = f"""
12
  <div style="font-family: 'Segoe UI', Arial, sans-serif; max-width:600px; margin:auto; color:#1a2540; line-height:1.6">
13
-
14
  <!-- Header -->
15
  <div style="background:#00285a; padding:22px; border-radius:10px 10px 0 0;">
16
  <h2 style="color:#ffffff; margin:0">EPIC-AMP Analysis Report</h2>
@@ -18,59 +16,60 @@ def send_report(to_email, pdf_b64, label, confidence, sequence):
18
  Explainable Antimicrobial Peptide Classification Platform
19
  </p>
20
  </div>
21
-
22
  <!-- Body -->
23
  <div style="border:1px solid #d0daea; border-top:none; padding:24px; border-radius:0 0 10px 10px">
24
-
25
- <p>Dear User,</p>
26
-
27
  <p>
28
  Your peptide sequence has been successfully analyzed using the <strong>EPIC-AMP platform</strong>.
29
- Please find your detailed report attached as a PDF file.
30
  </p>
31
-
32
- <p>Below is a summary of your analysis:</p>
33
-
34
- <!-- Table -->
35
- <table style="width:100%; border-collapse:collapse; margin:18px 0; font-size:14px">
 
 
36
  <tr style="background:#f0f4fa">
37
- <td style="padding:10px; font-weight:bold; width:40%">Classification</td>
38
- <td style="padding:10px">{label}</td>
39
  </tr>
40
  <tr>
41
- <td style="padding:10px; font-weight:bold">Confidence Score</td>
42
- <td style="padding:10px">{confidence}</td>
43
  </tr>
44
  <tr style="background:#f0f4fa">
45
- <td style="padding:10px; font-weight:bold">Input Sequence</td>
46
- <td style="padding:10px; font-family:monospace; font-size:12px; word-break:break-all">
47
- {sequence}
48
- </td>
49
  </tr>
50
  </table>
51
-
52
  <p>
53
- The attached report provides a comprehensive explanation of the prediction,
54
- including interpretability insights to support further research and analysis.
 
55
  </p>
56
-
57
  <p>
58
- If you have any questions or need assistance, feel free to contact us.
 
 
59
  </p>
60
-
61
- <p style="margin-top:24px">
62
  Best regards,<br>
63
- <strong>EPIC-AMP Team</strong>
 
64
  </p>
65
-
66
  <!-- Footer -->
67
  <hr style="border:none; border-top:1px solid #e0e6f0; margin:24px 0">
68
-
69
- <p style="color:#666; font-size:12px">
70
- Zewail City of Science and Technology Β· Biotechnology & Bioinformatics Unit (BCBU)<br>
71
- πŸ“§ <a href="mailto:epicamp.sup@gmail.com" style="color:#1a6fc4">epicamp.sup@gmail.com</a>
72
- </p>
73
-
 
 
 
 
74
  </div>
75
  </div>
76
  """
@@ -95,20 +94,24 @@ def send_report(to_email, pdf_b64, label, confidence, sequence):
95
  },
96
  timeout=20
97
  )
98
-
99
  return "sent" if resp.status_code == 202 else f"error:{resp.status_code}:{resp.text}"
100
 
101
 
102
- # Gradio interface
103
- gr.Interface(
104
- fn=send_report,
105
- inputs=[
106
- gr.Text(label="Recipient Email"),
107
- gr.Text(label="PDF Base64"),
108
- gr.Text(label="Label"),
109
- gr.Text(label="Confidence"),
110
- gr.Text(label="Sequence")
111
- ],
112
- outputs=gr.Text(label="Status"),
113
- title="EPIC-AMP Mailer"
114
- ).launch()
 
 
 
 
 
 
1
  import gradio as gr
2
  import os
3
  import requests
 
4
 
5
  # Environment variables
6
  SENDGRID_KEY = os.environ["SENDGRID_API_KEY"]
 
9
  def send_report(to_email, pdf_b64, label, confidence, sequence):
10
  html_content = f"""
11
  <div style="font-family: 'Segoe UI', Arial, sans-serif; max-width:600px; margin:auto; color:#1a2540; line-height:1.6">
 
12
  <!-- Header -->
13
  <div style="background:#00285a; padding:22px; border-radius:10px 10px 0 0;">
14
  <h2 style="color:#ffffff; margin:0">EPIC-AMP Analysis Report</h2>
 
16
  Explainable Antimicrobial Peptide Classification Platform
17
  </p>
18
  </div>
 
19
  <!-- Body -->
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
  Your peptide sequence has been successfully analyzed using the <strong>EPIC-AMP platform</strong>.
24
+ Please find your detailed PDF report attached to this email.
25
  </p>
26
+ <p>Below is a summary of your analysis results:</p>
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; font-weight:bold">Classification</td>
35
+ <td style="padding:10px 14px; font-weight:bold; color:{'#2e7d32' if 'AMP' in label and 'Non' not in label else '#c62828'}">{label}</td>
36
  </tr>
37
  <tr>
38
+ <td style="padding:10px 14px; font-weight:bold">Confidence Score</td>
39
+ <td style="padding:10px 14px">{confidence}</td>
40
  </tr>
41
  <tr style="background:#f0f4fa">
42
+ <td style="padding:10px 14px; font-weight:bold">Input Sequence</td>
43
+ <td style="padding:10px 14px; font-family:monospace; font-size:12px; word-break:break-all; color:#003f7d">{sequence}</td>
 
 
44
  </tr>
45
  </table>
 
46
  <p>
47
+ The attached PDF report includes a full breakdown of the prediction, LIME feature attributions,
48
+ MIC predictions (if applicable), and global SHAP feature importance β€” providing complete
49
+ interpretability to support your research.
50
  </p>
 
51
  <p>
52
+ If you have any questions, suggestions, or need further assistance, please don't hesitate
53
+ to reach out to us at
54
+ <a href="mailto:epicamp.sup@gmail.com" style="color:#1a6fc4">epicamp.sup@gmail.com</a>.
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 &amp; 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
  """
 
94
  },
95
  timeout=20
96
  )
 
97
  return "sent" if resp.status_code == 202 else f"error:{resp.status_code}:{resp.text}"
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")
104
+ pdf_b64 = gr.Text(label="PDF Base64")
105
+ label_in = gr.Text(label="Label")
106
+ confidence = gr.Text(label="Confidence")
107
+ sequence = gr.Text(label="Sequence")
108
+ result = gr.Text(label="Status")
109
+ btn = gr.Button("Send")
110
+ btn.click(
111
+ fn=send_report,
112
+ inputs=[to_email, pdf_b64, label_in, confidence, sequence],
113
+ outputs=result,
114
+ api_name="send" # ← makes /send the stable API endpoint
115
+ )
116
+
117
+ demo.launch(ssr_mode=False) # ← fixes the SSR startup warning