Spaces:
Sleeping
Sleeping
Commit Β·
5d3bbea
1
Parent(s): f2eac81
added first name and last name logging fields
Browse files
app.py
CHANGED
|
@@ -56,9 +56,15 @@ with gr.Blocks(title="Clinic LLM Assistant", css=ORANGE_CSS) as demo:
|
|
| 56 |
question_state = gr.State({}) # holds the question dict
|
| 57 |
so_state = gr.State("") # holds Subjective & Objective text
|
| 58 |
|
| 59 |
-
# ββββββββββββββββββββββββββββββββββββββββββββββββββ Step
|
|
|
|
| 60 |
with gr.Row():
|
| 61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
gender_input = gr.Dropdown(["Male", "Female"], label="Gender")
|
| 63 |
cc_input = gr.Textbox(lines=2, label="Chief Complaint")
|
| 64 |
gen_q_btn = gr.Button("Generate Questions", elem_classes="orange-btn")
|
|
@@ -103,17 +109,25 @@ with gr.Blocks(title="Clinic LLM Assistant", css=ORANGE_CSS) as demo:
|
|
| 103 |
# Callbacks
|
| 104 |
# -------------------------------------------------------------------------
|
| 105 |
|
| 106 |
-
def _gen_questions(age, gender, cc):
|
| 107 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
try:
|
| 109 |
q_dict = generate_question_dict(age, gender, cc)
|
| 110 |
except json.JSONDecodeError:
|
| 111 |
-
# Return fixedβlength output list even on failure
|
| 112 |
return (
|
| 113 |
-
"β οΈ LLM failed to return valid JSON. Please try again.",
|
| 114 |
*[gr.update(visible=False) for _ in range(MAX_QUESTIONS)],
|
| 115 |
gr.update(visible=False),
|
| 116 |
{},
|
|
|
|
| 117 |
)
|
| 118 |
|
| 119 |
# Prepare exactly MAX_QUESTIONS Textbox updates
|
|
@@ -129,13 +143,13 @@ with gr.Blocks(title="Clinic LLM Assistant", css=ORANGE_CSS) as demo:
|
|
| 129 |
*box_updates, # Answer boxes
|
| 130 |
gr.update(visible=True), # Show the column with answers & vitals inputs
|
| 131 |
q_dict, # Save question dict to state
|
| 132 |
-
gr.update(visible=False), # Hide loader
|
| 133 |
)
|
| 134 |
|
| 135 |
# Show loader quickly then run callback
|
| 136 |
-
gen_q_btn.click(lambda: gr.update(visible=True), None, loading_md, queue=False).then(
|
| 137 |
_gen_questions,
|
| 138 |
-
[age_input, gender_input, cc_input],
|
| 139 |
[*answer_boxes, answer_sec, question_state, loading_md],
|
| 140 |
)
|
| 141 |
|
|
|
|
| 56 |
question_state = gr.State({}) # holds the question dict
|
| 57 |
so_state = gr.State("") # holds Subjective & Objective text
|
| 58 |
|
| 59 |
+
# ββββββββββββββββββββββββββββββββββββββββββββββββββ Step 1 Demographics β Questions
|
| 60 |
+
# Personal details
|
| 61 |
with gr.Row():
|
| 62 |
+
name_input = gr.Textbox(label="Full Name", placeholder="Enter full name")
|
| 63 |
+
email_input = gr.Textbox(label="Email Address", placeholder="Enter email address")
|
| 64 |
+
|
| 65 |
+
# Demographics and chief complaint
|
| 66 |
+
with gr.Row():
|
| 67 |
+
age_input = gr.Number(label="Age (years)", precision=0, value=None)
|
| 68 |
gender_input = gr.Dropdown(["Male", "Female"], label="Gender")
|
| 69 |
cc_input = gr.Textbox(lines=2, label="Chief Complaint")
|
| 70 |
gen_q_btn = gr.Button("Generate Questions", elem_classes="orange-btn")
|
|
|
|
| 109 |
# Callbacks
|
| 110 |
# -------------------------------------------------------------------------
|
| 111 |
|
| 112 |
+
def _gen_questions(name, email, age, gender, cc):
|
| 113 |
+
"""Validate required fields, then call LLM β get question dict, then reveal answer boxes."""
|
| 114 |
+
# Ensure required fields are provided
|
| 115 |
+
if not name or not email:
|
| 116 |
+
return (
|
| 117 |
+
*[gr.update(visible=False) for _ in range(MAX_QUESTIONS)], # hide answer boxes
|
| 118 |
+
gr.update(visible=False), # hide answers section
|
| 119 |
+
{}, # clear question state
|
| 120 |
+
gr.update(value="β οΈ Please enter both Full Name and Email address.", visible=True), # show error
|
| 121 |
+
)
|
| 122 |
+
|
| 123 |
try:
|
| 124 |
q_dict = generate_question_dict(age, gender, cc)
|
| 125 |
except json.JSONDecodeError:
|
|
|
|
| 126 |
return (
|
|
|
|
| 127 |
*[gr.update(visible=False) for _ in range(MAX_QUESTIONS)],
|
| 128 |
gr.update(visible=False),
|
| 129 |
{},
|
| 130 |
+
gr.update(value="β οΈ LLM failed to return valid JSON. Please try again.", visible=True),
|
| 131 |
)
|
| 132 |
|
| 133 |
# Prepare exactly MAX_QUESTIONS Textbox updates
|
|
|
|
| 143 |
*box_updates, # Answer boxes
|
| 144 |
gr.update(visible=True), # Show the column with answers & vitals inputs
|
| 145 |
q_dict, # Save question dict to state
|
| 146 |
+
gr.update(visible=False), # Hide loader / message
|
| 147 |
)
|
| 148 |
|
| 149 |
# Show loader quickly then run callback
|
| 150 |
+
gen_q_btn.click(lambda: gr.update(value="β³ Loading ...", visible=True), None, loading_md, queue=False).then(
|
| 151 |
_gen_questions,
|
| 152 |
+
[name_input, email_input, age_input, gender_input, cc_input],
|
| 153 |
[*answer_boxes, answer_sec, question_state, loading_md],
|
| 154 |
)
|
| 155 |
|