Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -230,12 +230,43 @@ def app_function_chatbot(user_input, location, query, history):
|
|
| 230 |
return chatbot_history, sentiment_result, emotion_result, suggestions, professionals, map_html
|
| 231 |
|
| 232 |
# Disease Prediction Logic
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 233 |
def predict_disease(symptoms):
|
| 234 |
"""Predict disease based on input symptoms."""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 235 |
input_test = np.zeros(len(X_train.columns)) # Create an array for feature input
|
| 236 |
-
for symptom in
|
| 237 |
if symptom in X_train.columns:
|
| 238 |
input_test[X_train.columns.get_loc(symptom)] = 1
|
|
|
|
| 239 |
predictions = {}
|
| 240 |
for model_name, info in trained_models.items():
|
| 241 |
prediction = info['model'].predict([input_test])[0]
|
|
@@ -251,11 +282,11 @@ def predict_disease(symptoms):
|
|
| 251 |
|
| 252 |
return "\n".join(markdown_output)
|
| 253 |
|
|
|
|
| 254 |
from gradio.components import HTML
|
| 255 |
|
| 256 |
# Custom CSS for styling
|
| 257 |
-
|
| 258 |
-
/* Importing Google Fonts */
|
| 259 |
@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap');
|
| 260 |
|
| 261 |
/* General Body Styling */
|
|
@@ -272,7 +303,7 @@ h1, h2, h3, h4 {
|
|
| 272 |
|
| 273 |
h1 {
|
| 274 |
font-size: 2.5rem; /* Bigger header size */
|
| 275 |
-
background: linear-gradient(135deg, #3c6487, #355f7a);
|
| 276 |
color: #ffffff;
|
| 277 |
border-radius: 12px;
|
| 278 |
padding: 15px;
|
|
@@ -281,23 +312,29 @@ h1 {
|
|
| 281 |
margin-bottom: 20px; /* Spacing below the header */
|
| 282 |
}
|
| 283 |
|
| 284 |
-
/*
|
| 285 |
-
button
|
| 286 |
-
background-color:
|
| 287 |
-
color:
|
| 288 |
-
border:
|
| 289 |
-
padding: 10px 15px; /*
|
| 290 |
-
font-size:
|
|
|
|
| 291 |
cursor: pointer; /* Pointer on hover */
|
| 292 |
-
|
|
|
|
|
|
|
|
|
|
| 293 |
}
|
| 294 |
|
| 295 |
-
|
| 296 |
-
|
|
|
|
|
|
|
| 297 |
}
|
| 298 |
|
| 299 |
-
/* Add a
|
| 300 |
-
button
|
| 301 |
content: ""; /* Empty content for underline */
|
| 302 |
display: block;
|
| 303 |
width: 100%; /* Full width */
|
|
@@ -306,6 +343,12 @@ button[role="tab"].selected::after {
|
|
| 306 |
position: absolute;
|
| 307 |
bottom: -5px; /* Position it below the text */
|
| 308 |
left: 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 309 |
}
|
| 310 |
|
| 311 |
/* Input and Textarea Styling */
|
|
@@ -324,26 +367,6 @@ textarea:focus, input:focus {
|
|
| 324 |
box-shadow: 0 0 5px rgba(174, 28, 147, 0.5); /* Shadow on focus */
|
| 325 |
}
|
| 326 |
|
| 327 |
-
/* Button Styling */
|
| 328 |
-
.gr-button {
|
| 329 |
-
background-color: #3c6487; /* Button background */
|
| 330 |
-
color: white;
|
| 331 |
-
border-radius: 8px;
|
| 332 |
-
padding: 10px 20px; /* Adjusted padding */
|
| 333 |
-
font-size: 16px; /* Larger font size for buttons */
|
| 334 |
-
border: none; /* No border */
|
| 335 |
-
cursor: pointer; /* Pointer on hover */
|
| 336 |
-
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.2); /* Shadow on button */
|
| 337 |
-
}
|
| 338 |
-
|
| 339 |
-
.gr-button:hover {
|
| 340 |
-
background-color: #ae1c93; /* Change button color on hover */
|
| 341 |
-
}
|
| 342 |
-
|
| 343 |
-
.gr-button:active {
|
| 344 |
-
background-color: #8f167b; /* Even darker shade on active */
|
| 345 |
-
}
|
| 346 |
-
|
| 347 |
/* DataFrame Container Styling */
|
| 348 |
.df-container {
|
| 349 |
background: white; /* Background for data frames */
|
|
@@ -383,7 +406,6 @@ textarea:focus, input:focus {
|
|
| 383 |
margin-bottom: 10px; /* Spacing between inputs */
|
| 384 |
}
|
| 385 |
}
|
| 386 |
-
"""
|
| 387 |
|
| 388 |
# Gradio Application Interface
|
| 389 |
with gr.Blocks(css=custom_css) as app:
|
|
@@ -412,15 +434,15 @@ with gr.Blocks(css=custom_css) as app:
|
|
| 412 |
)
|
| 413 |
|
| 414 |
with gr.Tab("Disease Prediction"):
|
| 415 |
-
symptom1 = gr.Dropdown(X_train.columns.tolist(), label="Select Symptom 1")
|
| 416 |
-
symptom2 = gr.Dropdown(X_train.columns.tolist(), label="Select Symptom 2")
|
| 417 |
-
symptom3 = gr.Dropdown(X_train.columns.tolist(), label="Select Symptom 3")
|
| 418 |
-
symptom4 = gr.Dropdown(X_train.columns.tolist(), label="Select Symptom 4")
|
| 419 |
-
symptom5 = gr.Dropdown(X_train.columns.tolist(), label="Select Symptom 5")
|
| 420 |
-
|
| 421 |
submit_disease = gr.Button(value="Predict Disease", variant="primary", icon="fa-stethoscope")
|
| 422 |
-
|
| 423 |
-
disease_prediction_result = gr.Markdown(label="Predicted Diseases")
|
| 424 |
|
| 425 |
submit_disease.click(
|
| 426 |
lambda symptom1, symptom2, symptom3, symptom4, symptom5: predict_disease(
|
|
@@ -429,5 +451,6 @@ with gr.Blocks(css=custom_css) as app:
|
|
| 429 |
outputs=disease_prediction_result
|
| 430 |
)
|
| 431 |
|
|
|
|
| 432 |
# Launch the Gradio application
|
| 433 |
app.launch()
|
|
|
|
| 230 |
return chatbot_history, sentiment_result, emotion_result, suggestions, professionals, map_html
|
| 231 |
|
| 232 |
# Disease Prediction Logic
|
| 233 |
+
# def predict_disease(symptoms):
|
| 234 |
+
# """Predict disease based on input symptoms."""
|
| 235 |
+
# valid_symptoms = [s for s in symptoms if s is not None]
|
| 236 |
+
# if len(valid_symptoms) < 3:
|
| 237 |
+
# return "Please select at least 3 symptoms for a better prediction."
|
| 238 |
+
# input_test = np.zeros(len(X_train.columns)) # Create an array for feature input
|
| 239 |
+
# for symptom in symptoms:
|
| 240 |
+
# if symptom in X_train.columns:
|
| 241 |
+
# input_test[X_train.columns.get_loc(symptom)] = 1
|
| 242 |
+
# predictions = {}
|
| 243 |
+
# for model_name, info in trained_models.items():
|
| 244 |
+
# prediction = info['model'].predict([input_test])[0]
|
| 245 |
+
# predicted_disease = label_encoder_train.inverse_transform([prediction])[0]
|
| 246 |
+
# predictions[model_name] = predicted_disease
|
| 247 |
+
|
| 248 |
+
# # Create a Markdown table for displaying predictions
|
| 249 |
+
# markdown_output = ["### Predicted Diseases"]
|
| 250 |
+
# markdown_output.append("| Model | Predicted Disease |")
|
| 251 |
+
# markdown_output.append("|-------|------------------|") # Table headers
|
| 252 |
+
# for model_name, disease in predictions.items():
|
| 253 |
+
# markdown_output.append(f"| {model_name} | {disease} |")
|
| 254 |
+
|
| 255 |
+
# return "\n".join(markdown_output)
|
| 256 |
def predict_disease(symptoms):
|
| 257 |
"""Predict disease based on input symptoms."""
|
| 258 |
+
# Filter out None values
|
| 259 |
+
valid_symptoms = [s for s in symptoms if s is not None]
|
| 260 |
+
|
| 261 |
+
# Ensure at least 3 symptoms are selected
|
| 262 |
+
if len(valid_symptoms) < 3:
|
| 263 |
+
return "Please select at least 3 symptoms for a better prediction."
|
| 264 |
+
|
| 265 |
input_test = np.zeros(len(X_train.columns)) # Create an array for feature input
|
| 266 |
+
for symptom in valid_symptoms:
|
| 267 |
if symptom in X_train.columns:
|
| 268 |
input_test[X_train.columns.get_loc(symptom)] = 1
|
| 269 |
+
|
| 270 |
predictions = {}
|
| 271 |
for model_name, info in trained_models.items():
|
| 272 |
prediction = info['model'].predict([input_test])[0]
|
|
|
|
| 282 |
|
| 283 |
return "\n".join(markdown_output)
|
| 284 |
|
| 285 |
+
|
| 286 |
from gradio.components import HTML
|
| 287 |
|
| 288 |
# Custom CSS for styling
|
| 289 |
+
/* Custom CSS for styling */
|
|
|
|
| 290 |
@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap');
|
| 291 |
|
| 292 |
/* General Body Styling */
|
|
|
|
| 303 |
|
| 304 |
h1 {
|
| 305 |
font-size: 2.5rem; /* Bigger header size */
|
| 306 |
+
background: linear-gradient(135deg, #3c6487, #355f7a);
|
| 307 |
color: #ffffff;
|
| 308 |
border-radius: 12px;
|
| 309 |
padding: 15px;
|
|
|
|
| 312 |
margin-bottom: 20px; /* Spacing below the header */
|
| 313 |
}
|
| 314 |
|
| 315 |
+
/* Button Styling */
|
| 316 |
+
.gr-button {
|
| 317 |
+
background-color: #3c6487; /* Button background */
|
| 318 |
+
color: white;
|
| 319 |
+
border-radius: 8px;
|
| 320 |
+
padding: 10px 15px; /* Adjusted padding */
|
| 321 |
+
font-size: 16px; /* Font size for buttons */
|
| 322 |
+
border: none; /* No border */
|
| 323 |
cursor: pointer; /* Pointer on hover */
|
| 324 |
+
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.2); /* Shadow on button */
|
| 325 |
+
display: inline-block; /* Inline-block to wrap text */
|
| 326 |
+
position: relative; /* For pseudo-element positioning */
|
| 327 |
+
text-decoration: none; /* Remove default underline */
|
| 328 |
}
|
| 329 |
|
| 330 |
+
/* Button hover states */
|
| 331 |
+
.gr-button:hover {
|
| 332 |
+
background: linear-gradient(to right, #a0c4e1, #3c6487); /* Light blue gradient on hover */
|
| 333 |
+
transition: background 0.3s; /* Ease the background change */
|
| 334 |
}
|
| 335 |
|
| 336 |
+
/* Add a blue underline effect */
|
| 337 |
+
.gr-button::after {
|
| 338 |
content: ""; /* Empty content for underline */
|
| 339 |
display: block;
|
| 340 |
width: 100%; /* Full width */
|
|
|
|
| 343 |
position: absolute;
|
| 344 |
bottom: -5px; /* Position it below the text */
|
| 345 |
left: 0;
|
| 346 |
+
transform: scaleX(0); /* Initially scale to 0 (invisible) */
|
| 347 |
+
transition: transform 0.3s; /* Smooth transition for the underline */
|
| 348 |
+
}
|
| 349 |
+
|
| 350 |
+
.gr-button:hover::after {
|
| 351 |
+
transform: scaleX(1); /* Scale to full width on hover */
|
| 352 |
}
|
| 353 |
|
| 354 |
/* Input and Textarea Styling */
|
|
|
|
| 367 |
box-shadow: 0 0 5px rgba(174, 28, 147, 0.5); /* Shadow on focus */
|
| 368 |
}
|
| 369 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 370 |
/* DataFrame Container Styling */
|
| 371 |
.df-container {
|
| 372 |
background: white; /* Background for data frames */
|
|
|
|
| 406 |
margin-bottom: 10px; /* Spacing between inputs */
|
| 407 |
}
|
| 408 |
}
|
|
|
|
| 409 |
|
| 410 |
# Gradio Application Interface
|
| 411 |
with gr.Blocks(css=custom_css) as app:
|
|
|
|
| 434 |
)
|
| 435 |
|
| 436 |
with gr.Tab("Disease Prediction"):
|
| 437 |
+
symptom1 = gr.Dropdown(choices=[None] + X_train.columns.tolist(), label="Select Symptom 1", value=None)
|
| 438 |
+
symptom2 = gr.Dropdown(choices=[None] + X_train.columns.tolist(), label="Select Symptom 2", value=None)
|
| 439 |
+
symptom3 = gr.Dropdown(choices=[None] + X_train.columns.tolist(), label="Select Symptom 3", value=None)
|
| 440 |
+
symptom4 = gr.Dropdown(choices=[None] + X_train.columns.tolist(), label="Select Symptom 4", value=None)
|
| 441 |
+
symptom5 = gr.Dropdown(choices=[None] + X_train.columns.tolist(), label="Select Symptom 5", value=None)
|
| 442 |
+
|
| 443 |
submit_disease = gr.Button(value="Predict Disease", variant="primary", icon="fa-stethoscope")
|
| 444 |
+
|
| 445 |
+
disease_prediction_result = gr.Markdown(label="Predicted Diseases")
|
| 446 |
|
| 447 |
submit_disease.click(
|
| 448 |
lambda symptom1, symptom2, symptom3, symptom4, symptom5: predict_disease(
|
|
|
|
| 451 |
outputs=disease_prediction_result
|
| 452 |
)
|
| 453 |
|
| 454 |
+
|
| 455 |
# Launch the Gradio application
|
| 456 |
app.launch()
|