DreamStream-1 commited on
Commit
6606c0f
·
verified ·
1 Parent(s): 3a640f9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +69 -101
app.py CHANGED
@@ -67,12 +67,12 @@ def load_data():
67
  'GERD': 2,
68
  'Chronic cholestasis': 3,
69
  'Drug Reaction': 4,
70
- 'Peptic ulcer disease': 5, # corrected spelling
71
  'AIDS': 6,
72
- 'Diabetes': 7, # corrected spelling (removed extra space)
73
  'Gastroenteritis': 8,
74
  'Bronchial Asthma': 9,
75
- 'Hypertension': 10, # corrected spelling (removed extra space)
76
  'Migraine': 11,
77
  'Cervical spondylosis': 12,
78
  'Paralysis (brain hemorrhage)': 13,
@@ -81,7 +81,7 @@ def load_data():
81
  'Chicken pox': 16,
82
  'Dengue': 17,
83
  'Typhoid': 18,
84
- 'Hepatitis A': 19, # corrected spelling (capitalized)
85
  'Hepatitis B': 20,
86
  'Hepatitis C': 21,
87
  'Hepatitis D': 22,
@@ -90,15 +90,15 @@ def load_data():
90
  'Tuberculosis': 25,
91
  'Common Cold': 26,
92
  'Pneumonia': 27,
93
- 'Dimorphic hemorrhoids (piles)': 28, # corrected spelling
94
  'Heart attack': 29,
95
  'Varicose veins': 30,
96
  'Hypothyroidism': 31,
97
  'Hyperthyroidism': 32,
98
  'Hypoglycemia': 33,
99
- 'Osteoarthritis': 34, # corrected spelling
100
  'Arthritis': 35,
101
- '(vertigo) Paroxysmal Positional Vertigo': 36, # corrected spelling
102
  'Acne': 37,
103
  'Urinary tract infection': 38,
104
  'Psoriasis': 39,
@@ -318,102 +318,70 @@ def app_function(user_input, location, query, symptoms, history):
318
  disease_results
319
  )
320
 
321
- # CSS Styling
322
- custom_css = """
323
- body {
324
- font-family: 'Roboto', sans-serif;
325
- background-color: #3c6487;
326
- color: white;
327
- }
328
- h1 {
329
- background: #ffffff;
330
- color: #000000;
331
- border-radius: 8px;
332
- padding: 10px;
333
- font-weight: bold;
334
- text-align: center;
335
- font-size: 2.5rem;
336
- }
337
- textarea, input {
338
- background: transparent;
339
- color: black;
340
- border: 2px solid orange;
341
- padding: 8px;
342
- font-size: 1rem;
343
- caret-color: black;
344
- outline: none;
345
- border-radius: 8px;
346
- }
347
- textarea:focus, input:focus {
348
- background: transparent;
349
- color: black;
350
- border: 2px solid orange;
351
- outline: none;
352
- }
353
- .df-container {
354
- background: white;
355
- color: black;
356
- border: 2px solid orange;
357
- border-radius: 10px;
358
- padding: 10px;
359
- font-size: 14px;
360
- max-height: 400px;
361
- height: auto;
362
- overflow-y: auto;
363
- }
364
- #suggestions-title {
365
- text-align: center !important;
366
- font-weight: bold !important;
367
- color: white !important;
368
- font-size: 4.2rem !important;
369
- margin-bottom: 20px !important;
370
- }
371
- .gr-button {
372
- background-color: #ae1c93;
373
- box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1), 0 2px 4px rgba(0, 0, 0, 0.06);
374
- transition: background-color 0.3s ease;
375
- }
376
- .gr-button:hover {
377
- background-color: #8f167b;
378
- }
379
- .gr-button:active {
380
- background-color: #7f156b;
381
- }
382
- """
383
-
384
- # Gradio Application
385
- with gr.Blocks(css=custom_css) as app:
386
- gr.HTML("<h1>🌟 Well-Being Companion</h1>")
387
 
388
- with gr.Row():
389
- user_input = gr.Textbox(label="Please Enter Your Message Here", placeholder="Type your message...")
390
- location = gr.Textbox(label="Your Current Location Here", placeholder="Enter location...")
391
- query = gr.Textbox(label="Search Health Professionals Nearby", placeholder="What are you looking for...")
392
-
393
- with gr.Row():
394
- symptom1 = gr.Dropdown(choices=["None"] + l1, label="Symptom 1")
395
- symptom2 = gr.Dropdown(choices=["None"] + l1, label="Symptom 2")
396
- symptom3 = gr.Dropdown(choices=["None"] + l1, label="Symptom 3")
397
- symptom4 = gr.Dropdown(choices=["None"] + l1, label="Symptom 4")
398
- symptom5 = gr.Dropdown(choices=["None"] + l1, label="Symptom 5")
399
-
400
- submit = gr.Button(value="Submit", variant="primary")
401
-
402
- chatbot = gr.Chatbot(label="Chat History")
403
- sentiment = gr.Textbox(label="Detected Sentiment")
404
- emotion = gr.Textbox(label="Detected Emotion")
405
 
406
- gr.Markdown("Suggestions", elem_id="suggestions-title")
 
 
 
 
 
 
 
 
407
 
