Muhammadidrees commited on
Commit
06ceb89
·
verified ·
1 Parent(s): 561281d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -19
app.py CHANGED
@@ -26,8 +26,9 @@ print("Model loaded successfully!")
26
  print(f"Device map: {model.hf_device_map}")
27
  print(f"Model device: {next(model.parameters()).device}")
28
 
 
29
  # =======================================================
30
- # Generate Doctor Response (Stateless)
31
  # =======================================================
32
  def generate_doctor_response(history):
33
  user_message = history[-1]["content"]
@@ -37,25 +38,23 @@ def generate_doctor_response(history):
37
  yield history
38
  return
39
 
40
- # Single-turn prompt (no past context)
41
- prompt = """# 🩺 You are a highly knowledgeable Medical Expert
42
-
43
- **Roles:**
44
- - **Doctor:** Diagnose symptoms, ask relevant follow-up questions, and provide medical advice.
45
- - **Nutritionist:** Give diet and lifestyle recommendations.
46
- - **Medical Teacher:** Explain complex medical terms and conditions in simple, understandable language.
47
 
48
- **Guidelines:**
49
- 1. Ask **only one follow-up question at a time** if necessary.
50
- 2. Provide advice after collecting enough information.
51
- 3. Be **empathetic, professional, and conversational**.
52
- 4. Include disclaimers when needed:
53
- ⚕️ *This is AI-generated information and not a substitute for professional medical advice. Please consult a healthcare provider for proper diagnosis and treatment.*
54
- 5. Keep answers concise, clear, and actionable.
55
 
56
- Respond naturally to the following patient message:
57
 
58
- Patient: """ + user_message + "\nDoctor:"
 
 
59
 
60
  # Tokenize input
61
  inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
@@ -80,8 +79,8 @@ Patient: """ + user_message + "\nDoctor:"
80
 
81
  # Keep concise output
82
  response = ". ".join(response.split(". ")[:3]).strip()
83
- if response.lower().startswith("doctor:"):
84
- response = response[7:].strip()
85
  if len(response) < 10:
86
  response = "I understand your concern. Could you please provide more details about your symptoms?"
87
 
 
26
  print(f"Device map: {model.hf_device_map}")
27
  print(f"Model device: {next(model.parameters()).device}")
28
 
29
+
30
  # =======================================================
31
+ # Generate Doctor Response (Stateless + Clean Replies)
32
  # =======================================================
33
  def generate_doctor_response(history):
34
  user_message = history[-1]["content"]
 
38
  yield history
39
  return
40
 
41
+ # 🩺 New Prompt (no 'Patient:' or 'Doctor:' lines)
42
+ prompt = f"""
43
+ You are a compassionate and professional medical expert.
44
+ Your role is to help users by providing clear, empathetic, and accurate medical information.
 
 
 
45
 
46
+ Guidelines:
47
+ 1. Do NOT include words like 'Doctor:' or 'Patient:' in your replies.
48
+ 2. Respond naturally and directly to the user's concern.
49
+ 3. Keep answers short, clear, and medically sound.
50
+ 4. Add a disclaimer when appropriate:
51
+ ⚕️ *This is AI-generated information and not a substitute for professional medical advice.*
 
52
 
53
+ Now, please respond to the user's message below:
54
 
55
+ User: {user_message}
56
+ Assistant:
57
+ """
58
 
59
  # Tokenize input
60
  inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
 
79
 
80
  # Keep concise output
81
  response = ". ".join(response.split(". ")[:3]).strip()
82
+ if response.lower().startswith("assistant:"):
83
+ response = response[10:].strip()
84
  if len(response) < 10:
85
  response = "I understand your concern. Could you please provide more details about your symptoms?"
86