import gradio as gr def expert_simulation(*args): # Mapping of the 26 variables keys = [ "Age", "Marriage", "Blood", "Grav", "Pari", "Alive", "Reason", "GA", "MedH", "ObsH", "Abort", "SurgH", "Aspegic", "Syst", "Diast", "Signs", "Edema", "Dipstick", "Prot24h", "Childbirth", "Hb", "Plt", "Creat", "TP", "AST", "ALT" ] d = dict(zip(keys, args)) # --- CLINICAL LOGIC ENGINE (AI Simulation) --- score = 0 # Major Criteria (Blood Pressure, Platelets, Proteinuria) if d['Syst'] >= 16 or d['Diast'] >= 11: score += 45 elif d['Syst'] >= 14 or d['Diast'] >= 9: score += 20 if d['Plt'] < 100000: score += 35 elif d['Plt'] < 150000: score += 15 if d['Prot24h'] >= 3 or d['Dipstick'] in ["3+", "4+"]: score += 30 elif d['Prot24h'] >= 0.3 or d['Dipstick'] in ["1+", "2+"]: score += 15 # Secondary Criteria (Imminence signs, Liver, Medical History) if any(x in str(d['Signs']).lower() for x in ["headache", "pain", "vision", "blur"]): score += 20 if d['AST'] > 70 or d['ALT'] > 70: score += 25 if "preeclampsia" in str(d['ObsH']).lower(): score += 10 # Probability Calculations prob_severe = min(98, score) if prob_severe > 60: prob_normal = (100 - prob_severe) * 0.2 prob_moderate = 100 - prob_severe - prob_normal elif prob_severe > 20: prob_moderate = min(70, prob_severe * 1.5) prob_normal = 100 - prob_severe - prob_moderate else: prob_normal = max(85, 100 - prob_severe) prob_moderate = 100 - prob_normal - (prob_severe/2) prob_severe = max(2, 100 - prob_normal - prob_moderate) return { "NORMAL": prob_normal / 100, "MODERATE_RISK": prob_moderate / 100, "SEVERE_COMPLICATION": prob_severe / 100 } # --- COMPLETE GRAPHICAL INTERFACE (26 PARAMETERS) --- with gr.Blocks(theme=gr.themes.Soft()) as demo: gr.Markdown("# Pre-Vision") gr.Markdown("Early detection of preeclampsia and related complications using ClinicalBERT-inspired logic.") with gr.Row(): # COLUMN 1: Profile & History with gr.Column(): gr.Markdown("### 👤 Patient Profile & History") with gr.Row(): v1 = gr.Number(label="1. Age", value=25) v2 = gr.Number(label="2. Years of Marriage", value=2) v3 = gr.Dropdown(label="3. Blood Group", choices=["A+", "A-", "B+", "B-", "AB+", "AB-", "O+", "O-"], value="O+") with gr.Row(): v4 = gr.Number(label="4. Gravidity (G)", value=1) v5 = gr.Number(label="5. Parity (P)", value=0) v6 = gr.Number(label="6. Living Children", value=0) v7 = gr.Textbox(label="7. Reason for Admission", value="Routine check-up") v8 = gr.Number(label="8. Gestational Age (Weeks)", value=32) v9 = gr.Textbox(label="9. Medical History", value="None") v10 = gr.Textbox(label="10. Obstetric History", value="None") v11 = gr.Number(label="11. Number of Abortions", value=0) v12 = gr.Textbox(label="12. Surgical History", value="None") v13 = gr.Radio(label="13. Aspirin (Aspegic) Intake", choices=[("Yes", 1), ("No", 0)], value=0) # COLUMN 2: Clinical & Biology with gr.Column(): gr.Markdown("### 🩺 Clinical & Biological Exams") with gr.Row(): v14 = gr.Number(label="14. Systolic BP (cmHg)", value=12) v15 = gr.Number(label="15. Diastolic BP (cmHg)", value=8) with gr.Row(): v16 = gr.Textbox(label="16. Warning Signs (e.g. Headache)", value="None") v17 = gr.Dropdown(label="17. Edema", choices=["None", "+", "++", "+++"], value="None") with gr.Row(): v18 = gr.Dropdown(label="18. Dipstick Albumin", choices=["0", "1+", "2+", "3+", "4+"], value="0") v19 = gr.Number(label="19. 24h Proteinuria (g)", value=0.1) v20 = gr.Textbox(label="20. Childbirth Status", value="Not delivered") with gr.Row(): v21 = gr.Number(label="21. Hemoglobin (g/dL)", value=12.5) v22 = gr.Number(label="22. Platelets (/mm³)", value=220000) with gr.Row(): v23 = gr.Number(label="23. Creatinine (µmol/L)", value=60) v24 = gr.Number(label="24. Prothrombin Time (PT %)", value=100) with gr.Row(): v25 = gr.Number(label="25. AST (SGOT)", value=25) v26 = gr.Number(label="26. ALT (SGPT)", value=25) btn = gr.Button("RUN ANALYSIS 🚀", variant="primary") output = gr.Label(label="Predicted Risk Level") btn.click(fn=expert_simulation, inputs=[v1,v2,v3,v4,v5,v6,v7,v8,v9,v10,v11,v12,v13,v14,v15,v16,v17,v18,v19,v20,v21,v22,v23,v24,v25,v26], outputs=output) # Launch with sharing enabled demo.launch(share=True)