bushra-kh commited on
Commit
a6770d1
Β·
verified Β·
1 Parent(s): 923683e

Upload tab_extra.py

Browse files
Files changed (1) hide show
  1. tab_extra.py +94 -0
tab_extra.py ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ tabs_extra.py
3
+ ─────────────
4
+ A lightweight Gradio module that adds a Feature Reference tab and an About tab.
5
+ Import and attach to your existing Blocks app in projml.py like this:
6
+
7
+ from tabs_extra import add_extra_tabs
8
+
9
+ with gr.Blocks(...) as iface:
10
+ # ... your existing tabs/content ...
11
+ add_extra_tabs()
12
+
13
+ iface.launch(...)
14
+ """
15
+
16
+ import gradio as gr
17
+
18
+ # ──────────────────────────────────────────────
19
+ # FEATURE REFERENCE DATA
20
+ # ──────────────────────────────────────────────
21
+ FEATURE_INFO = {
22
+ "aluminium": {"unit": "mg/L", "who_limit": "0.2", "health_risk": "Neurological damage at high doses; suspected link to Alzheimer's disease."},
23
+ "ammonia": {"unit": "mg/L", "who_limit": "1.5", "health_risk": "Irritation of the respiratory tract; toxic to aquatic life."},
24
+ "arsenic": {"unit": "mg/L", "who_limit": "0.01", "health_risk": "Carcinogenic; causes skin lesions, cancer of bladder, lungs, and skin."},
25
+ "barium": {"unit": "mg/L", "who_limit": "0.7", "health_risk": "Increased blood pressure; cardiovascular effects."},
26
+ "cadmium": {"unit": "mg/L", "who_limit": "0.003", "health_risk": "Kidney damage; bone disease (itai-itai); carcinogenic."},
27
+ "chloramine": {"unit": "mg/L", "who_limit": "4.0", "health_risk": "Irritation of eyes and nose; anaemia in dialysis patients."},
28
+ "chromium": {"unit": "mg/L", "who_limit": "0.05", "health_risk": "Hexavalent chromium is carcinogenic; causes liver/kidney damage."},
29
+ "copper": {"unit": "mg/L", "who_limit": "2.0", "health_risk": "Nausea, vomiting; liver and kidney damage at high concentrations."},
30
+ "flouride": {"unit": "mg/L", "who_limit": "1.5", "health_risk": "Dental/skeletal fluorosis; bone fractures at very high levels."},
31
+ "bacteria": {"unit": "CFU/mL","who_limit": "0", "health_risk": "Gastrointestinal illness; cholera, typhoid, dysentery."},
32
+ "viruses": {"unit": "PFU/mL","who_limit": "0", "health_risk": "Hepatitis A, polio, gastroenteritis; severe illness."},
33
+ "lead": {"unit": "mg/L", "who_limit": "0.01", "health_risk": "Neurotoxic; developmental delays in children; kidney disease."},
34
+ "nitrates": {"unit": "mg/L", "who_limit": "10.0", "health_risk": "Methemoglobinaemia (blue baby syndrome) in infants."},
35
+ "nitrites": {"unit": "mg/L", "who_limit": "1.0", "health_risk": "Methemoglobinaemia; toxic to infants; potential carcinogen."},
36
+ "mercury": {"unit": "mg/L", "who_limit": "0.006", "health_risk": "Neurological damage; Minamata disease; kidney toxicity."},
37
+ "perchlorate": {"unit": "mg/L", "who_limit": "0.015", "health_risk": "Disrupts thyroid function; affects metabolism and development."},
38
+ "radium": {"unit": "pCi/L", "who_limit": "5.0", "health_risk": "Radioactive; increases cancer risk (bone cancer, leukaemia)."},
39
+ "selenium": {"unit": "mg/L", "who_limit": "0.04", "health_risk": "Selenosis (hair/nail loss, nerve damage) at high levels."},
40
+ "silver": {"unit": "mg/L", "who_limit": "0.1", "health_risk": "Argyria (permanent blue-grey skin); toxic to aquatic organisms."},
41
+ "uranium": {"unit": "mg/L", "who_limit": "0.03", "health_risk": "Kidney toxicity; radioactive; potential carcinogen."},
42
+ }
43
+
44
+
45
+ def _feature_reference_html():
46
+ rows = ""
47
+ for feature, info in FEATURE_INFO.items():
48
+ rows += f"""
49
+ <tr>
50
+ <td><strong>{feature.capitalize()}</strong></td>
51
+ <td>{info['unit']}</td>
52
+ <td style="color:#1565C0;font-weight:600;">{info['who_limit']}</td>
53
+ <td>{info['health_risk']}</td>
54
+ </tr>"""
55
+
56
+ return f"""
57
+ <style>
58
+ .ref-table {{ border-collapse: collapse; width: 100%; font-size: 0.9em; }}
59
+ .ref-table th {{
60
+ background:#1565C0; color:white; padding:10px 12px;
61
+ text-align:left; position:sticky; top:0; z-index:1;
62
+ }}
63
+ .ref-table td {{ padding:9px 12px; border-bottom:1px solid #e0e0e0; vertical-align:top; }}
64
+ .ref-table tr:hover td {{ background:#e3f2fd; }}
65
+ </style>
66
+ <h3 style="margin-bottom:8px;">πŸ“‹ WHO Guideline Limits &amp; Health Risks</h3>
67
+ <p style="margin-bottom:12px;color:#555;">
68
+ All limits follow the <strong>WHO Guidelines for Drinking-water Quality (4th Ed.)</strong>.
69
+ Values beyond these thresholds are flagged as potential health hazards by the model.
70
+ </p>
71
+ <div style="max-height:520px;overflow-y:auto;border:1px solid #ccc;border-radius:6px;">
72
+ <table class="ref-table">
73
+ <thead>
74
+ <tr>
75
+ <th>Parameter</th><th>Unit</th><th>WHO Limit</th><th>Health Risk</th>
76
+ </tr>
77
+ </thead>
78
+ <tbody>{rows}</tbody>
79
+ </table>
80
+ </div>"""
81
+
82
+
83
+
84
+ # ───────────────────────────���──────────────────
85
+ # PUBLIC FUNCTION β€” call inside your Blocks
86
+ # ──────────────────────────────────────────────
87
+ def add_extra_tabs():
88
+ """
89
+ Call this inside your existing `with gr.Blocks() as iface:` block.
90
+ It renders two TabItems: Feature Reference and About.
91
+ """
92
+ with gr.TabItem("πŸ“‹ Feature Reference"):
93
+ gr.HTML(_feature_reference_html())
94
+