Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,7 +7,7 @@ from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
|
|
| 7 |
MODEL_ID = "Muhammadidrees/my-gpt-oss"
|
| 8 |
|
| 9 |
tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
|
| 10 |
-
model = AutoModelForCausalLM.from_pretrained(MODEL_ID
|
| 11 |
pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)
|
| 12 |
|
| 13 |
|
|
@@ -25,7 +25,6 @@ def analyze(
|
|
| 25 |
except Exception:
|
| 26 |
bmi = "N/A"
|
| 27 |
|
| 28 |
-
# Fixed Instruction (no estimation, structured format only)
|
| 29 |
system_prompt = """
|
| 30 |
You are a professional AI Medical Assistant.
|
| 31 |
You are analyzing patient demographics and Levine biomarker panel values.
|
|
@@ -60,7 +59,6 @@ Output MUST strictly follow this structured format:
|
|
| 60 |
- Predictive longevity risk profile
|
| 61 |
"""
|
| 62 |
|
| 63 |
-
# Patient Data
|
| 64 |
patient_input = f"""
|
| 65 |
Patient Profile:
|
| 66 |
- Age: {age}
|
|
@@ -83,25 +81,21 @@ Lab Values:
|
|
| 83 |
|
| 84 |
prompt = system_prompt + "\n" + patient_input
|
| 85 |
|
| 86 |
-
# Call LLM
|
| 87 |
result = pipe(
|
| 88 |
prompt,
|
| 89 |
-
max_new_tokens=
|
| 90 |
do_sample=True,
|
| 91 |
temperature=0.3,
|
| 92 |
-
top_p=0.9
|
| 93 |
-
return_full_text=False
|
| 94 |
)
|
| 95 |
|
| 96 |
text = result[0]["generated_text"].strip()
|
| 97 |
|
| 98 |
-
#
|
| 99 |
-
left_sections = []
|
| 100 |
-
right_sections = []
|
| 101 |
capture_left = True
|
| 102 |
-
|
| 103 |
for line in text.splitlines():
|
| 104 |
-
if
|
| 105 |
capture_left = False
|
| 106 |
if capture_left:
|
| 107 |
left_sections.append(line)
|
|
@@ -124,23 +118,23 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
| 124 |
with gr.Row():
|
| 125 |
with gr.Column(scale=1):
|
| 126 |
gr.Markdown("### 👤 Demographics")
|
| 127 |
-
age = gr.Number(label="Age", value=
|
| 128 |
gender = gr.Dropdown(["Male", "Female"], label="Gender", value="Male")
|
| 129 |
height = gr.Number(label="Height (cm)", value=174)
|
| 130 |
weight = gr.Number(label="Weight (kg)", value=75)
|
| 131 |
|
| 132 |
gr.Markdown("### 🩸 Blood Panel")
|
| 133 |
-
wbc = gr.Number(label="WBC (K/uL)", value=
|
| 134 |
-
lymph = gr.Number(label="Lymphocytes (%)", value=
|
| 135 |
mcv = gr.Number(label="MCV (fL)", value=88)
|
| 136 |
rdw = gr.Number(label="RDW (%)", value=13)
|
| 137 |
|
| 138 |
with gr.Column(scale=1):
|
| 139 |
gr.Markdown("### 🧬 Chemistry Panel")
|
| 140 |
-
albumin = gr.Number(label="Albumin (g/dL)", value=
|
| 141 |
creatinine = gr.Number(label="Creatinine (mg/dL)", value=0.9)
|
| 142 |
-
glucose = gr.Number(label="Glucose (mg/dL)", value=
|
| 143 |
-
crp = gr.Number(label="CRP (mg/L)", value=0
|
| 144 |
alp = gr.Number(label="ALP (U/L)", value=70)
|
| 145 |
|
| 146 |
analyze_btn = gr.Button("🔬 Generate Report", variant="primary")
|
|
@@ -164,5 +158,6 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
| 164 |
"*⚠️ Disclaimer: This AI output is for educational purposes only and not a substitute for professional medical advice.*"
|
| 165 |
)
|
| 166 |
|
| 167 |
-
|
| 168 |
-
|
|
|
|
|
|
| 7 |
MODEL_ID = "Muhammadidrees/my-gpt-oss"
|
| 8 |
|
| 9 |
tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
|
| 10 |
+
model = AutoModelForCausalLM.from_pretrained(MODEL_ID) # works on CPU & GPU
|
| 11 |
pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)
|
| 12 |
|
| 13 |
|
|
|
|
| 25 |
except Exception:
|
| 26 |
bmi = "N/A"
|
| 27 |
|
|
|
|
| 28 |
system_prompt = """
|
| 29 |
You are a professional AI Medical Assistant.
|
| 30 |
You are analyzing patient demographics and Levine biomarker panel values.
|
|
|
|
| 59 |
- Predictive longevity risk profile
|
| 60 |
"""
|
| 61 |
|
|
|
|
| 62 |
patient_input = f"""
|
| 63 |
Patient Profile:
|
| 64 |
- Age: {age}
|
|
|
|
| 81 |
|
| 82 |
prompt = system_prompt + "\n" + patient_input
|
| 83 |
|
|
|
|
| 84 |
result = pipe(
|
| 85 |
prompt,
|
| 86 |
+
max_new_tokens=1000,
|
| 87 |
do_sample=True,
|
| 88 |
temperature=0.3,
|
| 89 |
+
top_p=0.9
|
|
|
|
| 90 |
)
|
| 91 |
|
| 92 |
text = result[0]["generated_text"].strip()
|
| 93 |
|
| 94 |
+
# Robust split into left (1–4) and right (5–6)
|
| 95 |
+
left_sections, right_sections = [], []
|
|
|
|
| 96 |
capture_left = True
|
|
|
|
| 97 |
for line in text.splitlines():
|
| 98 |
+
if "Tabular Mapping" in line:
|
| 99 |
capture_left = False
|
| 100 |
if capture_left:
|
| 101 |
left_sections.append(line)
|
|
|
|
| 118 |
with gr.Row():
|
| 119 |
with gr.Column(scale=1):
|
| 120 |
gr.Markdown("### 👤 Demographics")
|
| 121 |
+
age = gr.Number(label="Age", value=45)
|
| 122 |
gender = gr.Dropdown(["Male", "Female"], label="Gender", value="Male")
|
| 123 |
height = gr.Number(label="Height (cm)", value=174)
|
| 124 |
weight = gr.Number(label="Weight (kg)", value=75)
|
| 125 |
|
| 126 |
gr.Markdown("### 🩸 Blood Panel")
|
| 127 |
+
wbc = gr.Number(label="WBC (K/uL)", value=6.5)
|
| 128 |
+
lymph = gr.Number(label="Lymphocytes (%)", value=30)
|
| 129 |
mcv = gr.Number(label="MCV (fL)", value=88)
|
| 130 |
rdw = gr.Number(label="RDW (%)", value=13)
|
| 131 |
|
| 132 |
with gr.Column(scale=1):
|
| 133 |
gr.Markdown("### 🧬 Chemistry Panel")
|
| 134 |
+
albumin = gr.Number(label="Albumin (g/dL)", value=4.2)
|
| 135 |
creatinine = gr.Number(label="Creatinine (mg/dL)", value=0.9)
|
| 136 |
+
glucose = gr.Number(label="Glucose (mg/dL)", value=92)
|
| 137 |
+
crp = gr.Number(label="CRP (mg/L)", value=1.0)
|
| 138 |
alp = gr.Number(label="ALP (U/L)", value=70)
|
| 139 |
|
| 140 |
analyze_btn = gr.Button("🔬 Generate Report", variant="primary")
|
|
|
|
| 158 |
"*⚠️ Disclaimer: This AI output is for educational purposes only and not a substitute for professional medical advice.*"
|
| 159 |
)
|
| 160 |
|
| 161 |
+
|
| 162 |
+
if __name__ == "__main__":
|
| 163 |
+
demo.launch(server_name="0.0.0.0", server_port=7860)
|