Thanush commited on
Commit
5522bf8
·
1 Parent(s): d6da22c

Refactor MEDITRON_PROMPT in app.py to enhance medical assessment and recommendations, ensuring evidence-based practices and clear communication. Update name and age extraction logic for improved accuracy in user responses.

Browse files
Files changed (1) hide show
  1. app.py +23 -9
app.py CHANGED
@@ -31,13 +31,18 @@ Do NOT make specific prescriptions for prescription-only drugs.
31
  Respond empathetically and clearly. Always be professional and thorough."""
32
 
33
  MEDITRON_PROMPT = """<|im_start|>system
34
- You are a specialized medical assistant focusing ONLY on suggesting over-the-counter medicines and home remedies based on patient information.
35
- Based on the following patient information, provide ONLY:
36
- 1. One specific over-the-counter medicine with proper adult dosing instructions
37
- 2. One practical home remedy that might help
38
- 3. Clear guidance on when to seek professional medical care
39
- Be concise, practical, and focus only on general symptom relief. Do not diagnose. Include a disclaimer that you are not a licensed medical professional.
40
- <|im_end|>
 
 
 
 
 
41
  <|im_start|>user
42
  Patient information: {patient_info}
43
  <|im_end|>
@@ -111,12 +116,21 @@ def extract_name_age(messages):
111
  name, age = None, None
112
  for msg in messages:
113
  if msg.type == "human":
114
- age_match = re.search(r"(?:I am|I'm|age is|aged|My age is)\s*(\d{1,3})", msg.content, re.IGNORECASE)
 
115
  if age_match and not age:
116
  age = age_match.group(1)
117
- name_match = re.search(r"(?:my name is|I'm|I am)\s*([A-Za-z]+)", msg.content, re.IGNORECASE)
 
118
  if name_match and not name:
119
  name = name_match.group(1)
 
 
 
 
 
 
 
120
  return name, age
121
 
122
  @spaces.GPU
 
31
  Respond empathetically and clearly. Always be professional and thorough."""
32
 
33
  MEDITRON_PROMPT = """<|im_start|>system
34
+ You are a board-certified physician with extensive clinical experience. Your role is to provide evidence-based medical assessment and recommendations following standard medical practice.
35
+
36
+ For each patient case:
37
+ 1. Analyze presented symptoms systematically using medical terminology
38
+ 2. Create a structured differential diagnosis with most likely conditions first
39
+ 3. Recommend appropriate next steps (testing, monitoring, or treatment)
40
+ 4. Provide specific medication recommendations with precise dosing regimens
41
+ 5. Include clear red flags that would necessitate urgent medical attention
42
+ 6. Base all recommendations on current clinical guidelines and evidence-based medicine
43
+ 7. Maintain professional, clear, and compassionate communication
44
+
45
+ Follow standard clinical documentation format when appropriate and prioritize patient safety at all times. Remember to include appropriate medical disclaimers.
46
  <|im_start|>user
47
  Patient information: {patient_info}
48
  <|im_end|>
 
116
  name, age = None, None
117
  for msg in messages:
118
  if msg.type == "human":
119
+ # Try to extract age
120
+ age_match = re.search(r"(?:I am|I'm|age is|aged|My age is|im|i'm)\s*(\d{1,3})", msg.content, re.IGNORECASE)
121
  if age_match and not age:
122
  age = age_match.group(1)
123
+ # Try to extract name (avoid matching 'I'm' as name if age is present)
124
+ name_match = re.search(r"my name is\s*([A-Za-z]+)", msg.content, re.IGNORECASE)
125
  if name_match and not name:
126
  name = name_match.group(1)
127
+ # Fallback: if user says 'I'm <name> and <age>'
128
+ fallback_match = re.search(r"i['’`]?m\s*([A-Za-z]+)\s*(?:and|,)?\s*(\d{1,3})", msg.content, re.IGNORECASE)
129
+ if fallback_match:
130
+ if not name:
131
+ name = fallback_match.group(1)
132
+ if not age:
133
+ age = fallback_match.group(2)
134
  return name, age
135
 
136
  @spaces.GPU