Prajith04 commited on
Commit
9a573be
·
verified ·
1 Parent(s): 4747b39

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -16
app.py CHANGED
@@ -124,15 +124,15 @@ class SelectedSymptomsQuery(BaseModel):
124
  def find_disease(query: SelectedSymptomsQuery):
125
  SelectedSymptoms = query.selected_symptoms
126
  all_selected_symptoms.extend(SelectedSymptoms)
127
-
128
  disease_list = []
129
  symptoms_list = []
130
- unique_symptoms_list = []
131
-
132
  # Combine all the symptoms we already know (all_symptoms + selected symptoms)
133
  known_symptoms = {symptom.lower() for symptom_set in all_symptoms for symptom in symptom_set}
134
  known_symptoms.update([symptom.lower() for symptom in SelectedSymptoms])
135
-
136
  # Generate combinations of symptoms from all_symptoms and selected symptoms
137
  for symptoms_set in all_symptoms:
138
  for i in range(1, len(symptoms_set) + 1): # Generate combinations with all lengths
@@ -141,7 +141,7 @@ def find_disease(query: SelectedSymptomsQuery):
141
 
142
  # Search for diseases that match the combination
143
  matching_diseases = df[df['Symptoms'].apply(lambda x: all(s in x for s in temp))]
144
-
145
  for _, row in matching_diseases.iterrows():
146
  disease_info = {
147
  'Disease': row['Name'],
@@ -149,17 +149,15 @@ def find_disease(query: SelectedSymptomsQuery):
149
  'Treatments': row['Treatments']
150
  }
151
  disease_list.append(disease_info)
152
-
153
- symptoms_info = row['Symptoms']
154
- symptoms_list.append(symptoms_info)
155
-
156
- # Flatten the list of symptoms and remove duplicates, excluding known symptoms
157
- for symptoms in symptoms_list:
158
- for symptom in symptoms:
159
- symptom_lower = symptom.lower()
160
- if symptom_lower not in known_symptoms and symptom_lower not in unique_symptoms_list:
161
- unique_symptoms_list.append(symptom_lower)
162
-
163
  return {
164
  "unique_symptoms_list": unique_symptoms_list,
165
  "all_selected_symptoms": all_selected_symptoms,
 
124
  def find_disease(query: SelectedSymptomsQuery):
125
  SelectedSymptoms = query.selected_symptoms
126
  all_selected_symptoms.extend(SelectedSymptoms)
127
+
128
  disease_list = []
129
  symptoms_list = []
130
+ unique_symptoms_set = set() # Use a set for unique symptoms
131
+
132
  # Combine all the symptoms we already know (all_symptoms + selected symptoms)
133
  known_symptoms = {symptom.lower() for symptom_set in all_symptoms for symptom in symptom_set}
134
  known_symptoms.update([symptom.lower() for symptom in SelectedSymptoms])
135
+
136
  # Generate combinations of symptoms from all_symptoms and selected symptoms
137
  for symptoms_set in all_symptoms:
138
  for i in range(1, len(symptoms_set) + 1): # Generate combinations with all lengths
 
141
 
142
  # Search for diseases that match the combination
143
  matching_diseases = df[df['Symptoms'].apply(lambda x: all(s in x for s in temp))]
144
+
145
  for _, row in matching_diseases.iterrows():
146
  disease_info = {
147
  'Disease': row['Name'],
 
149
  'Treatments': row['Treatments']
150
  }
151
  disease_list.append(disease_info)
152
+
153
+ # Add each symptom in lowercase to the set
154
+ for symptom in row['Symptoms']:
155
+ if symptom.lower() not in known_symptoms:
156
+ unique_symptoms_set.add(symptom.lower())
157
+
158
+ # Convert the set back to a list for the response
159
+ unique_symptoms_list = list(unique_symptoms_set)
160
+
 
 
161
  return {
162
  "unique_symptoms_list": unique_symptoms_list,
163
  "all_selected_symptoms": all_selected_symptoms,