File size: 5,521 Bytes
a6770d1 | 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 92 93 94 95 | """
tabs_extra.py
βββββββββββββ
A lightweight Gradio module that adds a Feature Reference tab and an About tab.
Import and attach to your existing Blocks app in projml.py like this:
from tabs_extra import add_extra_tabs
with gr.Blocks(...) as iface:
# ... your existing tabs/content ...
add_extra_tabs()
iface.launch(...)
"""
import gradio as gr
# ββββββββββββββββββββββββββββββββββββββββββββββ
# FEATURE REFERENCE DATA
# ββββββββββββββββββββββββββββββββββββββββββββββ
FEATURE_INFO = {
"aluminium": {"unit": "mg/L", "who_limit": "0.2", "health_risk": "Neurological damage at high doses; suspected link to Alzheimer's disease."},
"ammonia": {"unit": "mg/L", "who_limit": "1.5", "health_risk": "Irritation of the respiratory tract; toxic to aquatic life."},
"arsenic": {"unit": "mg/L", "who_limit": "0.01", "health_risk": "Carcinogenic; causes skin lesions, cancer of bladder, lungs, and skin."},
"barium": {"unit": "mg/L", "who_limit": "0.7", "health_risk": "Increased blood pressure; cardiovascular effects."},
"cadmium": {"unit": "mg/L", "who_limit": "0.003", "health_risk": "Kidney damage; bone disease (itai-itai); carcinogenic."},
"chloramine": {"unit": "mg/L", "who_limit": "4.0", "health_risk": "Irritation of eyes and nose; anaemia in dialysis patients."},
"chromium": {"unit": "mg/L", "who_limit": "0.05", "health_risk": "Hexavalent chromium is carcinogenic; causes liver/kidney damage."},
"copper": {"unit": "mg/L", "who_limit": "2.0", "health_risk": "Nausea, vomiting; liver and kidney damage at high concentrations."},
"flouride": {"unit": "mg/L", "who_limit": "1.5", "health_risk": "Dental/skeletal fluorosis; bone fractures at very high levels."},
"bacteria": {"unit": "CFU/mL","who_limit": "0", "health_risk": "Gastrointestinal illness; cholera, typhoid, dysentery."},
"viruses": {"unit": "PFU/mL","who_limit": "0", "health_risk": "Hepatitis A, polio, gastroenteritis; severe illness."},
"lead": {"unit": "mg/L", "who_limit": "0.01", "health_risk": "Neurotoxic; developmental delays in children; kidney disease."},
"nitrates": {"unit": "mg/L", "who_limit": "10.0", "health_risk": "Methemoglobinaemia (blue baby syndrome) in infants."},
"nitrites": {"unit": "mg/L", "who_limit": "1.0", "health_risk": "Methemoglobinaemia; toxic to infants; potential carcinogen."},
"mercury": {"unit": "mg/L", "who_limit": "0.006", "health_risk": "Neurological damage; Minamata disease; kidney toxicity."},
"perchlorate": {"unit": "mg/L", "who_limit": "0.015", "health_risk": "Disrupts thyroid function; affects metabolism and development."},
"radium": {"unit": "pCi/L", "who_limit": "5.0", "health_risk": "Radioactive; increases cancer risk (bone cancer, leukaemia)."},
"selenium": {"unit": "mg/L", "who_limit": "0.04", "health_risk": "Selenosis (hair/nail loss, nerve damage) at high levels."},
"silver": {"unit": "mg/L", "who_limit": "0.1", "health_risk": "Argyria (permanent blue-grey skin); toxic to aquatic organisms."},
"uranium": {"unit": "mg/L", "who_limit": "0.03", "health_risk": "Kidney toxicity; radioactive; potential carcinogen."},
}
def _feature_reference_html():
rows = ""
for feature, info in FEATURE_INFO.items():
rows += f"""
<tr>
<td><strong>{feature.capitalize()}</strong></td>
<td>{info['unit']}</td>
<td style="color:#1565C0;font-weight:600;">{info['who_limit']}</td>
<td>{info['health_risk']}</td>
</tr>"""
return f"""
<style>
.ref-table {{ border-collapse: collapse; width: 100%; font-size: 0.9em; }}
.ref-table th {{
background:#1565C0; color:white; padding:10px 12px;
text-align:left; position:sticky; top:0; z-index:1;
}}
.ref-table td {{ padding:9px 12px; border-bottom:1px solid #e0e0e0; vertical-align:top; }}
.ref-table tr:hover td {{ background:#e3f2fd; }}
</style>
<h3 style="margin-bottom:8px;">π WHO Guideline Limits & Health Risks</h3>
<p style="margin-bottom:12px;color:#555;">
All limits follow the <strong>WHO Guidelines for Drinking-water Quality (4th Ed.)</strong>.
Values beyond these thresholds are flagged as potential health hazards by the model.
</p>
<div style="max-height:520px;overflow-y:auto;border:1px solid #ccc;border-radius:6px;">
<table class="ref-table">
<thead>
<tr>
<th>Parameter</th><th>Unit</th><th>WHO Limit</th><th>Health Risk</th>
</tr>
</thead>
<tbody>{rows}</tbody>
</table>
</div>"""
# ββββββββββββββββββββββββββββββββββββββββββββββ
# PUBLIC FUNCTION β call inside your Blocks
# ββββββββββββββββββββββββββββββββββββββββββββββ
def add_extra_tabs():
"""
Call this inside your existing `with gr.Blocks() as iface:` block.
It renders two TabItems: Feature Reference and About.
"""
with gr.TabItem("π Feature Reference"):
gr.HTML(_feature_reference_html())
|