Download tab_extra.py from ML-Project-S26/Detailed_Water_Quality_Prediction_System: direct link, hf CLI and curl.
- Browser
- Download file 5.52 kB
-
https://huggingface.co/spaces/ML-Project-S26/Detailed_Water_Quality_Prediction_System/resolve/main/tab_extra.py
- Command line
-
hf download hf://spaces/ML-Project-S26/Detailed_Water_Quality_Prediction_System/tab_extra.py
-
curl -L -o tab_extra.py https://huggingface.co/spaces/ML-Project-S26/Detailed_Water_Quality_Prediction_System/resolve/main/tab_extra.py
5.52 kB
| """ | |
| 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()) | |