web / app.py
Shwetakka's picture
Added the missing 4e and 4f modifications
506685d verified
Raw History Blame Contribute Delete
6.28 kB
import gradio as gr
from scoring_service import IOTNScoringService
from constants import SOURCE_NOTE
# Global service instance
service = IOTNScoringService()
def get_dhc_score(*args):
keys = [
"overjet_mm", "lip_competence", "reverse_overjet_mm",
"mastication_difficulty", "speech_difficulty",
"anterior_crossbite_mm", "posterior_crossbite_mm", "posterior_lingual_crossbite_no_contact",
"max_contact_displacement_mm", "overbite_mm", "open_bite_mm", "overbite_complete",
"gingival_trauma", "palatal_trauma",
"missing_teeth_UR", "missing_teeth_UL", "missing_teeth_LR", "missing_teeth_LL",
"space_closure_required", "restorative_implications",
"impeded_eruption", "cleft_lip_palate", "submerged_deciduous", "supplemental_teeth"
]
# Ensure all numerical args are handled safely (Gradio Number handles numeric enforcement)
payload = dict(zip(keys, args))
result = service.score(payload)
findings_list = [f"- **{f.code}**: {f.summary} ({f.evidence})" for f in result.findings]
findings_md = "### Matched Criteria\n" + "\n".join(findings_list) if findings_list else "No Grade 2+ criteria matched."
return (
f"## Grade {result.grade}",
f"**{result.classification}**: {result.subcode_label}",
result.summary,
findings_md
)
with gr.Blocks(title="IOTN Assistant", theme=gr.themes.Soft()) as demo:
gr.Markdown("# IOTN DHC Assessment Form")
gr.Markdown("Please enter the patient's findings below. The system will calculate the highest IOTN Grade based on the MOCDO hierarchy.")
with gr.Row():
# Unified Form Section (Left)
with gr.Column(scale=3):
gr.Markdown("### 1. Missing Teeth / Specials (M)")
with gr.Row():
m_ur = gr.Number(label="UR Missing", value=0, precision=0, minimum=0)
m_ul = gr.Number(label="UL Missing", value=0, precision=0, minimum=0)
m_lr = gr.Number(label="LR Missing", value=0, precision=0, minimum=0)
m_ll = gr.Number(label="LL Missing", value=0, precision=0, minimum=0)
with gr.Row():
sp_cl = gr.Checkbox(label="Space Closure Required")
rest_imp = gr.Checkbox(label="Restorative Needs")
imp_er = gr.Checkbox(label="Impeded Eruption")
with gr.Row():
cleft = gr.Checkbox(label="Cleft Lip/Palate")
subm = gr.Checkbox(label="Submerged Deciduous")
supp = gr.Checkbox(label="Supplemental Teeth")
gr.Markdown("---")
gr.Markdown("### 2. Overjet (O)")
with gr.Row():
oj_mm = gr.Number(label="Overjet (mm)", value=0.0, precision=1, minimum=0)
lips = gr.Radio(
choices=["competent", "incompetent"],
value="competent",
label="Lip Competence"
)
with gr.Row():
roj_mm = gr.Number(label="Reverse Overjet (mm)", value=0.0, precision=1, minimum=0)
mast = gr.Checkbox(label="Masticatory Difficulty")
speech = gr.Checkbox(label="Speech Difficulty")
gr.Markdown("---")
gr.Markdown("### 3. Crossbite (C)")
with gr.Row():
ant_cb = gr.Number(label="Anterior Crossbite Discrepancy (mm)", value=0.0, precision=1, minimum=0)
post_cb = gr.Number(label="Posterior Crossbite Discrepancy (mm)", value=0.0, precision=1, minimum=0)
scissor = gr.Checkbox(label="Posterior lingual crossbite (No contact)")
gr.Markdown("---")
gr.Markdown("### 4. Displacement (D)")
disp_mm = gr.Number(label="Max Contact Displacement (mm)", value=0.0, precision=1, minimum=0)
gr.Markdown("---")
gr.Markdown("### 5. Overbite / Open Bite (O)")
with gr.Row():
ob_mm = gr.Number(label="Overbite Depth (mm)", value=0.0, precision=1, minimum=0)
open_bite_mm = gr.Number(label="Open Bite (mm)", value=0.0, precision=1, minimum=0)
with gr.Row():
ob_comp = gr.Checkbox(label="Complete Overbite")
ging_tr = gr.Checkbox(label="Gingival Trauma")
pal_tr = gr.Checkbox(label="Palatal Trauma")
gr.Markdown("---")
score_btn = gr.Button("Calculate IOTN Grade", variant="primary", size="lg")
# Results Section (Right)
with gr.Column(scale=2):
with gr.Group():
gr.Markdown("### Assessment Result")
res_grade = gr.Markdown("## Grade -")
res_class = gr.Markdown("**Classification -**")
res_summary = gr.Textbox(label="Summary", interactive=False, lines=2)
res_findings = gr.Markdown("### Matched Criteria")
# Wire up events
all_inputs = [
oj_mm, lips, roj_mm, mast, speech,
ant_cb, post_cb, scissor,
disp_mm, ob_mm, open_bite_mm, ob_comp, ging_tr, pal_tr,
m_ur, m_ul, m_lr, m_ll, sp_cl, rest_imp,
imp_er, cleft, subm, supp
]
score_btn.click(
get_dhc_score,
inputs=all_inputs,
outputs=[res_grade, res_class, res_summary, res_findings],
show_progress="minimal"
)
gr.Markdown(f"\n\n--- \n{SOURCE_NOTE}")
gr.Examples(
examples=[
[10.0, "competent", 0.0, False, False, 0.0, 0.0, False, 0.0, 0.0, 0.0, False, False, False, 0, 0, 0, 0, False, False, False, False, False, False],
[5.0, "incompetent", 0.0, False, False, 0.0, 0.0, False, 0.0, 0.0, 0.0, False, False, False, 0, 0, 0, 0, False, False, False, False, False, False],
[0.0, "competent", 0.0, False, False, 0.0, 0.0, False, 0.0, 0.0, 0.0, False, False, False, 0, 0, 0, 0, False, False, True, False, False, False],
],
inputs=all_inputs,
label="Quick Samples"
)
if __name__ == "__main__":
demo.queue().launch(server_name="0.0.0.0", server_port=7860)