sunbal7 commited on
Commit
0e31758
·
verified ·
1 Parent(s): 2fd7766

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +183 -622
app.py CHANGED
@@ -191,6 +191,8 @@ def init_session_state():
191
  st.session_state.groq_api_key = ''
192
  if 'models_loaded' not in st.session_state:
193
  st.session_state.models_loaded = False
 
 
194
 
195
  # Healthcare quotes database
196
  HEALTHCARE_QUOTES = [
@@ -230,7 +232,7 @@ class GroqClient:
230
  "Content-Type": "application/json"
231
  }
232
 
233
- def chat_completions_create(self, messages, model="llama3-8b-8192", temperature=0.3, max_tokens=1024):
234
  try:
235
  url = f"{self.base_url}/chat/completions"
236
  data = {
@@ -253,59 +255,41 @@ class GroqClient:
253
  class HealthcareChatbot:
254
  def __init__(self, groq_client=None):
255
  self.groq_client = groq_client
256
- self.medical_knowledge_base = {
257
- 'heart_disease': {
258
- 'symptoms': ["Chest pain or discomfort", "Shortness of breath", "Pain in arms, neck, jaw", "Nausea", "Fatigue", "Dizziness"],
259
- 'risk_factors': ["High blood pressure", "High cholesterol", "Smoking", "Diabetes", "Obesity", "Family history", "Physical inactivity"],
260
- 'prevention': ["Healthy diet low in saturated fats", "Regular exercise 30 mins daily", "No smoking", "Weight management", "Stress management", "Regular check-ups"],
261
- 'emergency_signs': ["Severe chest pain", "Difficulty breathing", "Fainting", "Rapid heartbeat", "Pain spreading to arms/shoulders"]
262
- },
263
- 'diabetes': {
264
- 'symptoms': ["Increased thirst and hunger", "Frequent urination", "Fatigue", "Blurred vision", "Slow healing wounds", "Unexplained weight loss"],
265
- 'risk_factors': ["Family history", "Overweight (BMI > 25)", "High blood pressure", "Physical inactivity", "Age over 45", "Gestational diabetes history"],
266
- 'prevention': ["Balanced diet with controlled carbs", "Regular physical activity", "Weight management", "Blood sugar monitoring", "Regular health screenings"],
267
- 'emergency_signs': ["Blood sugar >300 mg/dL or <70 mg/dL", "Confusion or disorientation", "Fruity breath odor", "Rapid breathing", "Loss of consciousness"]
268
- },
269
- 'hypertension': {
270
- 'symptoms': ["Headaches", "Dizziness", "Blurred vision", "Shortness of breath", "Chest pain", "Nosebleeds"],
271
- 'risk_factors': ["Family history", "Age over 65", "Obesity", "High salt intake", "Stress", "Alcohol consumption", "Smoking"],
272
- 'prevention': ["DASH diet (low sodium)", "Regular aerobic exercise", "Weight management", "Stress reduction", "Limit alcohol", "No smoking"],
273
- 'emergency_signs': ["Severe headache", "Chest pain", "Difficulty breathing", "Vision changes", "Confusion", "Seizures"]
274
- }
275
- }
276
 
277
  def get_response(self, user_input, language='English'):
278
- # If Groq client is available, use it for more intelligent responses
279
- if self.groq_client and self.groq_client.api_key:
280
  try:
281
  return self._get_groq_response(user_input, language)
282
  except Exception as e:
283
- st.error(f"Groq API error: {str(e)}. Using rule-based response.")
 
284
 
285
- # Fallback to rule-based responses
286
- return self._get_rule_based_response(user_input, language)
287
 
288
  def _get_groq_response(self, user_input, language):
289
  system_prompt = """You are Dr. SehatAI, a professional medical AI assistant for Pakistani patients.
290
- Provide accurate, professional medical advice in a compassionate doctor-patient manner.
291
-
292
  CRITICAL GUIDELINES:
293
- 1. NEVER start with generic welcome messages or lists of services
294
- 2. ALWAYS provide specific, direct answers to the user's exact question
295
- 3. Respond like a professional doctor would to a patient's specific concern
296
- 4. Provide detailed medical explanations, practical advice, and when to seek help
297
- 5. Be empathetic but professional and authoritative
298
- 6. Focus on the specific medical issue the user is asking about
299
- 7. If it's a greeting, respond professionally and ask how you can help with their health concerns
300
-
301
- Format your response as a medical professional would speak to a patient.
302
-
303
- IMPORTANT: Never use generic welcome messages. Always answer the specific question asked."""
304
 
305
  if language == 'Urdu':
306
- system_prompt += " Respond in Urdu with professional medical terminology. Be direct and specific to the user's question. Never use generic welcome messages."
307
  else:
308
- system_prompt += " Respond in English with professional medical advice. Be direct and specific to the user's question. Never use generic welcome messages."
309
 
310
  messages = [
311
  {"role": "system", "content": system_prompt},
@@ -315,643 +299,213 @@ class HealthcareChatbot:
315
  response = self.groq_client.chat_completions_create(
316
  messages=messages,
317
  model="llama3-8b-8192",
318
- temperature=0.3,
319
  max_tokens=1024
320
  )
321
 
322
  bot_response = response['choices'][0]['message']['content']
323
 
324
- # Add disclaimer
325
  if language == 'Urdu':
326
- bot_response += "\n\n⚠️ براہ کرم نوٹ کریں: یہ ایک AI اسسٹنٹ ہے۔ سنگین طبی حالات کے لیے ہمیشہ کوالیفائیڈ ڈاکٹر سے مشورہ کریں۔"
327
  else:
328
- bot_response += "\n\n⚠️ Please note: This is an AI assistant. Always consult qualified doctors for serious medical conditions."
329
 
330
  return bot_response
331
 
332
- def _get_rule_based_response(self, user_input, language):
 
333
  user_input_lower = user_input.lower().strip()
334
 
335
- # Improved response mapping
336
- response_map = {
337
- 'heart': (['heart', 'cardiac', 'chest pain', 'cholesterol', 'دل', 'سینے میں درد', 'heart attack'],
338
- self._format_heart_response),
339
- 'diabetes': (['diabetes', 'sugar', 'glucose', 'insulin', 'ذیابیطس', 'شوگر'],
340
- self._format_diabetes_response),
341
- 'hypertension': (['blood pressure', 'hypertension', 'bp', 'بلڈ پریشر', 'ہائی بلڈ پریشر'],
342
- self._format_hypertension_response),
343
- 'nutrition': (['diet', 'nutrition', 'food', 'eating', 'غذا', 'کھانا', 'diet'],
344
- self._format_nutrition_response),
345
- 'exercise': (['exercise', 'workout', 'fitness', 'gym', 'ورزش', 'جم', 'physical'],
346
- self._format_exercise_response),
347
- 'symptoms': (['symptom', 'pain', 'fever', 'headache', 'علامت', 'درد', 'بخار'],
348
- self._format_symptoms_response),
349
- 'medicine': (['medicine', 'medication', 'drug', 'treatment', 'دوا', 'علاج'],
350
- self._format_medication_response),
351
- 'emergency': (['emergency', 'urgent', 'help', 'ہنگامی', 'فوری'],
352
- self._format_emergency_response),
353
- 'general': (['health', 'wellness', 'prevention', 'صحت', 'تندرستی'],
354
- self._format_general_health_response)
355
- }
356
-
357
- # Check for greetings first
358
  if any(word in user_input_lower for word in ['hello', 'hi', 'hey', 'salam', 'السلام علیکم']):
359
- return self._format_professional_greeting(user_input, language)
360
 
361
- # Check for matching categories
362
- for category, (keywords, response_func) in response_map.items():
363
- if any(keyword in user_input_lower for keyword in keywords):
364
- return response_func(language)
365
 
366
- # Default professional response for unknown queries
367
- return self._format_professional_response(user_input, language)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
368
 
369
- def _format_professional_greeting(self, user_input, language):
370
- """Professional response for greetings"""
371
  if language == 'English':
372
- return f"""
373
- **Dr. SehatAI:** Thank you for your message. I understand you're reaching out about health concerns.
374
-
375
- As your medical AI assistant, I'm here to provide specific, professional healthcare guidance. Please tell me about your specific health concern or question, and I'll provide detailed medical advice tailored to your situation.
376
 
377
- I specialize in cardiovascular health, diabetes management, blood pressure control, and general wellness.
378
 
379
- What specific health issue would you like to discuss today?
380
 
381
- *Note: I'm an AI assistant. For serious medical concerns, always consult a qualified healthcare professional.*
382
- """
383
  else:
384
- return f"""
385
- **ڈاکٹر سیحت اے آئی:** آپ کے پیغام کا شکریہ۔ میں سمجھتا ہوں کہ آپ صحت کے مسائل کے بارے میں رابطہ کر رہے ہیں۔
386
-
387
- آپ کے میڈیکل AI اسسٹنٹ کے طور پر، میں مخصوص، پیشہ ورانہ ہیلتھ کیئر رہنمائی فراہم کرنے کے لیے یہاں ہوں۔ براہ کرم مجھے اپنے مخصوص صحت کے مسئلے یا سوال کے بارے میں بتائیں، اور میں آپ کی صورت حال کے مطابق تفصیلی طبی مشورہ دوں گا۔
388
 
389
- میں قلبی صحت، ذیابیطس مینجمنٹ، بلڈ پریشر کنٹرول، اور عام تندرستی میں مہارت رکھتا ہوں۔
390
 
391
- آج آپ کون سا مخصوص صحت کا مسئلہ زیر بحث لانا چاہیں گے؟
392
 
393
- *نوٹ: میں ایک AI اسسٹنٹ ہوں۔ سنگین طبی مسائل کے لیے، ہمیشہ کوالیفائیڈ ہیلتھ کیئر پروفیشنل سے مشورہ کریں۔*
394
- """
395
 
396
- def _format_professional_response(self, user_input, language):
397
- """Improved professional response for unknown queries"""
398
  if language == 'English':
399
- return f"""
400
- **Dr. SehatAI:** I understand you're asking about: "{user_input}"
401
-
402
- I'm here to provide professional medical guidance. Based on your query, here are the key areas I can help you with:
403
-
404
- 🔍 **Medical Assessment & Risk Prediction**
405
- Heart disease risk evaluation
406
- • Diabetes screening and management
407
- Blood pressure monitoring
408
- • Symptom analysis and triage
409
-
410
- 💊 **Treatment & Medication Guidance**
411
- • Medication safety information
412
- • Treatment protocols for common conditions
413
- • Drug interaction checks
414
-
415
- 🩺 **Clinical Consultation**
416
- • Interpretation of medical reports
417
- • Preventive healthcare strategies
418
- • Lifestyle modification advice
419
-
420
- 🚨 **Emergency Guidance**
421
- • Identifying critical symptoms
422
- • First aid recommendations
423
- • When to seek immediate care
424
-
425
- Please ask me specific questions about:
426
- • Your symptoms or health concerns
427
- • Medical test results interpretation
428
- • Medication queries
429
- • Preventive health measures
430
-
431
- *Note: For medical emergencies, please call 1122 immediately or visit your nearest hospital.*
432
- """
433
  else:
434
- return f"""
435
- **ڈاکٹر سیحت اے آئی:** میں سمجھتا ہوں کہ آپ پوچھ رہے ہیں: "{user_input}"
436
-
437
- میں پیشہ ورانہ طبی رہنمائی فراہم کرنے کے لیے یہاں ہوں۔ آپ کے سوال کی بنیاد پر، میں آپ کی ان اہم شعبوں میں مدد کر سکتا ہوں:
438
-
439
- 🔍 **طبی تشخیص اور خطرے کی پیشگوئی**
440
- • دل کی بیماری کے خطرے کا جائزہ
441
- • ذیابیطس کی اسکریننگ اور انتظام
442
- • بلڈ پریشر کی نگرانی
443
- • علامات کا تجزیہ اور ترجیح
444
-
445
- 💊 **علاج اور دوائیوں کی رہنمائی**
446
- • دوائیوں کی حفاظت کی معلومات
447
- • عام حالات کے لیے علاج کے طریقہ کار
448
- • دوائیوں کے باہمی تعامل کی چیکنگ
449
-
450
- 🩺 **کلینیکل مشاورت**
451
- • طبی رپورٹس کی تشریح
452
- • احتیاطی ہیلتھ کیئر کی حکمت عملی
453
- • طرز زندگی میں تبدیلی کے مشورے
454
-
455
- 🚨 **ہنگامی رہنمائی**
456
- • critical علامات کی شناخت
457
- • فرسٹ ایڈ کی سفارشات
458
- • فوری دیکھ بھال کی ضرورت کا تعین
459
-
460
- براہ کرم مجھ سے ان کے بارے میں مخصوص سوالات پوچھیں:
461
- • آپ کی علامات یا صحت کے خدشات
462
- • طبی ٹیسٹ کے نتائج کی تشریح
463
- • دوائیوں کے سوالات
464
- • احتیاطی صحت کے اقدامات
465
-
466
- *نوٹ: طبی ایمرجنسیز کے لیے، براہ کرم فوری طور پر 1122 پر کال کریں یا اپنے قریبی ہسپتال جائیں۔*
467
- """
468
-
469
- def _format_heart_response(self, language):
470
- knowledge = self.medical_knowledge_base['heart_disease']
471
- if language == 'English':
472
- return f"""
473
- **Dr. SehatAI - Cardiac Specialist:**
474
- Based on your question about heart health, here's my professional assessment:
475
 
476
- **Cardiac Symptoms to Monitor:**
477
- {chr(10).join(['• ' + symptom for symptom in knowledge['symptoms']])}
478
 
479
- **Key Risk Factors:**
480
- {chr(10).join(['• ' + factor for factor in knowledge['risk_factors']])}
481
 
482
- **Preventive Cardiology Recommendations:**
483
- {chr(10).join(['• ' + tip for tip in knowledge['prevention']])}
484
 
485
- **🚨 Cardiac Emergency Indicators:**
486
- {chr(10).join(['• ' + sign for sign in knowledge['emergency_signs']])}
 
 
 
487
 
488
- **Clinical Monitoring Protocol:**
489
- • Regular BP monitoring (weekly if hypertensive)
490
- • Lipid profile every 6-12 months
491
- • ECG if symptomatic
492
- • Stress testing as clinically indicated
493
 
494
- *Medical Note: Cardiovascular disease remains the leading cause of mortality. Early intervention significantly improves outcomes.*
495
- """
496
- else:
497
- return f"""
498
- **ڈاکٹر سیحت اے آئی - کارڈیاک اسپیشلسٹ:**
499
- دل کی صحت کے بارے میں آپ کے سوال کی بنیاد پر، یہ میرا پیشہ ورانہ جائزہ ہے:
500
 
501
- **نگرانی کرنے والی قلبی علامات:**
502
- {chr(10).join(['• ' + symptom for symptom in ['سینے میں درد یا بے چینی', 'سانس لینے میں دشواری', 'بازوؤں، گردن، جبڑے میں درد', 'متلی', 'تھکاوٹ', 'چکر آنا']])}
 
503
 
504
- **اہم خطرے کے عوامل:**
505
- {chr(10).join(['• ' + factor for factor in ['ہائی بلڈ پریشر', 'ہائی کولیسٹرول', 'سگریٹ نوشی', 'ذیابیطس', 'موٹاپا', 'خاندانی تاریخ', 'جسمانی غیر فعالیت']])}
506
 
507
- **احتیاطی کارڈیالوجی سفارشات:**
508
- {chr(10).join(['• ' + tip for tip in ['سیر شدہ چکنائی سے پاک صحت مند غذا', 'روزانہ 30 منٹ باقاعدہ ورزش', 'سگریٹ نوشی سے پرہیز', 'وزن کا انتظام', 'تناؤ کا انتظام', 'باقاعدہ چیک اپ']])}
509
 
510
- **🚨 قلبی ہنگامی اشارے:**
511
- {chr(10).join(['• ' + sign for sign in ['شدید سینے میں درد', 'سانس لینے میں شدید دشواری', 'بیہوش ہونا', 'تیز دل کی دھڑکن', 'بازو/کندھوں میں پھیلنے والا درد']])}
512
 
513
- *طبی نوٹ: قلبی بیماری اموات کی سب سے بڑی وجہ بنی ہوئی ہے۔ ابتدائی مداخلت نتائج کو نمایاں طور پر بہتر بناتی ہے۔*
514
- """
515
 
516
- def _format_diabetes_response(self, language):
517
- knowledge = self.medical_knowledge_base['diabetes']
518
  if language == 'English':
519
- return f"""
520
- **Dr. SehatAI - Endocrinology Specialist:**
521
- Regarding your diabetes inquiry, here's my clinical perspective:
522
 
523
- **Common Diabetic Symptoms:**
524
- {chr(10).join(['• ' + symptom for symptom in knowledge['symptoms']])}
525
 
526
- **Diabetes Risk Profile:**
527
- {chr(10).join(['• ' + factor for factor in knowledge['risk_factors']])}
528
 
529
- **Comprehensive Diabetes Management:**
530
- {chr(10).join(['• ' + tip for tip in knowledge['prevention']])}
531
 
532
- **🚨 Diabetic Emergency Situations:**
533
- {chr(10).join(['• ' + sign for sign in knowledge['emergency_signs']])}
 
534
 
535
- **Glycemic Control Targets:**
536
- • Fasting glucose: 80-130 mg/dL
537
- • Postprandial glucose: <180 mg/dL
538
- • HbA1c: <7.0% (individualized)
539
- • Regular ophthalmologic exams
540
- • Annual foot examination
541
 
542
- *Clinical Insight: Consistent glucose monitoring and lifestyle modification are cornerstone to diabetes management.*
543
- """
544
- else:
545
- return f"""
546
- **ڈاکٹر سیحت اے آئی - اینڈوکرینالوجی اسپیشلسٹ:**
547
- ذیابیطس کے بارے میں آپ کی استفسار کے حوالے سے، یہ میرا کلینیکل نقطہ نظر ہے:
548
 
549
- **عام ذیابیطس کی علامات:**
550
- {chr(10).join(['• ' + symptom for symptom in ['زیادہ پیاس اور بھوک لگنا', 'بار بار پیشاب آنا', 'تھکاوٹ', 'دھندلا نظر آنا', 'زخموں کا دیر سے بھرنا', 'بے وجہ وزن میں کمی']])}
551
 
552
- **ذیابیطس کا خطرہ پروفائل:**
553
- {chr(10).join(['• ' + factor for factor in ['خاندانی تاریخ', 'وزن زیادہ ہونا (BMI > 25)', 'ہائی بلڈ پریشر', 'جسمانی غیر فعالیت', '45 سال سے زیادہ عمر', 'حمل کی ذیابیطس کی تاریخ']])}
 
 
 
554
 
555
- **جامع ذیابیطس مینجمنٹ:**
556
- {chr(10).join(['• ' + tip for tip in ['کنٹرول کاربوہائیڈریٹ کے ساتھ متوازن غذا', 'باقاعدہ جسمانی سرگرمی', 'وزن کا انتظام', 'بلڈ شوگر مانیٹرنگ', 'باقاعدہ صحت کی اسکریننگ']])}
557
 
558
- **🚨 ذیابیطس کی ہنگامی صورتحال:**
559
- {chr(10).join(['• ' + sign for sign in ['بلڈ شوگر >300 mg/dL یا <70 mg/dL', 'الجھن یا بے ترتیبی', 'پھل کی سی بو والی سانس', 'تیز سانس لینا', 'ہوش کا ضیاع']])}
 
 
 
560
 
561
- *کلینیکل بصیرت: مستقل گلوکوز مانیٹرنگ اور طرز زندگی میں ترمیم ذیابیطس کے انتظام کی بنیاد ہیں۔*
562
- """
563
 
564
- def _format_hypertension_response(self, language):
565
- knowledge = self.medical_knowledge_base['hypertension']
566
  if language == 'English':
567
- return f"""
568
- **Dr. SehatAI - Hypertension Specialist:**
569
- Regarding your blood pressure concerns, here's my medical assessment:
570
 
571
- **Hypertension Symptoms:**
572
- {chr(10).join(['• ' + symptom for symptom in knowledge['symptoms']])}
573
 
574
- **Hypertension Risk Factors:**
575
- {chr(10).join(['• ' + factor for factor in knowledge['risk_factors']])}
576
 
577
- **Blood Pressure Management Protocol:**
578
- {chr(10).join(['• ' + tip for tip in knowledge['prevention']])}
579
 
580
- **🚨 Hypertensive Crisis Indicators:**
581
- {chr(10).join(['• ' + sign for sign in knowledge['emergency_signs']])}
582
 
583
- **Blood Pressure Classification:**
584
- • Normal: <120/<80 mmHg
585
- • Elevated: 120-129/<80 mmHg
586
- • Stage 1 HTN: 130-139/80-89 mmHg
587
- • Stage 2 HTN: ≥140/90 mmHg
588
- • Hypertensive Crisis: >180/>120 mmHg
589
-
590
- *Clinical Note: Hypertension is often asymptomatic until complications develop. Regular monitoring is essential.*
591
- """
592
  else:
593
- return f"""
594
- **ڈاکٹر سیحت اے آئی - ہائی بلڈ پریشر اسپیشلسٹ:**
595
- بلڈ پریشر کے بارے میں آپ کی تشویش کے حوالے سے، یہ میری طبی تشخیص ہے:
596
 
597
- **ہائی بلڈ پریشر کی علامات:**
598
- {chr(10).join(['• ' + symptom for symptom in ['سر درد', 'چکر آنا', 'دھندلا نظر آنا', 'سانس لینے میں دشواری', 'سینے میں درد', 'ناک سے خون آنا']])}
599
 
600
- **ہائی بلڈ پریشر کے خطرے کے عوامل:**
601
- {chr(10).join(['• ' + factor for factor in ['خاندانی تاریخ', '65 سال سے زیادہ عمر', 'موٹاپا', 'زیادہ نمک کا استعمال', 'تناؤ', 'شراب کا استعمال', 'سگریٹ نوشی']])}
602
 
603
- **بلڈ پریشر مینجمنٹ پروٹوکول:**
604
- {chr(10).join(['• ' + tip for tip in ['ڈیش ڈائٹ (کم سوڈیم)', 'باقاعدہ ایروبک ورزش', 'وزن کا انتظام', 'تناؤ میں کمی', 'شراب کو محدود کریں', 'سگریٹ نوشی سے پرہیز']])}
605
 
606
- **🚨 ہائی بلڈ پریشر کے بحران کے اشارے:**
607
- {chr(10).join(['• ' + sign for sign in ['شدید سر درد', 'سینے میں درد', 'سانس لینے میں دشواری', 'بینائی میں تبدیلی', 'الجھن', 'دورے']])}
608
 
609
- *کلینیکل نوٹ: ہائی بلڈ پریشر اکثر پیچیدگیاں پیدا ہونے تک بے علامت ہوتا ہے۔ باقاعدہ نگرانی ضروری ہے۔*
610
- """
611
-
612
- def _format_nutrition_response(self, language):
613
- if language == 'English':
614
- return """
615
- **Dr. SehatAI - Clinical Nutrition Specialist:**
616
- Based on your nutritional inquiry, here are evidence-based dietary recommendations:
617
-
618
- **Core Nutritional Principles:**
619
- • Consume 5-9 servings of fruits/vegetables daily
620
- • Prioritize whole grains over refined carbohydrates
621
- • Include lean protein sources (poultry, fish, legumes)
622
- • Maintain hydration (2-3 liters daily)
623
- • Minimize processed foods and added sugars
624
-
625
- **Condition-Specific Dietary Modifications:**
626
- • **Cardiac Health**: Mediterranean diet, omega-3 fatty acids
627
- • **Diabetes**: Controlled carbohydrate intake, high fiber
628
- • **Hypertension**: DASH diet (<2300mg sodium/day), potassium-rich foods
629
-
630
- **Cultural Dietary Adaptations for Pakistan:**
631
- • Choose whole wheat chapati over refined flour
632
- • Incorporate lentils (daal) and legumes regularly
633
- • Utilize healthy cooking oils (canola, olive, mustard)
634
- • Limit ghee and saturated fat consumption
635
-
636
- *Nutritional Note: Balanced nutrition forms the foundation of preventive healthcare and chronic disease management.*
637
- """
638
- else:
639
- return """
640
- **ڈاکٹر سیحت اے آئی - کلینیکل نیوٹریشن اسپیشلسٹ:**
641
- آپ کی غذائی استفسار کی بنیاد پر، یہ ثبوت پر مبنی غذائی سفارشات ہیں:
642
-
643
- **بنیادی غذائی اصول:**
644
- • روزانہ 5-9 سرونگ پھل/سبزیاں کھائیں
645
- • ریفائنڈ کاربوہائیڈریٹس پر سارا اناج ترجیح دیں
646
- • لیان پروٹین ذرائع (پولٹری، مچھلی، پھلیاں) شامل کریں
647
- • ہائیڈریشن برقرار رکھیں (روزانہ 2-3 لیٹر)
648
- • پراسیسڈ فوڈز اور اضافی چینی کو کم سے کم کریں
649
-
650
- **حالت کی مخصوص غذائی ترامیم:**
651
- • **قلبی صحت**: بحیرہ روم کی غذا، اومیگا 3 فیٹی ایسڈ
652
- • **ذیابیطس**: کنٹرول کاربوہائیڈریٹ انٹیک، زیادہ فائبر
653
- • **ہائی بلڈ پریشر**: ڈیش ڈائٹ (<2300mg سوڈیم/دن)، پوٹاشیم سے بھرپور غذائیں
654
-
655
- **پاکستان کے لیے ثقافتی غذائی موافقت:**
656
- • ریفائنڈ آٹے پر whole wheat چپاتی کو ترجیح دیں
657
- • دالوں اور پھلیوں کو باقاعدہ شامل کریں
658
- • صحت مند ککنگ آئلز (کینولا، زیتون، سرسوں) استعمال کریں
659
- • گھی اور سیر شدہ چکنائی کے استعمال کو محدود کریں
660
-
661
- *غذائی نوٹ: متوازن غذائیت احتیاطی ہیلتھ کیئر اور دائمی بیماری کے انتظام کی بنیاد بنتی ہے۔*
662
- """
663
-
664
- def _format_exercise_response(self, language):
665
- if language == 'English':
666
- return """
667
- **Dr. SehatAI - Exercise Physiology Specialist:**
668
- Regarding physical activity, here's my exercise prescription:
669
-
670
- **General Exercise Guidelines:**
671
- • 150 minutes moderate-intensity aerobic exercise weekly
672
- • Strength training 2-3 times weekly
673
- • Daily physical activity integration
674
- • Flexibility and balance exercises
675
- • Adequate recovery between sessions
676
-
677
- **Disease-Specific Exercise Prescriptions:**
678
- • **Cardiac Patients**: 30 minutes moderate cardio daily, supervised if high-risk
679
- • **Diabetic Patients**: Combination of aerobic and resistance training
680
- • **Hypertensive Patients**: Regular aerobic activity, avoid isometric exercises
681
-
682
- **Climate Considerations for Pakistan:**
683
- • Exercise during cooler morning/evening hours
684
- • Maintain hydration with electrolyte balance
685
- • Wear lightweight, breathable clothing
686
- • Monitor for heat-related illness symptoms
687
-
688
- *Exercise Physiology Note: Regular physical activity is potent medicine for chronic disease prevention and management.*
689
- """
690
- else:
691
- return """
692
- **ڈاکٹر سیحت اے آئی - ورزش فزیالوجی اسپیشلسٹ:**
693
- جسمانی سرگرمی کے بارے میں، یہ میری ورزش کی نسخہ ہے:
694
-
695
- **عام ورزش کے رہنما اصول:**
696
- • ہفتے میں 150 منٹ اعتدال پسند شدت کی ایروبک ورزش
697
- • ہفتے میں 2-3 بار طاقت کی تربیت
698
- • روزانہ جسمانی سرگرمی کا انضمام
699
- • لچک اور توازن کی ورزشیں
700
- • سیشن کے درمیان مناسب بحالی
701
-
702
- **بیماری کی مخصوص ورزش کے نسخے:**
703
- • **قلبی مریض**: روزانہ 30 منٹ اعتدال پسند کارڈیو، اگر اعلی خطرہ ہو تو نگرانی میں
704
- • **ذیابیطس کے مریض**: ایروبک اور مزاحمتی تربیت کا مجموعہ
705
- • **ہائی بلڈ پریشر کے مریض**: باقاعدہ ایروبک سرگرمی، آئسومیٹرک ورزشوں سے پرہیز
706
-
707
- **پاکستان کے لیے آب و ہیا کے تحفظات:**
708
- • ٹھنڈے صبح/شام کے اوقات میں ورزش کریں
709
- • الیکٹرولائٹ توازن کے ساتھ ہائیڈریشن برقرار رکھیں
710
- • ہلکے وزن، ہوا دار کپڑے پہنیں
711
- • گرمی سے متعلق بیماری کی علامات کی نگرانی کریں
712
-
713
- *ورزش فزیالوجی نوٹ: باقاعدہ جسمانی سرگرمی دائمی بیماری کی روک تھام اور انتظام کے لیے طاقتور دوا ہے۔*
714
- """
715
-
716
- def _format_symptoms_response(self, language):
717
- if language == 'English':
718
- return """
719
- **Dr. SehatAI - Clinical Assessment Specialist:**
720
- Regarding symptom evaluation, here's my clinical guidance:
721
-
722
- **When to Seek Medical Evaluation:**
723
- • Persistent fever >103°F (39.4°C) unresponsive to antipyretics
724
- • Respiratory distress or chest pain
725
- • Severe abdominal pain or trauma
726
- • Acute neurological changes (weakness, confusion, vision changes)
727
- • Unexplained weight loss >10% body weight in 6 months
728
- • Symptoms persisting beyond 2 weeks without improvement
729
-
730
- **🚨 Emergency Department Indicators:**
731
- • Acute respiratory distress or stridor
732
- • Chest pain with radiation, diaphoresis, or nausea
733
- • Uncontrolled hemorrhage
734
- • Sudden severe pain anywhere
735
- • Altered mental status or syncope
736
- • Seizure activity
737
-
738
- **Clinical Assessment Protocol:**
739
- • Comprehensive history taking
740
- • Vital signs assessment
741
- • Systematic physical examination
742
- • Appropriate diagnostic testing
743
- • Specialist referral when indicated
744
-
745
- *Medical Note: Symptom assessment requires professional medical evaluation for accurate diagnosis and treatment.*
746
- """
747
- else:
748
- return """
749
- **ڈاکٹر سیحت اے آئی - کلینیکل تشخیص اسپیشلسٹ:**
750
- علامات کی تشخیص کے بارے میں، یہ میری کلینیکل رہنمائی ہے:
751
-
752
- **طبی تشخیص کب حاصل کریں:**
753
- • اینٹیپائریٹکس کے لیے غیر receptive مستقل بخار >103°F (39.4°C)
754
- • سانس کی تکلیف یا سینے میں درد
755
- • شدید پیٹ کا درد یا چوٹ
756
- • شدید اعصابی تبدیلیاں (کمزوری، الجھن، بینائی میں تبدیلی)
757
- • 6 ماہ میں جسمانی وزن کا >10% بے وجہ وزن میں کمی
758
- • بہتری کے بغیر 2 ہفتے سے زیادہ علامات برقرار رہنا
759
-
760
- **🚨 ایمرجنسی ڈیپارٹمنٹ کے اشارے:**
761
- • شدید سانس کی تکلیف یا سٹرائیڈر
762
- • تابکاری، پسینہ آنا، یا متلی کے ساتھ سینے میں درد
763
- • غیر کنٹرول خون بہنا
764
- • کہیں بھی اچانک شدید درد
765
- • تبدیل ذہنی حیثیت یا سنکوپ
766
- • دورے کی سرگرمی
767
-
768
- **کلینیکل تشخیص پروٹوکول:**
769
- • جامع تاریخ لینا
770
- • اہم علامات کی تشخیص
771
- • نظامی جسمانی معائنہ
772
- • مناسب تشخیصی ٹیسٹنگ
773
- • اشارہ کردہ ہو تو ماہر کی رجوع
774
-
775
- *طبی نوٹ: علامات کی تشخیص کے لیے درست تشخیص اور علاج کے لیے پیشہ ورانہ طبی تشخیص کی ضرورت ہوتی ہے۔*
776
- """
777
-
778
- def _format_medication_response(self, language):
779
- if language == 'English':
780
- return """
781
- **Dr. SehatAI - Clinical Pharmacology Specialist:**
782
- Regarding medication management, here's my pharmacological guidance:
783
-
784
- **Medication Safety Protocol:**
785
- • Adhere strictly to prescribed dosing schedules
786
- • Never share prescription medications
787
- • Maintain current medication list including OTC products
788
- • Disclose all medications to all healthcare providers
789
- • Understand therapeutic goals and potential adverse effects
790
-
791
- **🚨 Medication Adverse Reaction Indicators:**
792
- • Anaphylaxis (urticaria, angioedema, respiratory distress)
793
- • Bronchospasm or wheezing post-medication
794
- • Severe gastrointestinal symptoms
795
- • Unexplained bleeding or bruising
796
- • Neurological changes (confusion, hallucinations)
797
-
798
- **Medication Management Principles:**
799
- • Regular medication reconciliation
800
- • Adherence assessment at each visit
801
- • Monitoring for drug interactions
802
- • Appropriate storage and disposal
803
- • Understanding administration techniques
804
-
805
- *Pharmacology Note: Medication management requires ongoing professional supervision for optimal therapeutic outcomes.*
806
- """
807
- else:
808
- return """
809
- **ڈاکٹر سیحت اے آئی - کلینیکل فارماکالوجی اسپیشلسٹ:**
810
- دوائیوں کے انتظام کے بارے میں، یہ میری فارماکولوجیکل رہنمائی ہے:
811
-
812
- **دوائیوں کی حفاظت کا پروٹوکول:**
813
- • تجویز کردہ خوراک کے شیڈول پر سختی سے عمل کریں
814
- • کبھی بھی نسخہ کی دوائیں شیئر نہ کریں
815
- • OTC مصنوعات سمیت موجودہ دوائیوں کی فہرست برقرار رکھیں
816
- • تمام ہیلتھ کیئر فراہم کرنے والوں کو تمام دوائیں بتائیں
817
- • علاج کے مقاصد اور ممکنہ مضر اثرات کو سمجھیں
818
-
819
- **🚨 دوائیوں کے مضر رد عمل کے اشارے:**
820
- • انافیلیکسس (urticaria، angioedema، سانس کی تکلیف)
821
- • دوائی کے بعد برونکوسپازم یا wheezing
822
- • شدید gastrointestinal علامات
823
- • بے وجہ خون بہنا یا چوٹ لگنا
824
- • اعصابی تبدیلیاں (الجھن، توہمات)
825
-
826
- **دوائیوں کے انتظام کے اصول:**
827
- • باقاعدہ دوائیوں کی مطابقت پذیری
828
- • ہر وزٹ پر پابندی کی تشخیص
829
- • دوائیوں کے تعاملات کی نگرانی
830
- • مناسب اسٹوریج اور ضائع
831
- • انتظامیہ کی تکنیکوں کو سمجھنا
832
-
833
- *فارماکالوجی نوٹ: دوائیوں کے انتظام کے لیے بہترین علاج کے نتائج کے لیے مسلسل پیشہ ورانہ نگرانی کی ضرورت ہوتی ہے۔*
834
- """
835
 
836
- def _format_emergency_response(self, language):
837
  if language == 'English':
838
- return """
839
- **Dr. SehatAI - Emergency Medicine Protocol:**
840
-
841
- **🚨 IMMEDIATE MEDICAL ATTENTION REQUIRED**
842
-
843
- **Emergency Response Protocol:**
844
- Activate emergency medical services (1122 in Pakistan)
845
- • Do not attempt self-transport to hospital
846
- • Maintain patient in position of comfort
847
- • Prepare relevant medical information
848
- • Withhold oral intake
849
-
850
- **Emergency Department Presentation Indicators:**
851
- • Acute chest pain or pressure
852
- • Respiratory distress or hypoxia
853
- • Uncontrolled hemorrhage
854
- • Acute neurological deficit
855
- • Major trauma or burns
856
- • Suspected poisoning or overdose
857
- • Seizure activity
858
-
859
- **Pre-Hospital Management:**
860
- • Ensure scene safety
861
- • Basic life support if trained
862
- • Continuous monitoring of vital signs
863
- • Preparation for EMS arrival
864
- • Documentation of event timeline
865
-
866
- **⚠️ CRITICAL: This constitutes emergency medical guidance only. Seek immediate professional medical evaluation.**
867
- """
868
  else:
869
- return """
870
- **ڈاکٹر سیحت اے ��ئی - ایمرجنسی میڈیسن پروٹوکول:**
871
-
872
- **🚨 فوری طبی توجہ درکار**
873
-
874
- **ہنگامی ردعمل پروٹوکول:**
875
- ہنگامی طبی خدمات کو چالو کریں (پاکستان میں 1122)
876
- • ہسپتال خود نقل و حمل کی کوشش نہ کریں
877
- • مریض کو آرام کی پوزیشن میں رکھیں
878
- • متعلقہ طبی معلومات تیار کریں
879
- • زبانی انٹیک کو روکیں
880
-
881
- **ایمرجنسی ڈیپارٹمنٹ پیشکش کے اشارے:**
882
- • شدید سینے میں درد یا دباؤ
883
- • سانس کی تکلیف یا hypoxia
884
- • غیر کنٹرول خون بہنا
885
- • شدید اعصابی خسارہ
886
- • بڑی چوٹ یا جلنے
887
- • مشتبہ زہر یا اوور ڈوز
888
- • دورے کی سرگرمی
889
-
890
- **ہسپتال سے پہلے کے انتظام:**
891
- • منظر کی حفاظت کو یقینی بنائیں
892
- • اگر تربیت یافتہ ہوں تو بنیادی زندگی کی حمایت
893
- • اہم علامات کی مسلسل نگرانی
894
- • EMS کی آمد کی تیاری
895
- • واقعہ کی ٹائم لائن کی دستاویزات
896
-
897
- **⚠️ اہم: یہ صرف ہنگامی طبی رہنمائی پر مشتمل ہے۔ فوری پیشہ ورانہ طبی تشخیص حاصل کریں۔*
898
- """
899
 
900
- def _format_general_health_response(self, language):
901
  if language == 'English':
902
- return """
903
- **Dr. SehatAI - Preventive Medicine Specialist:**
904
- Regarding general health and wellness, here's my comprehensive preventive guidance:
905
-
906
- **Lifestyle Medicine Recommendations:**
907
- • Sleep hygiene: 7-9 hours quality sleep nightly
908
- Stress management: Mindfulness, meditation, coping strategies
909
- • Tobacco cessation: Complete avoidance
910
- Alcohol moderation: ≤1 drink/day women, ≤2 drinks/day men
911
- • Regular preventive health screenings
912
-
913
- **Preventive Healthcare Protocol:**
914
- • Annual comprehensive physical examination
915
- • Age-appropriate vaccination schedule
916
- • Hand hygiene and infection control
917
- • Sun protection and skin surveillance
918
- • Mental health screening and support
919
-
920
- **Public Health Considerations for Pakistan:**
921
- • Access to clean drinking water
922
- • Consumption of fresh, seasonal produce
923
- • Food safety and hygiene practices
924
- • Adequate vitamin D synthesis through sensible sun exposure
925
-
926
- *Preventive Medicine Insight: Sustainable health improvements result from consistent lifestyle modifications and regular preventive care.*
927
- """
928
  else:
929
- return """
930
- **ڈاکٹر سیحت اے آئی - احتیاطی میڈیسن اسپیشلسٹ:**
931
- عام صحت اور تندرستی کے بارے میں، یہ میری جامع احتیاطی رہنمائی ہے:
932
-
933
- **طرز زندگی کی میڈیسن سفارشات:**
934
- • نیند کی حفظان صحت: رات میں 7-9 گھنٹے معیاری نیند
935
- تناؤ کا انتظام: مائنڈفلنیس، مراقبہ، نمٹنے کی حکمت عملی
936
- • تمباکو نوشی بند کرنا: مکمل پرہیز
937
- شراب اعتدال: ≤1 ڈرنک/دن خواتین، ≤2 ڈرنکس/دن مرد
938
- • باقاعدہ احتیاطی صحت کی اسکریننگ
939
-
940
- **احتیاطی ہیلتھ کیئر پروٹوکول:**
941
- • سالانہ جامع جسمانی معائنہ
942
- • عمر کے مناسب ویکسینیشن شیڈول
943
- • ہاتھ کی حفظان صحت اور انفیکشن کنٹرول
944
- • سورج سے تحفظ اور جلد کی نگرانی
945
- • ذہنی صحت کی اسکریننگ اور حمایت
946
-
947
- **پاکستان کے لیے عوامی صحت کے تحفظات:**
948
- • صاف پینے کے پانی تک رسائی
949
- • تازہ، موسمی پیداوار کی کھپت
950
- • غذائی تحفظ اور حفظان صحت کے طریقے
951
- • سمجھدار سورج کی نمائش کے ذریعے مناسب وٹامن ڈی ترکیب
952
-
953
- *احتیاطی میڈیسن بصیرت: پائیدار صحت کی بہتری مسلسل طرز زندگی میں ترمیم اور باقاعدہ احتیاطی دیکھ بھال کا نتیجہ ہے۔*
954
- """
955
 
956
  class PDFReportGenerator:
957
  def __init__(self):
@@ -1583,19 +1137,26 @@ def main():
1583
  st.markdown('<h2 style="color: #00401A; border-bottom: 3px solid #00401A; padding-bottom: 10px;">💬 سیحت اے آئی ہیلتھ اسسٹنٹ</h2>', unsafe_allow_html=True)
1584
  st.write("صحت سے متعلق سوالات پوچھیں اور فوری، قابل اعتماد طبی معلومات حاصل کریں")
1585
 
1586
- # Groq API Configuration - Hidden from interface as requested
1587
- # Check if API key is available in environment or secrets
1588
  groq_api_key = st.secrets.get("GROQ_API_KEY", "") if hasattr(st, 'secrets') else ""
1589
 
 
1590
  if groq_api_key:
1591
  st.session_state.groq_api_key = groq_api_key
1592
  try:
1593
  groq_client = GroqClient(groq_api_key)
1594
  chatbot = HealthcareChatbot(groq_client)
 
 
 
1595
  except Exception as e:
1596
  chatbot = HealthcareChatbot()
 
 
1597
  else:
1598
  chatbot = HealthcareChatbot()
 
 
1599
 
1600
  # Display chat history
1601
  for message in st.session_state.chat_history:
@@ -1634,46 +1195,46 @@ def main():
1634
  with col_qa1:
1635
  if st.button("❤️ Heart Health", use_container_width=True):
1636
  if language == "English":
1637
- query = "What are the symptoms of heart disease and how can I prevent it?"
1638
  else:
1639
- query = "دل کی بیماری کی علامات کیا ہیں اور میں اسے کیسے روک سکتا ہوں؟"
1640
  st.session_state.chat_history.append({"role": "user", "content": query})
1641
  st.rerun()
1642
 
1643
  with col_qa2:
1644
  if st.button("🩺 Diabetes", use_container_width=True):
1645
  if language == "English":
1646
- query = "How can I manage diabetes and what are the warning signs?"
1647
  else:
1648
- query = "میں ذیابیطس کا انتظام کیسے کر سکتا ہوں اور انتباہی علامات کیا ہیں؟"
1649
  st.session_state.chat_history.append({"role": "user", "content": query})
1650
  st.rerun()
1651
 
1652
  with col_qa3:
1653
  if st.button("💓 Blood Pressure", use_container_width=True):
1654
  if language == "English":
1655
- query = "What are natural ways to control high blood pressure?"
1656
  else:
1657
- query = "ہائی بلڈ پریشر کو کنٹرول کرنے کے قدرتی طریقے کیا ہیں؟"
1658
  st.session_state.chat_history.append({"role": "user", "content": query})
1659
  st.rerun()
1660
 
1661
  with col_qa4:
1662
  if st.button("🍎 Nutrition", use_container_width=True):
1663
  if language == "English":
1664
- query = "What is the best diet for maintaining heart health?"
1665
  else:
1666
- query = "دل کی صحت برقرار رکھنے کے لیے بہترین غذا کیا ہے؟"
1667
  st.session_state.chat_history.append({"role": "user", "content": query})
1668
  st.rerun()
1669
 
1670
  # Test Medical Queries Section
1671
  if language == "English":
1672
  st.subheader("Test Medical Queries")
1673
- st.write("Quickly test the chatbot with these sample medical questions:")
1674
  else:
1675
  st.subheader("طبی سوالات کی جانچ")
1676
- st.write("ان نمونہ طبی سوالات کے ساتھ چیٹ بوٹ کو فوری طور پر آزمائیں:")
1677
 
1678
  test_col1, test_col2 = st.columns(2)
1679
 
@@ -1689,9 +1250,9 @@ def main():
1689
  with test_col2:
1690
  if st.button("Test Diabetes Query", use_container_width=True):
1691
  if language == "English":
1692
- test_query = "What are the early symptoms of diabetes?"
1693
  else:
1694
- test_query = "ذیابیطس کی ابتدائی علامات کیا ہیں؟"
1695
  st.session_state.chat_history.append({"role": "user", "content": test_query})
1696
  st.rerun()
1697
 
 
191
  st.session_state.groq_api_key = ''
192
  if 'models_loaded' not in st.session_state:
193
  st.session_state.models_loaded = False
194
+ if 'api_available' not in st.session_state:
195
+ st.session_state.api_available = False
196
 
197
  # Healthcare quotes database
198
  HEALTHCARE_QUOTES = [
 
232
  "Content-Type": "application/json"
233
  }
234
 
235
+ def chat_completions_create(self, messages, model="llama3-8b-8192", temperature=0.7, max_tokens=1024):
236
  try:
237
  url = f"{self.base_url}/chat/completions"
238
  data = {
 
255
  class HealthcareChatbot:
256
  def __init__(self, groq_client=None):
257
  self.groq_client = groq_client
258
+ self.api_available = groq_client is not None and groq_client.api_key
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
259
 
260
  def get_response(self, user_input, language='English'):
261
+ # Always try API first if available
262
+ if self.api_available:
263
  try:
264
  return self._get_groq_response(user_input, language)
265
  except Exception as e:
266
+ st.error(f"⚠️ API temporarily unavailable. Using enhanced response system.")
267
+ return self._get_enhanced_response(user_input, language)
268
 
269
+ # If no API, use enhanced responses
270
+ return self._get_enhanced_response(user_input, language)
271
 
272
  def _get_groq_response(self, user_input, language):
273
  system_prompt = """You are Dr. SehatAI, a professional medical AI assistant for Pakistani patients.
274
+ Provide accurate, compassionate medical guidance in a natural, conversational tone.
275
+
276
  CRITICAL GUIDELINES:
277
+ 1. NEVER use structured lists with bullet points or markdown formatting
278
+ 2. ALWAYS respond in natural, flowing paragraphs like a real doctor
279
+ 3. Be specific and directly address the patient's concern
280
+ 4. Provide practical, actionable medical advice
281
+ 5. Include when to seek emergency care when relevant
282
+ 6. Be empathetic but professional
283
+ 7. Use plain text without any special formatting
284
+ 8. Keep responses concise but comprehensive
285
+ 9. For Pakistani context, consider local healthcare accessibility
286
+
287
+ Format your response as a doctor would speak to a patient in a consultation."""
288
 
289
  if language == 'Urdu':
290
+ system_prompt += " Respond in Urdu with natural, flowing text. Use professional medical terminology but make it accessible. Avoid any structured lists or bullet points."
291
  else:
292
+ system_prompt += " Respond in English with natural, flowing text. Use professional medical terminology but make it accessible. Avoid any structured lists or bullet points."
293
 
294
  messages = [
295
  {"role": "system", "content": system_prompt},
 
299
  response = self.groq_client.chat_completions_create(
300
  messages=messages,
301
  model="llama3-8b-8192",
302
+ temperature=0.7,
303
  max_tokens=1024
304
  )
305
 
306
  bot_response = response['choices'][0]['message']['content']
307
 
308
+ # Add disclaimer in natural language
309
  if language == 'Urdu':
310
+ bot_response += "\n\nیہ ایک AI اسسٹنٹ کی طرف سے فراہم کردہ عمومی طبی معلومات ہیں۔ سنگین طبی حالات کے لیے ہمیشہ کوالیفائیڈ ڈاکٹر سے مشورہ کریں۔"
311
  else:
312
+ bot_response += "\n\nThis is general medical information provided by an AI assistant. Always consult qualified doctors for serious medical conditions."
313
 
314
  return bot_response
315
 
316
+ def _get_enhanced_response(self, user_input, language):
317
+ """Enhanced natural language responses without structured formatting"""
318
  user_input_lower = user_input.lower().strip()
319
 
320
+ # For greetings
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
321
  if any(word in user_input_lower for word in ['hello', 'hi', 'hey', 'salam', 'السلام علیکم']):
322
+ return self._format_natural_greeting(language)
323
 
324
+ # Medical topics with natural responses
325
+ if any(word in user_input_lower for word in ['heart', 'cardiac', 'chest pain', 'cholesterol', 'دل', 'سینے میں درد']):
326
+ return self._format_natural_heart_response(language)
 
327
 
328
+ elif any(word in user_input_lower for word in ['diabetes', 'sugar', 'glucose', 'insulin', 'ذیابیطس', 'شوگر']):
329
+ return self._format_natural_diabetes_response(language)
330
+
331
+ elif any(word in user_input_lower for word in ['blood pressure', 'hypertension', 'bp', 'بلڈ پریشر', 'ہائی بلڈ پریشر']):
332
+ return self._format_natural_hypertension_response(language)
333
+
334
+ elif any(word in user_input_lower for word in ['diet', 'nutrition', 'food', 'eating', 'غذا', 'کھانا']):
335
+ return self._format_natural_nutrition_response(language)
336
+
337
+ elif any(word in user_input_lower for word in ['emergency', 'urgent', 'help', 'ہنگامی', 'فوری']):
338
+ return self._format_natural_emergency_response(language)
339
+
340
+ elif any(word in user_input_lower for word in ['symptom', 'pain', 'fever', 'headache', 'علامت', 'درد']):
341
+ return self._format_natural_symptoms_response(language)
342
+
343
+ # Default professional response
344
+ return self._format_natural_default_response(user_input, language)
345
 
346
+ def _format_natural_greeting(self, language):
 
347
  if language == 'English':
348
+ return """Thank you for reaching out to SehatAI. I'm here to provide you with professional medical guidance and support.
 
 
 
349
 
350
+ I understand you might have health concerns or questions. Please feel free to share your specific health issue, whether it's about symptoms you're experiencing, medication questions, preventive care, or any other medical concern.
351
 
352
+ I can help with cardiovascular health, diabetes management, blood pressure control, and general wellness advice. What would you like to discuss today?
353
 
354
+ Please note: I'm an AI assistant providing general medical information. For serious conditions, always consult a healthcare professional."""
 
355
  else:
356
+ return """سیحت اے آئی سے رابطہ کرنے کا شکریہ۔ میں آپ کو پیشہ ورانہ طبی رہنمائی اور مدد فراہم کرنے کے لیے یہاں ہوں۔
 
 
 
357
 
358
+ میں سمجھتا ہوں کہ آپ کے صحت کے بارے میں خدشات یا سوالات ہو سکتے ہیں۔ براہ کرم اپنا مخصوص صحت کا مسئلہ شیئر کریں، چاہے وہ علامات ہوں جو آپ محسوس کر رہے ہیں، دوائیوں کے سوالات، احتیاطی دیکھ بھال، یا کوئی اور طبی تشویش ہو۔
359
 
360
+ میں قلبی صحت، ذیابیطس کا انتظام، بلڈ پریشر کنٹرول، اور عام صحت کے مشوروں میں مدد کر سکتا ہوں۔ آج آپ کیا زیر بحث لانا چاہیں گے؟
361
 
362
+ براہ کرم نوٹ کریں: میں ایک AI اسسٹنٹ ہوں جو عمومی طبی معلومات فراہم کرتا ہوں۔ سنگین حالات کے لیے، ہمیشہ ہیلتھ کیئر پروفیشنل سے مشورہ کریں۔"""
 
363
 
364
+ def _format_natural_heart_response(self, language):
 
365
  if language == 'English':
366
+ return """When it comes to heart health, it's important to be proactive about monitoring your cardiovascular system. Common symptoms that warrant attention include chest discomfort or pain, shortness of breath especially during physical activity, pain that radiates to your arms, neck, or jaw, unexplained nausea, persistent fatigue, and feelings of dizziness.
367
+
368
+ Several factors can increase your risk of heart issues, including elevated blood pressure, high cholesterol levels, tobacco use, diabetes, excess weight, family history of heart disease, and sedentary lifestyle habits.
369
+
370
+ For prevention, I recommend focusing on a heart-healthy diet that's low in saturated fats, engaging in regular physical activity for about 30 minutes daily, completely avoiding tobacco products, maintaining a healthy weight through balanced nutrition, developing effective stress management techniques, and scheduling regular health check-ups.
371
+
372
+ It's crucial to recognize emergency warning signs such as severe crushing chest pain, significant difficulty breathing, fainting episodes, rapid or irregular heartbeat, and pain that spreads to your shoulders or arms. If you experience any of these symptoms, seek immediate medical attention.
373
+
374
+ For ongoing monitoring, I suggest regular blood pressure checks, comprehensive lipid profiles every 6 to 12 months, electrocardiograms when symptoms are present, and stress testing as recommended by your healthcare provider based on your individual risk factors."""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
375
  else:
376
+ return """دل کی صحت کے معاملے میں، اپنے قلبی نظام کی نگرانی کے بارے میں پیشگی اقدامات کرنا بہت ضروری ہے۔ عام علامات جن پر توجہ دینے کی ضرورت ہوتی ہے ان میں سینے میں بے چینی یا درد، خاص طور پر جسمانی سرگرمی کے دوران سانس لینے میں دشواری، آپ کے بازوؤں، گردن یا جبڑے میں پھیلنے والا درد، بے وجہ متلی، مسلسل تھکاوٹ، اور چکر آنے کے احساسات شامل ہیں۔
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
377
 
378
+ کئی عوامل دل کے مسائل کے خطرے کو بڑھا سکتے ہیں، جن میں بلند بلڈ پریشر، ہائی کولیسٹرول کی سطح، تمباکو کا استعمال، ذیابیطس، زیادہ وزن، دل کی بیماری کی خاندانی تاریخ، اور بیٹھے رہنے کی عادات شامل ہیں۔
 
379
 
380
+ روک تھام کے لیے، میں سیر شدہ چکنائیوں سے پاک دل کے لیے صحت مند غذا پر توجہ مرکوز کرنے، روزانہ تقریباً 30 منٹ تک باقاعدہ جسمانی سرگرمی میں مشغول رہنے، تمباکو کی مصنوعات سے مکمل پرہیز کرنے، متوازن غذائیت کے ذریعے صحت مند وزن برقرار رکھنے، مؤثر تناؤ انتظام کی تکنیکیں تیار کرنے، اور باقاعدہ صحت کی جانچ پڑتال کی سفارش کرتا ہوں۔
 
381
 
382
+ ہنگامی انتباہی علامات کو پہچاننا بہت ضروری ہے جیسے کہ شدید کچلنے والا سینے کا درد، سانس لینے میں نمایاں دشواری، بیہوشی کے دورے، تیز یا بے ترتیب دل کی دھڑکن، اور درد جو آپ کے کندھوں یا بازوؤں میں پھیل جاتا ہو۔ اگر آپ ان میں سے کوئی بھی علامت محسوس کرتے ہیں، تو فوری طبی امداد حاصل کریں۔
 
383
 
384
+ جاری نگرانی کے لیے، میں باقاعدہ بلڈ پریشر چیک، ہر 6 سے 12 ماہ میں جامع لپڈ پروفائل، علامات موجود ہونے پر الیکٹروکارڈیوگرام، اور آپ کے ہیلتھ کیئر فراہم کنندہ کی طرف سے آپ کے انفرادی خطرے کے عوامل کی بنیاد پر سفارش کردہ اسٹریس ٹیسٹنگ کی تجویز کرتا ہوں۔"""
385
+
386
+ def _format_natural_diabetes_response(self, language):
387
+ if language == 'English':
388
+ return """Diabetes management requires careful attention to both lifestyle factors and medical monitoring. Common symptoms that might indicate diabetes include increased thirst and hunger, frequent urination especially at night, persistent fatigue that doesn't improve with rest, blurred vision that comes and goes, slow healing of cuts and wounds, and unexplained weight loss despite normal eating habits.
389
 
390
+ Key risk factors to be aware of include family history of diabetes, being overweight particularly with a BMI over 25, existing high blood pressure, physical inactivity, age over 45 years, and history of gestational diabetes during pregnancy.
 
 
 
 
391
 
392
+ For effective diabetes management, I recommend adopting a balanced diet with controlled carbohydrate intake, engaging in regular physical activity that combines both aerobic and resistance training, maintaining a healthy weight through proper nutrition, regular blood sugar monitoring to track patterns, and comprehensive health screenings including eye and foot examinations.
393
+
394
+ It's essential to recognize diabetic emergencies such as blood sugar levels above 300 mg/dL or below 70 mg/dL, confusion or disorientation, fruity-smelling breath indicating ketoacidosis, rapid deep breathing, and loss of consciousness. These situations require immediate medical attention.
 
 
 
395
 
396
+ For optimal diabetes control, aim for fasting glucose levels between 80-130 mg/dL, post-meal readings below 180 mg/dL, and individualized HbA1c targets typically below 7%. Regular ophthalmologic exams and annual foot assessments are crucial for preventing complications."""
397
+ else:
398
+ return """ذیابیطس کے انتظام کے لیے طرز زندگی کے عوامل اور طبی نگرانی دونوں پر احتیاط سے توجہ دینے کی ضرورت ہوتی ہے۔ عام علامات جو ذیابیطس کی نشاندہی کر سکتی ہیں ان میں پیاس اور بھوک میں اضافہ، خاص طور پر رات کے وقت بار بار پیشاب آنا، مسلسل تھکاوٹ جو آرام سے بہتر نہ ہو، آتی جاتی دھندلی نظر، کٹوں اور زخموں کا دیر سے بھرنا، اور عام کھانے کی عادات کے باوجود بے وجہ وزن میں کمی شامل ہیں۔
399
 
400
+ ذیابیطس کے اہم خطرے کے عوامل جن سے آگاہ رہنا ضروری ہے ان میں ذیابیطس کی خاندانی تاریخ، زیادہ وزن خاص طور پر 25 سے زیادہ BMI والے، موجودہ ہائی بلڈ پریشر، جسمانی غیر فعالیت، 45 سال سے زیادہ عمر، اور حمل کے دوران gestational ذیابیطس کی تاریخ شامل ہیں۔
 
401
 
402
+ ذیابیطس کے مؤثر انتظام کے لیے، میں کنٹرول کاربوہائیڈریٹ انٹیک کے ساتھ متوازن غذا اپنانے، باقاعدہ جسمانی سرگرمی میں مشغول ہونے کی سفارش کرتا ہوں جو ایروبک اور مزاحمتی تربیت دونوں کو یکجا کرتی ہے، مناسب غذائیت کے ذریعے صحت مند وزن برقرار رکھتی ہے، پیٹرن کو ٹریک کرنے کے لیے باقاعدہ بلڈ شوگر مانیٹرنگ، اور آنکھوں اور پاؤں کی جانچ سمیت جامع صحت کی اسکریننگ۔
 
403
 
404
+ ذیابیطس کی ایمرجنسیز کو پہچاننا ضروری ہے جیسے کہ 300 mg/dL سے اوپر یا 70 mg/dL سے نیچے بلڈ شوگر کی سطح، الجھن یا بے ترتیبی، ketosis کی نشاندہی کرنے والی پھل کی سی بو والی سانس، تیز گہری سانس لینا، اور ہوش کا ضیاع۔ ان حالات میں فوری طبی توجہ کی ضرورت ہوتی ہے۔
 
405
 
406
+ ذیابیطس کے بہترین کنٹرول کے لیے، فاسٹنگ گلوکوز کی سطح 80-130 mg/dL، کھانے کے بعد کی ریڈنگ 180 mg/dL سے نیچے، اور انفرادی HbA1c کے ہدف کی کوشش کریں جو عام طور پر 7% سے کم ہوں۔ پیچیدگیوں کو روکنے کے لیے باقاعدہ ophthalmologic امتحانات اور سالانہ پاؤں کے جائزے بہت ضروری ہیں۔"""
 
407
 
408
+ def _format_natural_hypertension_response(self, language):
 
409
  if language == 'English':
410
+ return """High blood pressure often develops silently without obvious symptoms, which is why regular monitoring is crucial. When symptoms do occur, they might include persistent headaches particularly in the morning, episodes of dizziness or lightheadedness, blurred vision that comes and goes, shortness of breath during routine activities, chest discomfort or tightness, and occasional nosebleeds in some individuals.
 
 
411
 
412
+ Several factors can increase your risk of developing hypertension, including family history of high blood pressure, age over 65 years, excess body weight, high sodium intake in your diet, chronic stress, regular alcohol consumption, and tobacco use.
 
413
 
414
+ For effective blood pressure management, I recommend following the DASH diet which emphasizes low sodium intake, engaging in regular aerobic exercise like brisk walking or swimming, maintaining a healthy weight through balanced nutrition, practicing stress reduction techniques such as meditation or deep breathing, limiting alcohol consumption to moderate levels, and completely avoiding tobacco products.
 
415
 
416
+ It's vital to recognize hypertensive crisis symptoms including severe pounding headaches, chest pain or pressure, significant breathing difficulties, vision changes like blurriness or spots, confusion or difficulty thinking clearly, and seizure activity. These require immediate emergency medical care.
 
417
 
418
+ Understanding blood pressure classifications can help you monitor your health: normal is below 120/80 mmHg, elevated ranges from 120-129/<80 mmHg, stage 1 hypertension is 130-139/80-89 mmHg, stage 2 hypertension is 140/90 mmHg or higher, and hypertensive crisis occurs above 180/120 mmHg."""
419
+ else:
420
+ return """ہائی بلڈ پریشر اکثر واضح علامات کے بغیر خاموشی سے نشوونما پاتا ہے، یہی وجہ ہے کہ باقاعدہ نگرانی بہت ضروری ہے۔ جب علامات واقع ہوتی ہیں، تو ان میں مسلسل سر درد خاص طور پر صبح کے وقت، چکر آنے یا سر ہلکا ہونے کے واقعات، آتی جاتی دھندلی نظر، روزمرہ کی سرگرمیوں کے دوران سانس لینے میں دشواری، سینے میں بے چینی یا تنگی، اور کچھ افراد میں occasional نکسیر شامل ہو سکتی ہیں۔
421
 
422
+ کئی عوامل آپ کے ہائی بلڈ پریشر کے خطرے کو بڑھا سکتے ہیں، جن میں ہائی بلڈ پریشر کی خاندانی تاریخ، 65 سال سے زیادہ عمر، جسمانی وزن میں اضافہ، آپ کی غذا میں high سوڈیم انٹیک، دائمی تناؤ، باقاعدہ شراب کا استعمال، اور تمباکو کا استعمال شامل ہیں۔
 
 
 
 
 
423
 
424
+ بلڈ پریشر کے مؤثر انتظام کے لیے، میں ڈیش ڈائٹ کی پیروی کرنے کی سفارش کرتا ہوں جو low سوڈیم انٹیک پر زور دیتی ہے، تیز چہل قدمی یا تیراکی جیسی باقاعدہ ایروبک ورزش میں مشغول ہونا، متوازن غذائیت کے ذریعے صحت مند وزن برقرار رکھنا، مراقبہ یا گہری سانس لینے جیسی تناؤ میں کمی کی تکنیکوں پر عمل کرنا، اعتدال پسندی تک شراب کے استعمال کو محدود کرنا، اور تمباکو کی مصنوعات سے مکمل پرہیز کرنا۔
 
 
 
 
 
425
 
426
+ ہائی بلڈ پریشر کے بحران کی علامات کو پہچاننا بہت ضروری ہے جن میں شدید تھپتھپانے والا سر درد، سینے میں درد یا دباؤ، سانس لینے میں نمایاں دشواری، دھندلاپن یا داغوں جیسی بینائی میں تبدیلی، الجھن یا واضح طور پر سوچنے میں دشواری، اور دورے کی سرگرمی شامل ہیں۔ ان کے لیے فوری ہنگامی طبی دیکھ بھال کی ضرورت ہوتی ہے۔
 
427
 
428
+ بلڈ پریشر کی درجہ بندی کو سمجھنا آپ کو اپنی صحت کی نگرانی میں مدد کر سکتا ہے: نارمل 120/80 mmHg سے کم ہے، elevated 120-129/<80 mmHg کے درمیان ہوتی ہے، stage 1 ہائی بلڈ پریشر 130-139/80-89 mmHg ہے، stage 2 ہائی بلڈ پریشر 140/90 mmHg یا اس سے زیادہ ہے، اور ہائی بلڈ پریشر کا بحران 180/120 mmHg سے اوپر ہوتا ہے۔"""
429
+
430
+ def _format_natural_nutrition_response(self, language):
431
+ if language == 'English':
432
+ return """Good nutrition forms the foundation of overall health and disease prevention. For optimal health, focus on consuming 5 to 9 servings of fruits and vegetables daily, choosing whole grains over refined carbohydrates, including lean protein sources like poultry, fish, and legumes in your meals, maintaining proper hydration with 2-3 liters of water daily, and minimizing processed foods and added sugars in your diet.
433
 
434
+ For specific health conditions, dietary adjustments can be particularly beneficial. For heart health, the Mediterranean diet rich in omega-3 fatty acids has shown excellent results. For diabetes management, controlled carbohydrate intake combined with high fiber foods helps maintain stable blood sugar levels. For hypertension, the DASH diet with less than 2300mg of sodium daily along with potassium-rich foods can significantly improve blood pressure control.
 
435
 
436
+ Considering cultural dietary patterns in Pakistan, I recommend choosing whole wheat chapati instead of refined flour, regularly incorporating lentils and legumes into your meals, using healthier cooking oils like canola, olive, or mustard oil, and limiting the consumption of ghee and saturated fats. These simple adjustments can make a significant difference in your long-term health outcomes."""
437
+ else:
438
+ return """اچھی غذائیت مجموعی صحت اور بیماریوں کی روک تھام کی بنیاد بنتی ہے۔ بہترین صحت کے لیے، روزانہ 5 سے 9 سرونگ پھل اور سبزیاں کھانے، refined کاربوہائیڈریٹس پر سارا اناج منتخب کرنے، اپنے کھانوں میں پولٹری، مچھلی، اور پھلیاں جیسے lean پروٹین کے ذرائع شامل کرنے، روزانہ 2-3 لیٹر پانی کے ساتھ مناسب ہائیڈریشن برقرار رکھنے، اور اپنی غذا میں پراسیسڈ فوڈز اور اضافی شکر کو کم سے کم کرنے پر توجہ مرکوز کریں۔
439
+
440
+ مخصوص صحت کی حالتوں کے لیے، غذائی ایڈجسٹمنٹ خاص طور پر فائدہ مند ہو سکتی ہیں۔ دل کی صحت کے لیے، اومیگا 3 فیٹی ایسڈ سے بھرپور بحیرہ روم کی غذا نے شاندار نتائج دکھائے ہیں۔ ذیابیطس کے انتظام کے لیے، کنٹرول کاربوہائیڈریٹ انٹیک high فائبر والی غذاؤں کے ساتھ مل کر stable بلڈ شوگر کی سطح برقرار رکھنے میں مدد کرتا ہے۔ ہائی بلڈ پریشر کے لیے، روزانہ 2300mg سے کم سوڈیم کے ساتھ ڈیش ڈائٹ اور پوٹاشیم سے بھرپور غذائیں بلڈ پریشر کنٹرول کو نمایاں طور پر بہتر بنا سکتی ہیں۔
441
 
442
+ پاکستان میں ثقافتی غذائی نمونوں کو مدنظر رکھتے ہوئے، میں refined آٹے کے بجائے whole wheat چپاتی منتخب کرنے، اپنے کھانوں میں باقاعدگی سے دالوں اور پھلیوں کو شامل کرنے، کینولا، زیتون، یا سرسوں کے تیل جیسے صحت مند کھانا پکانے کے تیل استعمال کرنے، اور گھی اور سیر شدہ چربی کے استعمال کو محدود کرنے کی سفارش کرتا ہوں۔ یہ سادہ ایڈجسٹمنٹ آپ کی طویل مدتی صحت کے نتائج میں نمایاں فرق لا سکتی ہیں۔"""
 
443
 
444
+ def _format_natural_emergency_response(self, language):
 
445
  if language == 'English':
446
+ return """IMMEDIATE MEDICAL ATTENTION REQUIRED
 
 
447
 
448
+ If you or someone you're with is experiencing a medical emergency, please act quickly and decisively. First, activate emergency medical services immediately by calling 1122 in Pakistan. Do not attempt to transport the patient to the hospital yourself, as emergency personnel can begin life-saving treatments en route.
 
449
 
450
+ Keep the patient in a comfortable position, preferably lying down if possible. Gather any relevant medical information such as current medications, known allergies, and existing medical conditions. Withhold all oral intake including food and water until medical professionals can assess the situation.
 
451
 
452
+ Emergency situations that require immediate hospital attention include acute chest pain or pressure, respiratory distress or difficulty breathing, uncontrolled bleeding, acute neurological changes like weakness or confusion, major trauma or burns, suspected poisoning or overdose, and seizure activity.
 
453
 
454
+ While waiting for emergency services, ensure the scene is safe for both the patient and responders. If you're trained in basic life support, provide assistance as needed. Continuously monitor vital signs like breathing and pulse. Prepare to provide emergency personnel with a clear timeline of events when they arrive.
 
455
 
456
+ This guidance is for emergency situations only and should not replace professional medical evaluation. Please seek immediate medical attention for any serious health concerns."""
 
 
 
 
 
 
 
 
457
  else:
458
+ return """فوری طبی توجہ درکار
 
 
459
 
460
+ اگر آپ یا کوئی شخص جس کے ساتھ آپ ہیں طبی ایمرجنسی کا سامنا کر رہا ہے، تو براہ کرم فوری اور فیصلہ کن طور پر عمل کریں۔ سب سے پہلے، پاکستان میں 1122 پر فون کر کے فوری طور پر ہنگامی طبی خدمات کو چالو کریں۔ مریض کو خود ہسپتال لے جانے کی کوشش نہ کریں، کیونکہ ہنگامی عملہ راستے میں زندگی بچانے والے علاج شروع کر سکتا ہے۔
 
461
 
462
+ مریض کو آرام دہ پوزیشن میں رکھیں، ترجیحاً اگر ممکن ہو تو لیٹا ہوا۔ کوئی بھی متعلقہ طبی معلومات اکٹھی کریں جیسے کہ موجودہ دوائیں، معلوم الرجی، اور موجودہ طبی حالات۔ طبی پیشہ ورانہ حالات کا جائزہ لینے تک کھانے اور پانی سمیت تمام زبانی انٹیک کو روکیں۔
 
463
 
464
+ فوری ہسپتال کی توجہ کی ضرورت والی ہنگامی صورتحال میں شدید سینے میں درد یا دباؤ، سانس کی تکلیف یا سانس لینے میں دشواری، غیر کنٹرول خون بہنا، کمزوری یا الجھن جیسی شدید اعصابی تبدیلیاں، بڑی چوٹ یا جلنے، مشتبہ زہر یا اوور ڈوز، اور دورے کی سرگرمی شامل ہیں۔
 
465
 
466
+ ہنگامی خدمات کے انتظار کے دوران، یقینی بنائیں کہ منظر مریض اور رسپانڈرز دونوں کے لیے محفوظ ہے۔ اگر آپ بنیادی زندگی کی حمایت میں تربیت یافتہ ہیں، تو ضرورت کے مطابق مدد فراہم کریں۔ سانس اور نبض جیسی اہم علامات کی مسلسل نگرانی کریں۔ جب وہ آئیں گے تو ہنگامی عملہ کو واقعات کی واضح ٹائم لائن فراہم کرنے کے لیے تیار رہیں۔
 
467
 
468
+ یہ رہنمائی صرف ہنگامی حالات کے لیے ہے اور اسے پیشہ ورانہ طبی تشخیص کی جگہ نہیں لینی چاہیے۔ براہ کرم کسی بھی سنگین صحت کے خدشات کے لیے فوری طبی امداد حاصل کریں۔"""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
469
 
470
+ def _format_natural_symptoms_response(self, language):
471
  if language == 'English':
472
+ return """When evaluating symptoms, it's important to understand when professional medical assessment is necessary. You should seek medical evaluation for persistent fever above 103°F that doesn't respond to fever-reducing medications, any respiratory distress or chest pain, severe abdominal pain or significant trauma, acute neurological changes like sudden weakness, confusion, or vision changes, unexplained weight loss exceeding 10% of body weight within six months, or any symptoms that persist beyond two weeks without improvement.
473
+
474
+ Certain situations require immediate emergency department attention. These include acute respiratory distress with stridor sounds, chest pain that radiates to other areas accompanied by sweating or nausea, uncontrolled bleeding from any site, sudden severe pain anywhere in the body, altered mental status or fainting episodes, and any seizure activity.
475
+
476
+ A proper clinical assessment should include comprehensive history taking to understand the symptom pattern, thorough vital signs assessment including temperature and blood pressure, systematic physical examination of affected areas, appropriate diagnostic testing based on clinical findings, and specialist referral when the condition warrants more specialized care.
477
+
478
+ Remember that symptom assessment requires professional medical evaluation for accurate diagnosis and treatment planning. While I can provide general guidance, specific symptoms should always be evaluated by a healthcare professional who can perform hands-on assessment and order appropriate tests."""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
479
  else:
480
+ return """علامات کا جائزہ لیتے وقت، یہ سمجھنا ضروری ہے کہ پیشہ ورانہ طبی تشخیص کب ضروری ہے۔ آپ کو طبی تشخیص کے لیے رابطہ کرنا چاہیے اگر آپ کو 103°F سے اوپر مستقل بخار ہے جو بخار کم کرنے والی دوائیوں کا جواب نہیں دیتا، کوئی بھی سانس کی تکلیف یا سینے میں درد، شدید پیٹ میں درد یا نمایاں چوٹ، اچانک کمزوری، الجھن، یا بینائی میں تبدیلی جیسی شدید اعصابی تبدیلیاں، چھ ماہ کے اندر جسمانی وزن کے 10% سے زیادہ بے وجہ وزن میں کمی، یا کوئی بھی علامات جو دو ہفتوں سے زیادہ بغیر بہتری کے برقرار رہتی ہیں۔
481
+
482
+ کچھ حالات فوری ایمرجنسی ڈیپارٹمنٹ کی توجہ کی ضرورت ہوتی ہے۔ ان میں سٹرائیڈر آوازوں کے ساتھ شدید سانس کی تکلیف، سینے میں درد جو پسینہ آنا یا متلی کے ساتھ دوسرے علاقوں میں پھیلتا ہے، کسی بھی جگہ سے غیر کنٹرول خون بہنا، جسم میں کہیں بھی اچانک شدید درد، تبدیل ذہنی حیثیت یا بیہوشی کے واقعات، اور کوئی بھی دورے کی سرگرمی شامل ہیں۔
483
+
484
+ ایک مناسب کلینیکل تشخیص میں علامت کے پیٹرن کو سمجھنے کے لیے جامع تاریخ لینا، درجہ حرارت اور بلڈ پریشر سمیت اہم علامات کی مکمل تشخیص، متاثرہ علاقوں کا نظامی جسمانی معائنہ، کلینیکل نتائج کی بنیاد پر مناسب تشخیصی ٹیسٹنگ، اور ماہر کی رجوع کرنا شامل ہونا چاہیے جب حالت زیادہ خصوصی دیکھ بھال کی warrent کرتی ہے۔
485
+
486
+ یاد رکھیں کہ علامات کی تشخیص کے لیے درست تشخیص اور علاج کی منصوبہ بندی کے لیے پیشہ ورانہ طبی تشخیص کی ضرورت ہوتی ہے۔ اگرچہ میں عمومی رہنمائی فراہم کر سکتا ہوں، مخصوص علامات کی ہمیشہ ہیلتھ کیئر پروفیشنل کے ذریعے تشخیص کی جانی چاہیے جو hands-on تشخیص کر سکتا ہے اور مناسب ٹیسٹوں کا حکم دے سکتا ہے۔"""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
487
 
488
+ def _format_natural_default_response(self, user_input, language):
489
  if language == 'English':
490
+ return f"""I understand you're asking about: "{user_input}"
491
+
492
+ As your medical AI assistant, I'm here to provide professional healthcare guidance across various medical domains. I can help you with cardiovascular health assessments, diabetes management strategies, blood pressure monitoring, symptom evaluation, medication questions, and general wellness advice.
493
+
494
+ Could you please provide more specific details about your health concern? The more information you share about your symptoms, medical history, or specific questions, the better I can assist you with tailored medical guidance.
495
+
496
+ I specialize in providing evidence-based information about heart conditions, diabetes care, hypertension management, nutrition, exercise recommendations, and when to seek emergency care. Please feel free to ask me any specific health-related questions you might have.
497
+
498
+ Remember that while I can provide comprehensive medical information, serious health concerns should always be evaluated by qualified healthcare professionals who can provide personalized care based on direct examination."""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
499
  else:
500
+ return f"""میں سمجھتا ہوں کہ آپ پوچھ رہے ہیں: "{user_input}"
501
+
502
+ آپ کے میڈیکل AI اسسٹنٹ کے طور پر، میں مختلف طبی شعبوں میں پیشہ ورانہ ہیلتھ کیئر رہنمائی فراہم کرنے کے لیے یہاں ہوں۔ میں آپ کی قلبی صحت کی تشخیص، ذیابیطس مینجمنٹ کی حکمت عملی، بلڈ پریشر مانیٹرنگ، علامات کی تشخیص، دوائیوں کے سوالات، اور عام صحت کے مشوروں میں مدد کر سکتا ہوں۔
503
+
504
+ کیا آپ براہ کرم اپنے صحت کے مسئلے کے بارے میں مزید مخصوص تفصیلات فراہم کر سکتے ہیں؟ آپ اپنی علامات، طبی تاریخ، یا مخصوص سوالات کے بارے میں جتنی زیادہ معلومات شیئر کریں گے، میں آپ کی حسب ضرورت طبی رہنمائی کے ساتھ اتنی ہی بہتر مدد کر سکتا ہوں۔
505
+
506
+ میں دل کی حالتوں، ذیابیطس کی دیکھ بھال، ہائی بلڈ پریشر مینجمنٹ، غذائیت، ورزش کی سفارشات، اور ہنگامی دیکھ بھال کے وقت کے بارے میں evidence-based معلومات فراہم کرنے میں مہارت رکھتا ہوں۔ براہ کرم مجھ سے اپنے کسی بھی مخصوص صحت سے متعلق سوالات پوچھنے میں آزاد محسوس کریں۔
507
+
508
+ یاد رکھیں کہ اگرچہ میں جامع طبی معلومات فراہم کر سکتا ہوں، سنگین صحت کے خدشات کی ہمیشہ کوالیفائیڈ ہیلتھ کیئر پروفیشنلز کے ذریعے تشخیص کی جانی چاہیے جو براہ راست معائنہ کی بنیاد پر ذاتی نوعیت کی دیکھ بھال فراہم کر سکتے ہیں۔"""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
509
 
510
  class PDFReportGenerator:
511
  def __init__(self):
 
1137
  st.markdown('<h2 style="color: #00401A; border-bottom: 3px solid #00401A; padding-bottom: 10px;">💬 سیحت اے آئی ہیلتھ اسسٹنٹ</h2>', unsafe_allow_html=True)
1138
  st.write("صحت سے متعلق سوالات پوچھیں اور فوری، قابل اعتماد طبی معلومات حاصل کریں")
1139
 
1140
+ # Groq API Configuration
 
1141
  groq_api_key = st.secrets.get("GROQ_API_KEY", "") if hasattr(st, 'secrets') else ""
1142
 
1143
+ # Initialize chatbot with API if available
1144
  if groq_api_key:
1145
  st.session_state.groq_api_key = groq_api_key
1146
  try:
1147
  groq_client = GroqClient(groq_api_key)
1148
  chatbot = HealthcareChatbot(groq_client)
1149
+ st.session_state.api_available = True
1150
+ # Show API status
1151
+ st.success("✅ AI Assistant is using advanced language model for responses")
1152
  except Exception as e:
1153
  chatbot = HealthcareChatbot()
1154
+ st.session_state.api_available = False
1155
+ st.info("ℹ️ Using enhanced response system (API temporarily unavailable)")
1156
  else:
1157
  chatbot = HealthcareChatbot()
1158
+ st.session_state.api_available = False
1159
+ st.info("ℹ️ Using enhanced natural language response system")
1160
 
1161
  # Display chat history
1162
  for message in st.session_state.chat_history:
 
1195
  with col_qa1:
1196
  if st.button("❤️ Heart Health", use_container_width=True):
1197
  if language == "English":
1198
+ query = "What should I know about heart disease prevention and symptoms?"
1199
  else:
1200
+ query = "دل کی بیماری کی روک تھام اور علامات کے بارے میں مجھے کیا جاننا چاہیے؟"
1201
  st.session_state.chat_history.append({"role": "user", "content": query})
1202
  st.rerun()
1203
 
1204
  with col_qa2:
1205
  if st.button("🩺 Diabetes", use_container_width=True):
1206
  if language == "English":
1207
+ query = "Can you explain diabetes management and early warning signs?"
1208
  else:
1209
+ query = "کیا آپ ذیابیطس کے انتظام اور ابتدائی انتباہی علامات کی وضاحت کر سکتے ہیں؟"
1210
  st.session_state.chat_history.append({"role": "user", "content": query})
1211
  st.rerun()
1212
 
1213
  with col_qa3:
1214
  if st.button("💓 Blood Pressure", use_container_width=True):
1215
  if language == "English":
1216
+ query = "What are effective ways to manage high blood pressure naturally?"
1217
  else:
1218
+ query = "ہائی بلڈ پریشر کو قدرتی طور پر کنٹرول کرنے کے مؤثر طریقے کیا ہیں؟"
1219
  st.session_state.chat_history.append({"role": "user", "content": query})
1220
  st.rerun()
1221
 
1222
  with col_qa4:
1223
  if st.button("🍎 Nutrition", use_container_width=True):
1224
  if language == "English":
1225
+ query = "What dietary recommendations do you have for overall health?"
1226
  else:
1227
+ query = "مجموعی صحت کے لیے آپ کے پاس غذائی سفارشات کیا ہیں؟"
1228
  st.session_state.chat_history.append({"role": "user", "content": query})
1229
  st.rerun()
1230
 
1231
  # Test Medical Queries Section
1232
  if language == "English":
1233
  st.subheader("Test Medical Queries")
1234
+ st.write("Quickly test the assistant with these sample medical questions:")
1235
  else:
1236
  st.subheader("طبی سوالات کی جانچ")
1237
+ st.write("ان نمونہ طبی سوالات کے ساتھ اسسٹنٹ کو فوری طور پر آزمائیں:")
1238
 
1239
  test_col1, test_col2 = st.columns(2)
1240
 
 
1250
  with test_col2:
1251
  if st.button("Test Diabetes Query", use_container_width=True):
1252
  if language == "English":
1253
+ test_query = "What are the early symptoms of diabetes I should watch for?"
1254
  else:
1255
+ test_query = "ذیابیطس کی ابتدائی علامات کیا ہیں جن پر مجھے نظر رکھنی چاہیے؟"
1256
  st.session_state.chat_history.append({"role": "user", "content": test_query})
1257
  st.rerun()
1258