Update app.py
Browse files
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 |
-
|
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 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
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,
|