Muhammadidrees commited on
Commit
aaa2d4c
·
verified ·
1 Parent(s): 5b9460d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -30
app.py CHANGED
@@ -8,7 +8,6 @@ tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
8
  model = AutoModelForCausalLM.from_pretrained(MODEL_ID, device_map="auto")
9
  pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)
10
 
11
-
12
  # Function to build structured input and query the LLM
13
  def analyze(
14
  albumin, creatinine, glucose, crp, mcv, rdw, alp,
@@ -21,9 +20,14 @@ def analyze(
21
  except Exception:
22
  bmi = "N/A"
23
 
24
- # System-style instruction
25
  system_prompt = (
26
- """Executive Summary
 
 
 
 
 
27
  - Longevity Vitality Score (out of 100)
28
  - Top Priority Areas for Optimization
29
  - Key Strengths
@@ -52,46 +56,45 @@ def analyze(
52
  - Predicted nutrient needs (iron, B12, folate, copper) framed as optimization
53
  - Patterns in WBC/lymphocyte values for general resilience
54
  - Predictive wellness trends (non-medical)
 
 
55
 
56
- """ )
57
-
58
- # Construct patient profile input
59
  patient_input = f"""
60
- Patient Profile:
61
- - Age: {age}
62
- - Gender: {gender}
63
- - Height: {height} cm
64
- - Weight: {weight} kg
65
- - BMI: {bmi}
66
-
67
- Lab Values:
68
- - Albumin: {albumin} g/dL
69
- - Creatinine: {creatinine} mg/dL
70
- - Glucose: {glucose} mg/dL
71
- - C-Reactive Protein: {crp} mg/L
72
- - Mean Cell Volume: {mcv} fL
73
- - Red Cell Distribution Width: {rdw} %
74
- - Alkaline Phosphatase: {alp} U/L
75
- - White Blood Cell Count: {wbc} K/uL
76
- - Lymphocyte Percentage: {lymph} %
77
- """
78
 
79
  prompt = system_prompt + "\n" + patient_input
80
 
81
- # Call LLM (exclude echoed input)
82
  result = pipe(
83
  prompt,
84
- max_new_tokens=2000,
85
  do_sample=True,
86
  temperature=0.6,
87
  return_full_text=False
88
  )
89
  return result[0]["generated_text"].strip()
90
 
91
-
92
  # Build Gradio UI
93
  with gr.Blocks() as demo:
94
- gr.Markdown("## 🧪 Medical Insights AI — Enter Patient Data")
95
 
96
  with gr.Row():
97
  albumin = gr.Number(label="Albumin (g/dL)")
@@ -121,9 +124,8 @@ with gr.Blocks() as demo:
121
  alp = gr.Number(label="Alkaline Phosphatase (U/L)")
122
 
123
  analyze_btn = gr.Button("🔎 Analyze")
124
- output = gr.Textbox(label="AI Medical Assessment", lines=12)
125
 
126
- # Run analysis
127
  analyze_btn.click(
128
  fn=analyze,
129
  inputs=[albumin, creatinine, glucose, crp, mcv, rdw, alp,
 
8
  model = AutoModelForCausalLM.from_pretrained(MODEL_ID, device_map="auto")
9
  pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)
10
 
 
11
  # Function to build structured input and query the LLM
12
  def analyze(
13
  albumin, creatinine, glucose, crp, mcv, rdw, alp,
 
20
  except Exception:
21
  bmi = "N/A"
22
 
23
+ # System-style instruction (non-medical)
24
  system_prompt = (
25
+ """You are a wellness assistant.
26
+ Do NOT provide medical insights, diagnoses, or test recommendations.
27
+ Only use neutral, non-medical, wellness-oriented language (e.g., energy, balance, recovery, nutrition).
28
+ Strictly follow the structure below and generate only these sections with no extra headings:
29
+
30
+ Executive Summary
31
  - Longevity Vitality Score (out of 100)
32
  - Top Priority Areas for Optimization
33
  - Key Strengths
 
56
  - Predicted nutrient needs (iron, B12, folate, copper) framed as optimization
57
  - Patterns in WBC/lymphocyte values for general resilience
58
  - Predictive wellness trends (non-medical)
59
+ """
60
+ )
61
 
62
+ # Construct profile input
 
 
63
  patient_input = f"""
64
+ Patient Profile:
65
+ - Age: {age}
66
+ - Gender: {gender}
67
+ - Height: {height} cm
68
+ - Weight: {weight} kg
69
+ - BMI: {bmi}
70
+
71
+ Lab Values:
72
+ - Albumin: {albumin} g/dL
73
+ - Creatinine: {creatinine} mg/dL
74
+ - Glucose: {glucose} mg/dL
75
+ - C-Reactive Protein: {crp} mg/L
76
+ - Mean Cell Volume: {mcv} fL
77
+ - Red Cell Distribution Width: {rdw} %
78
+ - Alkaline Phosphatase: {alp} U/L
79
+ - White Blood Cell Count: {wbc} K/uL
80
+ - Lymphocyte Percentage: {lymph} %
81
+ """
82
 
83
  prompt = system_prompt + "\n" + patient_input
84
 
85
+ # Call LLM
86
  result = pipe(
87
  prompt,
88
+ max_new_tokens=1200,
89
  do_sample=True,
90
  temperature=0.6,
91
  return_full_text=False
92
  )
93
  return result[0]["generated_text"].strip()
94
 
 
95
  # Build Gradio UI
96
  with gr.Blocks() as demo:
97
+ gr.Markdown("## 🧪 Wellness Insights AI — Enter Profile Data")
98
 
99
  with gr.Row():
100
  albumin = gr.Number(label="Albumin (g/dL)")
 
124
  alp = gr.Number(label="Alkaline Phosphatase (U/L)")
125
 
126
  analyze_btn = gr.Button("🔎 Analyze")
127
+ output = gr.Textbox(label="AI Wellness Assessment", lines=12)
128
 
 
129
  analyze_btn.click(
130
  fn=analyze,
131
  inputs=[albumin, creatinine, glucose, crp, mcv, rdw, alp,