PranayChamala commited on
Commit
9af961d
·
1 Parent(s): b9e9312

Made changes to chatbot.py

Browse files
Files changed (1) hide show
  1. app/chatbot.py +11 -7
app/chatbot.py CHANGED
@@ -80,7 +80,6 @@ import random
80
  # Chatbot session class
81
  # -------------------------------
82
  class ChatbotSession:
83
-
84
  def __init__(self):
85
  self.conversation_history = []
86
  self.reported_symptoms = set()
@@ -183,16 +182,21 @@ class ChatbotSession:
183
  matches = len(set(self.reported_symptoms) & set(symptoms))
184
  if matches > 0:
185
  score = matches / len(symptoms)
186
- match_scores.append((disease, score))
 
187
 
188
  match_scores.sort(key=lambda x: x[1], reverse=True)
189
- self.predicted_diseases = match_scores[:3] # Top 3 predictions
190
 
191
  def _generate_summary(self):
192
- report = "\n".join([
193
- f"- {sym.title()}: {details}" if isinstance(details, dict) else f"- {sym.title()}: {details}"
194
- for sym, details in self.symptom_details.items()
195
- ])
 
 
 
 
196
 
197
  disease_part = ""
198
  if self.predicted_diseases:
 
80
  # Chatbot session class
81
  # -------------------------------
82
  class ChatbotSession:
 
83
  def __init__(self):
84
  self.conversation_history = []
85
  self.reported_symptoms = set()
 
182
  matches = len(set(self.reported_symptoms) & set(symptoms))
183
  if matches > 0:
184
  score = matches / len(symptoms)
185
+ if matches >= 2: # Only consider diseases with at least 2 matching symptoms
186
+ match_scores.append((disease, score))
187
 
188
  match_scores.sort(key=lambda x: x[1], reverse=True)
189
+ self.predicted_diseases = match_scores[:2] # Top 2 predictions
190
 
191
  def _generate_summary(self):
192
+ report_lines = []
193
+ for sym, details in self.symptom_details.items():
194
+ if isinstance(details, dict) and details:
195
+ formatted_details = ", ".join(f"{k}: {v}" for k, v in details.items())
196
+ report_lines.append(f"- {sym.title()}: {formatted_details}")
197
+ else:
198
+ report_lines.append(f"- {sym.title()}: {details}")
199
+ report = "\n".join(report_lines)
200
 
201
  disease_part = ""
202
  if self.predicted_diseases: