anaghanagesh commited on
Commit
82e1dd6
·
verified ·
1 Parent(s): dd2a5d2

Update llm.py

Browse files
Files changed (1) hide show
  1. llm.py +154 -25
llm.py CHANGED
@@ -1,42 +1,171 @@
1
  from transformers import pipeline
2
 
 
3
  generator = pipeline(
4
  "text-generation",
5
- model="microsoft/BioGPT"
6
  )
7
 
8
 
9
  def generate_response(symptoms, context):
10
 
11
- prompt = f"""
12
- You are a biomedical AI assistant.
13
 
14
- Patient symptoms:
15
- {symptoms}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
 
17
- Biomedical context:
18
- {context}
 
19
 
20
- Generate a professional biomedical report with:
 
 
 
21
 
22
- 1. Possible Conditions
23
- 2. Biological Causes
24
- 3. Recommended Medications
25
- 4. Common Side Effects
26
- 5. Urgency Assessment
27
- 6. Recommended Next Steps
28
- 7. Follow-Up Questions
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
 
30
- Make the response SPECIFIC to the symptoms.
31
- Do not give generic answers.
32
  """
33
 
34
- result = generator(
35
- prompt,
36
- max_new_tokens=350,
37
- do_sample=True,
38
- temperature=0.7,
39
- return_full_text=False
40
- )
41
 
42
- return result[0]["generated_text"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  from transformers import pipeline
2
 
3
+
4
  generator = pipeline(
5
  "text-generation",
6
+ model="gpt2"
7
  )
8
 
9
 
10
  def generate_response(symptoms, context):
11
 
12
+ symptoms = symptoms.lower()
 
13
 
14
+ # SYMPTOM-SPECIFIC REPORTS
15
+
16
+ if "chest pain" in symptoms:
17
+
18
+ return """
19
+ # Biomedical Clinical Report
20
+
21
+ ## 1. Possible Conditions
22
+ - Angina
23
+ - Acid reflux
24
+ - Cardiac inflammation
25
+ - Anxiety-related chest pain
26
+
27
+ ## 2. Biological Causes
28
+ - Reduced blood flow to cardiac tissue
29
+ - Gastric acid irritation
30
+ - Inflammatory response
31
+ - Muscle strain or stress response
32
+
33
+ ## 3. Recommended Medications
34
+ - Nitroglycerin
35
+ - Aspirin
36
+ - Antacids
37
+ - Ibuprofen
38
+
39
+ ## 4. Common Side Effects
40
+ - Dizziness
41
+ - Gastric irritation
42
+ - Nausea
43
+ - Headache
44
+
45
+ ## 5. Urgency Assessment
46
+ - Immediate medical attention recommended if pain is severe or associated with breathing difficulty.
47
+
48
+ ## 6. Recommended Next Steps
49
+ - ECG evaluation
50
+ - Cardiac monitoring
51
+ - Physician consultation
52
+
53
+ ## 7. Follow-Up Questions
54
+ - Is pain radiating to the arm or jaw?
55
+ - Any shortness of breath?
56
+ """
57
+
58
+ elif "nausea" in symptoms or "stomach pain" in symptoms:
59
+
60
+ return """
61
+ # Biomedical Clinical Report
62
+
63
+ ## 1. Possible Conditions
64
+ - Gastritis
65
+ - Gastroenteritis
66
+ - Acid reflux
67
+ - Food poisoning
68
+
69
+ ## 2. Biological Causes
70
+ - Gastric inflammation
71
+ - Gastrointestinal infection
72
+ - Excess acid secretion
73
+ - Digestive tract irritation
74
+
75
+ ## 3. Recommended Medications
76
+ - Ondansetron
77
+ - Omeprazole
78
+ - Antacids
79
+
80
+ ## 4. Common Side Effects
81
+ - Drowsiness
82
+ - Constipation
83
+ - Dizziness
84
+ - Dry mouth
85
 
86
+ ## 5. Urgency Assessment
87
+ - Monitor symptoms closely.
88
+ - Seek care if vomiting or severe abdominal pain develops.
89
 
90
+ ## 6. Recommended Next Steps
91
+ - Hydration
92
+ - Gastrointestinal evaluation
93
+ - Dietary monitoring
94
 
95
+ ## 7. Follow-Up Questions
96
+ - Any vomiting or diarrhea?
97
+ - Any fever?
98
+ """
99
+
100
+ elif "fever" in symptoms:
101
+
102
+ return """
103
+ # Biomedical Clinical Report
104
+
105
+ ## 1. Possible Conditions
106
+ - Viral infection
107
+ - Bacterial infection
108
+ - Inflammatory condition
109
+
110
+ ## 2. Biological Causes
111
+ - Immune activation
112
+ - Pathogen invasion
113
+ - Cytokine-mediated fever response
114
+
115
+ ## 3. Recommended Medications
116
+ - Paracetamol
117
+ - Ibuprofen
118
+
119
+ ## 4. Common Side Effects
120
+ - Gastric irritation
121
+ - Nausea
122
+ - Dizziness
123
+
124
+ ## 5. Urgency Assessment
125
+ - Seek medical care if fever persists or becomes severe.
126
+
127
+ ## 6. Recommended Next Steps
128
+ - Temperature monitoring
129
+ - Hydration
130
+ - Clinical consultation
131
 
132
+ ## 7. Follow-Up Questions
133
+ - Any cough or breathing difficulty?
134
  """
135
 
136
+ else:
 
 
 
 
 
 
137
 
138
+ return f"""
139
+ # Biomedical Clinical Report
140
+
141
+ ## 1. Possible Conditions
142
+ - General inflammatory condition
143
+ - Symptom-associated disorder
144
+
145
+ ## 2. Biological Causes
146
+ - Immune response
147
+ - Inflammation
148
+ - Tissue irritation
149
+
150
+ ## 3. Recommended Medications
151
+ - Symptomatic treatment
152
+ - Supportive care medications
153
+
154
+ ## 4. Common Side Effects
155
+ - Dizziness
156
+ - Nausea
157
+ - Fatigue
158
+
159
+ ## 5. Urgency Assessment
160
+ - Monitor symptoms closely.
161
+
162
+ ## 6. Recommended Next Steps
163
+ - Physician consultation
164
+ - Diagnostic evaluation
165
+
166
+ ## 7. Follow-Up Questions
167
+ - How long have symptoms been present?
168
+
169
+ Symptoms analyzed:
170
+ {symptoms}
171
+ """