Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
|
@@ -14,6 +14,13 @@ def analyze(
|
|
| 14 |
albumin, creatinine, glucose, crp, mcv, rdw, alp,
|
| 15 |
wbc, lymph, age, gender, height, weight
|
| 16 |
):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
# System-style instruction
|
| 18 |
system_prompt = (
|
| 19 |
"You are an advanced AI medical assistant. "
|
|
@@ -29,8 +36,8 @@ def analyze(
|
|
| 29 |
- Gender: {gender}
|
| 30 |
- Height: {height} cm
|
| 31 |
- Weight: {weight} kg
|
|
|
|
| 32 |
|
| 33 |
-
|
| 34 |
Lab Values:
|
| 35 |
- Albumin: {albumin} g/dL
|
| 36 |
- Creatinine: {creatinine} mg/dL
|
|
@@ -47,7 +54,7 @@ def analyze(
|
|
| 47 |
|
| 48 |
# Call LLM
|
| 49 |
result = pipe(prompt, max_new_tokens=1000, do_sample=True, temperature=0.6)
|
| 50 |
-
return result[
|
| 51 |
|
| 52 |
|
| 53 |
# Build Gradio UI
|
|
@@ -84,11 +91,12 @@ with gr.Blocks() as demo:
|
|
| 84 |
analyze_btn = gr.Button("🔎 Analyze")
|
| 85 |
output = gr.Textbox(label="AI Medical Assessment", lines=12)
|
| 86 |
|
|
|
|
| 87 |
analyze_btn.click(
|
| 88 |
fn=analyze,
|
| 89 |
inputs=[albumin, creatinine, glucose, crp, mcv, rdw, alp,
|
| 90 |
-
wbc, lymph, age, gender, height, weight
|
| 91 |
outputs=output
|
| 92 |
)
|
| 93 |
|
| 94 |
-
demo.launch()
|
|
|
|
| 14 |
albumin, creatinine, glucose, crp, mcv, rdw, alp,
|
| 15 |
wbc, lymph, age, gender, height, weight
|
| 16 |
):
|
| 17 |
+
# Calculate BMI (hidden from user, only passed to LLM)
|
| 18 |
+
try:
|
| 19 |
+
height_m = height / 100 # cm → m
|
| 20 |
+
bmi = round(weight / (height_m ** 2), 2)
|
| 21 |
+
except Exception:
|
| 22 |
+
bmi = "N/A"
|
| 23 |
+
|
| 24 |
# System-style instruction
|
| 25 |
system_prompt = (
|
| 26 |
"You are an advanced AI medical assistant. "
|
|
|
|
| 36 |
- Gender: {gender}
|
| 37 |
- Height: {height} cm
|
| 38 |
- Weight: {weight} kg
|
| 39 |
+
- BMI: {bmi}
|
| 40 |
|
|
|
|
| 41 |
Lab Values:
|
| 42 |
- Albumin: {albumin} g/dL
|
| 43 |
- Creatinine: {creatinine} mg/dL
|
|
|
|
| 54 |
|
| 55 |
# Call LLM
|
| 56 |
result = pipe(prompt, max_new_tokens=1000, do_sample=True, temperature=0.6)
|
| 57 |
+
return result[0]["generated_text"]
|
| 58 |
|
| 59 |
|
| 60 |
# Build Gradio UI
|
|
|
|
| 91 |
analyze_btn = gr.Button("🔎 Analyze")
|
| 92 |
output = gr.Textbox(label="AI Medical Assessment", lines=12)
|
| 93 |
|
| 94 |
+
# Run analysis
|
| 95 |
analyze_btn.click(
|
| 96 |
fn=analyze,
|
| 97 |
inputs=[albumin, creatinine, glucose, crp, mcv, rdw, alp,
|
| 98 |
+
wbc, lymph, age, gender, height, weight],
|
| 99 |
outputs=output
|
| 100 |
)
|
| 101 |
|
| 102 |
+
demo.launch()
|