sunbal7 commited on
Commit
401a11d
·
verified ·
1 Parent(s): 6679896

Delete chatbot.py

Browse files
Files changed (1) hide show
  1. chatbot.py +0 -125
chatbot.py DELETED
@@ -1,125 +0,0 @@
1
- import random
2
- from datetime import datetime
3
-
4
- class HealthcareChatbot:
5
- def __init__(self):
6
- self.health_knowledge_base = {
7
- 'heart_health': {
8
- 'tips': [
9
- "Maintain a heart-healthy diet rich in fruits, vegetables, and whole grains",
10
- "Aim for at least 150 minutes of moderate exercise per week",
11
- "Monitor your blood pressure regularly",
12
- "Avoid smoking and limit alcohol consumption",
13
- "Manage stress through relaxation techniques"
14
- ],
15
- 'symptoms': {
16
- 'chest_pain': "Chest pain can be a sign of heart issues. Consult a doctor immediately.",
17
- 'shortness_breath': "Shortness of breath may indicate cardiac problems. Seek medical attention."
18
- }
19
- },
20
- 'diabetes_management': {
21
- 'tips': [
22
- "Monitor blood sugar levels regularly",
23
- "Follow a balanced diet with controlled carbohydrates",
24
- "Take medications as prescribed by your doctor",
25
- "Stay physically active with regular exercise",
26
- "Get regular eye and foot examinations"
27
- ]
28
- },
29
- 'hypertension': {
30
- 'tips': [
31
- "Reduce sodium intake in your diet",
32
- "Maintain a healthy body weight",
33
- "Limit alcohol and caffeine consumption",
34
- "Practice stress management techniques",
35
- "Take prescribed medications regularly"
36
- ]
37
- },
38
- 'general_health': {
39
- 'tips': [
40
- "Get 7-9 hours of quality sleep each night",
41
- "Stay hydrated by drinking plenty of water",
42
- "Practice good hygiene and hand washing",
43
- "Get regular health check-ups",
44
- "Maintain a balanced diet and healthy lifestyle"
45
- ]
46
- }
47
- }
48
-
49
- self.urdu_responses = {
50
- 'greeting': "السلام علیکم! میں آپ کی صحت کے معاملات میں مدد کر سکتا ہوں۔",
51
- 'heart_health': "دل کی صحت کے لیے مشورے:\n• پھل، سبزیاں اور سارے اناج سے بھرپور غذا کھائیں\n• ہفتے میں کم از کم 150 منٹ ورزش کریں\n• اپنا بلڈ پریشر باقاعدگی سے چیک کریں",
52
- 'diabetes': "ذیابیطس کے انتظام کے لیے:\n• خون میں شکر کی سطح باقاعدگی سے چیک کریں\n• متوازن غذا کھائیں\n• دوائیں ڈاکٹر کے مشورے سے لیں",
53
- 'hypertension': "ہائی بلڈ پریشر کے لیے:\n• نمک کا استعمال کم کریں\n• صحت مند وزن برقرار رکھیں\n• ورزش کو اپنی عادت بنائیں"
54
- }
55
-
56
- def get_response(self, user_input, language='English'):
57
- """Generate context-aware healthcare responses"""
58
- user_input_lower = user_input.lower()
59
-
60
- # Greeting detection
61
- if any(word in user_input_lower for word in ['hello', 'hi', 'hey', 'سلام', 'ہیلو']):
62
- if language == 'Urdu':
63
- return self.urdu_responses['greeting']
64
- else:
65
- return "Hello! I'm your healthcare assistant. How can I help you today?"
66
-
67
- # Topic-based responses
68
- response = self.generate_topic_response(user_input_lower, language)
69
-
70
- return response
71
-
72
- def generate_topic_response(self, user_input, language):
73
- """Generate response based on detected health topic"""
74
-
75
- if any(word in user_input for word in ['heart', 'cardiac', 'chest', 'دل', 'سینہ']):
76
- tips = self.health_knowledge_base['heart_health']['tips']
77
- if language == 'Urdu':
78
- return self.urdu_responses['heart_health']
79
- else:
80
- return "Heart Health Tips:\n" + "\n".join([f"• {tip}" for tip in tips])
81
-
82
- elif any(word in user_input for word in ['diabetes', 'sugar', 'glucose', 'شوگر', 'ذیابیطس']):
83
- tips = self.health_knowledge_base['diabetes_management']['tips']
84
- if language == 'Urdu':
85
- return self.urdu_responses['diabetes']
86
- else:
87
- return "Diabetes Management Tips:\n" + "\n".join([f"• {tip}" for tip in tips])
88
-
89
- elif any(word in user_input for word in ['blood pressure', 'hypertension', 'bp', 'بلڈ پریشر']):
90
- tips = self.health_knowledge_base['hypertension']['tips']
91
- if language == 'Urdu':
92
- return self.urdu_responses['hypertension']
93
- else:
94
- return "Hypertension Management Tips:\n" + "\n".join([f"• {tip}" for tip in tips])
95
-
96
- else:
97
- # General health tips
98
- tips = self.health_knowledge_base['general_health']['tips']
99
- if language == 'Urdu':
100
- return "عام صحت کے نکات:\n" + "\n".join([f"• {tip}" for tip in random.sample(tips, 3)])
101
- else:
102
- return "General Health Tips:\n" + "\n".join([f"• {tip}" for tip in random.sample(tips, 3)])
103
-
104
- def get_emergency_advice(self, symptoms, language='English'):
105
- """Provide emergency advice for concerning symptoms"""
106
- emergency_symptoms = {
107
- 'chest_pain': {
108
- 'english': "Chest pain can be serious. Seek immediate medical attention.",
109
- 'urdu': "سینے میں درد سنگین ہو سکتا ہے۔ فوری طبی امداد حاصل کریں۔"
110
- },
111
- 'severe_shortness_breath': {
112
- 'english': "Severe shortness of breath requires emergency care.",
113
- 'urdu': "سانس لینے میں شدید دشواری ہنگامی علاج کی ضرورت ہے۔"
114
- },
115
- 'fainting': {
116
- 'english': "Fainting spells need immediate medical evaluation.",
117
- 'urdu': "بیہوشی کے دورے فوری طبی تشخیص کی ضرورت ہے۔"
118
- }
119
- }
120
-
121
- for symptom, advice in emergency_symptoms.items():
122
- if symptom in symptoms:
123
- return advice['urdu'] if language == 'Urdu' else advice['english']
124
-
125
- return None