puneeth1 commited on
Commit
bc15897
Β·
verified Β·
1 Parent(s): 43e89b3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +68 -40
app.py CHANGED
@@ -30,7 +30,7 @@ lemmatizer = WordNetLemmatizer()
30
 
31
  # Configure Streamlit page
32
  st.set_page_config(
33
- page_title='PDDRS',
34
  page_icon='πŸ‘¨β€βš•οΈ',
35
  layout='wide'
36
  )
@@ -133,11 +133,29 @@ symptoms = [
133
  ]
134
 
135
  # Input section with multiselect for symptoms
136
- st.header("πŸ“ Select Patient Symptoms")
137
- selected_symptoms = st.multiselect("Choose the symptoms:", symptoms)
138
 
139
- # Convert selected symptoms to a single string
140
- raw_text = ", ".join(selected_symptoms)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
- with st.spinner("🧠 Analyzing the condition and generating recommendations..."):
201
- predict(raw_text)
202
-
203
- st.markdown("---")
204
- st.markdown("### 🎯 Condition Predicted")
205
- st.markdown(f"<div class='condition-card'><h3>{predicted_cond}</h3></div>", unsafe_allow_html=True)
206
-
207
- st.markdown("---")
208
- st.markdown("### πŸ’Š Top Recommended Drugs")
209
- for i, drug in enumerate(top_drugs):
210
- if i == 0:
211
- st.markdown(f"<div class='drug-card-1'><h4>{i + 1}. {drug}</h4></div>", unsafe_allow_html=True)
212
- elif i == 1:
213
- st.markdown(f"<div class='drug-card-2'><h4>{i + 1}. {drug}</h4></div>", unsafe_allow_html=True)
214
- elif i == 2:
215
- st.markdown(f"<div class='drug-card-3'><h4>{i + 1}. {drug}</h4></div>", unsafe_allow_html=True)
216
- elif i == 3:
217
- st.markdown(f"<div class='drug-card-4'><h4>{i + 1}. {drug}</h4></div>", unsafe_allow_html=True)
218
-
219
- # Visualize top drugs using a bar chart with matching colors
220
- st.markdown("---")
221
- st.markdown("### πŸ“Š Drug Recommendations Visualization")
222
- df_drugs = pd.DataFrame({"Drug": top_drugs, "Rank": range(len(top_drugs), 0, -1)}) # Reverse ranks
223
- fig = px.bar(df_drugs, x="Rank", y="Drug", title="Top Recommended Drugs",
224
- labels={"Drug": "Drug Name", "Rank": "Rank"},
225
- orientation='h', # Horizontal bar chart
226
- color="Drug", # Color by drug name
227
- color_discrete_map={
228
- top_drugs[0]: "#b4befe", # Lavender
229
- top_drugs[1]: "#a6e3a1", # Green
230
- top_drugs[2]: "#f38ba8", # Red
231
- top_drugs[3]: "#f2cdcd" # Flamingo
232
- }) # Map colors to drugs
233
- fig.update_layout(yaxis={'categoryorder':'total ascending'}) # Sort by rank
234
- st.plotly_chart(fig, use_container_width=True)
 
 
 
 
 
 
 
 
 
 
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("---")