Update app.py
Browse files
app.py
CHANGED
@@ -30,7 +30,7 @@ lemmatizer = WordNetLemmatizer()
|
|
30 |
|
31 |
# Configure Streamlit page
|
32 |
st.set_page_config(
|
33 |
-
page_title='
|
34 |
page_icon='π¨ββοΈ',
|
35 |
layout='wide'
|
36 |
)
|
@@ -133,11 +133,29 @@ symptoms = [
|
|
133 |
]
|
134 |
|
135 |
# Input section with multiselect for symptoms
|
136 |
-
st.header("π
|
137 |
-
selected_symptoms = st.multiselect("Choose the symptoms:", symptoms)
|
138 |
|
139 |
-
#
|
140 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
141 |
|
142 |
# Function to clean and preprocess text
|
143 |
def clean_text(raw_review):
|
@@ -197,41 +215,51 @@ predict_button = st.button("π Predict")
|
|
197 |
|
198 |
# Display results when the button is clicked
|
199 |
if predict_button:
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
235 |
|
236 |
# Warning and thank you message
|
237 |
st.markdown("---")
|
|
|
30 |
|
31 |
# Configure Streamlit page
|
32 |
st.set_page_config(
|
33 |
+
page_title='DPDR',
|
34 |
page_icon='π¨ββοΈ',
|
35 |
layout='wide'
|
36 |
)
|
|
|
133 |
]
|
134 |
|
135 |
# Input section with multiselect for symptoms
|
136 |
+
st.header("π Enter Patient Symptoms")
|
|
|
137 |
|
138 |
+
# Radio button to choose input method
|
139 |
+
input_method = st.radio(
|
140 |
+
"Choose how you want to enter symptoms:",
|
141 |
+
options=["Select from predefined list", "Type your own text"],
|
142 |
+
index=0 # Default to the first option
|
143 |
+
)
|
144 |
+
|
145 |
+
# Initialize raw_text
|
146 |
+
raw_text = ""
|
147 |
+
|
148 |
+
# Option 1: Select from predefined list
|
149 |
+
if input_method == "Select from predefined list":
|
150 |
+
selected_symptoms = st.multiselect("Choose the symptoms:", symptoms)
|
151 |
+
raw_text = ", ".join(selected_symptoms)
|
152 |
+
|
153 |
+
# Option 2: Type your own text
|
154 |
+
elif input_method == "Type your own text":
|
155 |
+
raw_text = st.text_area("Describe the patient's symptoms or condition here:", height=100)
|
156 |
+
|
157 |
+
# Display the final input text (for debugging or confirmation)
|
158 |
+
st.markdown(f"**Input Text:** {raw_text}")
|
159 |
|
160 |
# Function to clean and preprocess text
|
161 |
def clean_text(raw_review):
|
|
|
215 |
|
216 |
# Display results when the button is clicked
|
217 |
if predict_button:
|
218 |
+
# Check if input is empty
|
219 |
+
if not raw_text.strip():
|
220 |
+
st.warning("β οΈ Please enter symptoms or select from the predefined list before predicting.")
|
221 |
+
else:
|
222 |
+
with st.spinner("π§ Analyzing the condition and generating recommendations..."):
|
223 |
+
predict(raw_text)
|
224 |
+
|
225 |
+
st.markdown("---")
|
226 |
+
st.markdown("### π― Condition Predicted")
|
227 |
+
st.markdown(f"<div class='condition-card'><h3>{predicted_cond}</h3></div>", unsafe_allow_html=True)
|
228 |
+
|
229 |
+
st.markdown("---")
|
230 |
+
st.markdown("### π Top Recommended Drugs")
|
231 |
+
|
232 |
+
# Check if recommended drugs are less than 4
|
233 |
+
if len(top_drugs) < 4:
|
234 |
+
st.warning(f"β οΈ Only {len(top_drugs)} recommended drugs are available for this condition.")
|
235 |
+
|
236 |
+
# Display recommended drugs
|
237 |
+
for i, drug in enumerate(top_drugs):
|
238 |
+
if i == 0:
|
239 |
+
st.markdown(f"<div class='drug-card-1'><h4>{i + 1}. {drug}</h4></div>", unsafe_allow_html=True)
|
240 |
+
elif i == 1:
|
241 |
+
st.markdown(f"<div class='drug-card-2'><h4>{i + 1}. {drug}</h4></div>", unsafe_allow_html=True)
|
242 |
+
elif i == 2:
|
243 |
+
st.markdown(f"<div class='drug-card-3'><h4>{i + 1}. {drug}</h4></div>", unsafe_allow_html=True)
|
244 |
+
elif i == 3:
|
245 |
+
st.markdown(f"<div class='drug-card-4'><h4>{i + 1}. {drug}</h4></div>", unsafe_allow_html=True)
|
246 |
+
|
247 |
+
# Visualize top drugs using a bar chart with matching colors
|
248 |
+
st.markdown("---")
|
249 |
+
st.markdown("### π Drug Recommendations Visualization")
|
250 |
+
df_drugs = pd.DataFrame({"Drug": top_drugs, "Rank": range(len(top_drugs), 0, -1)}) # Reverse ranks
|
251 |
+
fig = px.bar(df_drugs, x="Rank", y="Drug", title="Top Recommended Drugs",
|
252 |
+
labels={"Drug": "Drug Name", "Rank": "Rank"},
|
253 |
+
orientation='h', # Horizontal bar chart
|
254 |
+
color="Drug", # Color by drug name
|
255 |
+
color_discrete_map={
|
256 |
+
top_drugs[0]: "#b4befe", # Lavender
|
257 |
+
top_drugs[1]: "#a6e3a1", # Green
|
258 |
+
top_drugs[2]: "#f38ba8", # Red
|
259 |
+
top_drugs[3]: "#f2cdcd" # Flamingo
|
260 |
+
}) # Map colors to drugs
|
261 |
+
fig.update_layout(yaxis={'categoryorder':'total ascending'}) # Sort by rank
|
262 |
+
st.plotly_chart(fig, use_container_width=True)
|
263 |
|
264 |
# Warning and thank you message
|
265 |
st.markdown("---")
|