408
- suggestions = gr.DataFrame(headers=["Title", "Link"])
409
- professionals = gr.DataFrame(label="Nearby Health Professionals", headers=["Name", "Address"])
410
- map_html = gr.HTML(label="Interactive Map")
411
- disease_predictions = gr.Textbox(label="Disease Predictions")
412
-
413
- submit.click(
414
- app_function,
415
- inputs=[user_input, location, query, [symptom1, symptom2, symptom3, symptom4, symptom5], chatbot],
416
- outputs=[chatbot, sentiment, emotion, suggestions, professionals, map_html, disease_predictions],
417
- )
418
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
419
  app.launch()
 
67
  'GERD': 2,
68
  'Chronic cholestasis': 3,
69
  'Drug Reaction': 4,
70
+ 'Peptic ulcer disease': 5,
71
  'AIDS': 6,
72
+ 'Diabetes': 7,
73
  'Gastroenteritis': 8,
74
  'Bronchial Asthma': 9,
75
+ 'Hypertension': 10,
76
  'Migraine': 11,
77
  'Cervical spondylosis': 12,
78
  'Paralysis (brain hemorrhage)': 13,
 
81
  'Chicken pox': 16,
82
  'Dengue': 17,
83
  'Typhoid': 18,
84
+ 'Hepatitis A': 19,
85
  'Hepatitis B': 20,
86
  'Hepatitis C': 21,
87
  'Hepatitis D': 22,
 
90
  'Tuberculosis': 25,
91
  'Common Cold': 26,
92
  'Pneumonia': 27,
93
+ 'Dimorphic hemorrhoids (piles)': 28,
94
  'Heart attack': 29,
95
  'Varicose veins': 30,
96
  'Hypothyroidism': 31,
97
  'Hyperthyroidism': 32,
98
  'Hypoglycemia': 33,
99
+ 'Osteoarthritis': 34,
100
  'Arthritis': 35,
101
+ '(vertigo) Paroxysmal Positional Vertigo': 36,
102
  'Acne': 37,
103
  'Urinary tract infection': 38,
104
  'Psoriasis': 39,
 
318
  disease_results
319
  )
320
 
321
+ # Disease Prediction Interface
322
+ def disease_app_function(name, symptom1, symptom2, symptom3, symptom4, symptom5):
323
+ if not name.strip():
324
+ return "Please enter the patient's name."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
325
 
326
+ symptoms_selected = [s for s in [symptom1, symptom2, symptom3, symptom4, symptom5] if s != "None"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
327
 
328
+ if len(symptoms_selected) < 3:
329
+ return "Please select at least 3 symptoms for accurate prediction."
330
+
331
+ results = []
332
+ for model_name, (model, acc) in trained_models.items():
333
+ prediction = predict_disease(model, symptoms_selected)
334
+ result = f"{model_name} Prediction: Predicted Disease: **{prediction}**"
335
+ result += f" (Accuracy: {acc * 100:.2f}%)"
336
+ results.append(result)
337
 
338
+ return "\n\n".join(results)
 
 
 
 
 
 
 
 
 
339
 
340
+ # Gradio Interface Setup
341
+ with gr.Blocks() as app:
342
+ gr.HTML("<h1>🌟 Well-Being Companion</h1>")
343
+
344
+ with gr.Tab("Mental Health Companion"):
345
+ with gr.Row():
346
+ user_input = gr.Textbox(label="Please Enter Your Message Here", placeholder="Type your message...")
347
+ location = gr.Textbox(label="Your Current Location Here", placeholder="Enter location...")
348
+ query = gr.Textbox(label="Search Health Professionals Nearby", placeholder="What are you looking for...")
349
+
350
+ with gr.Row():
351
+ symptom1 = gr.Dropdown(choices=["None"] + l1, label="Symptom 1")
352
+ symptom2 = gr.Dropdown(choices=["None"] + l1, label="Symptom 2")
353
+ symptom3 = gr.Dropdown(choices=["None"] + l1, label="Symptom 3")
354
+ symptom4 = gr.Dropdown(choices=["None"] + l1, label="Symptom 4")
355
+ symptom5 = gr.Dropdown(choices=["None"] + l1, label="Symptom 5")
356
+
357
+ submit_chatbot = gr.Button(value="Submit", variant="primary")
358
+ chatbot = gr.Chatbot(label="Chat History")
359
+ sentiment = gr.Textbox(label="Detected Sentiment")
360
+ emotion = gr.Textbox(label="Detected Emotion")
361
+
362
+ suggestions = gr.DataFrame(headers=["Title", "Link"])
363
+ professionals = gr.DataFrame(label="Nearby Health Professionals", headers=["Name", "Address"])
364
+ map_html = gr.HTML(label="Interactive Map")
365
+ disease_predictions = gr.Textbox(label="Disease Predictions")
366
+
367
+ submit_chatbot.click(
368
+ app_function,
369
+ inputs=[user_input, location, query, [symptom1, symptom2, symptom3, symptom4, symptom5], chatbot],
370
+ outputs=[chatbot, sentiment, emotion, suggestions, professionals, map_html, disease_predictions],
371
+ )
372
+
373
+ with gr.Tab("Disease Prediction"):
374
+ name_box = gr.Textbox(label="Name of Patient", placeholder="Enter patient's name")
375
+ symptom_choices = [gr.Dropdown(choices=["None"] + l1, label=f"Symptom {i+1}") for i in range(5)]
376
+ submit_disease = gr.Button(value="Submit", variant="primary")
377
+
378
+ disease_output = gr.Textbox(label="Predicted Disease", placeholder="Prediction will appear here")
379
+
380
+ submit_disease.click(
381
+ disease_app_function,
382
+ inputs=[name_box] + symptom_choices,
383
+ outputs=disease_output
384
+ )
385
+
386
+ # Launch the Gradio application
387
  app.launch()