File size: 5,929 Bytes
a6dd66b
0eb63a5
a6dd66b
0eb63a5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e4da22c
 
0eb63a5
 
 
 
 
 
 
 
 
a6dd66b
 
 
 
 
e4da22c
0eb63a5
e4da22c
0eb63a5
 
 
 
 
 
 
 
 
 
e4da22c
 
 
a6dd66b
 
0eb63a5
 
 
e4da22c
 
a6dd66b
 
0eb63a5
 
a6dd66b
0eb63a5
 
 
a6dd66b
 
 
0eb63a5
 
 
a6dd66b
0eb63a5
 
a6dd66b
 
 
0f878f4
0eb63a5
a6dd66b
 
0eb63a5
 
 
a6dd66b
0eb63a5
 
a6dd66b
0eb63a5
 
 
a6dd66b
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import gradio as gr
import numpy as np

# Your original symptom list (copied from your code)
all_symptoms = [
    'abdominal_pain', 'abnormal_menstruation', 'acidity', 'acute_liver_failure', 
    'altered_sensorium', 'anxiety', 'back_pain', 'belly_pain', 'blackheads', 
    'bladder_discomfort', 'blister', 'blood_in_sputum', 'bloody_stool', 
    'blurred_and_distorted_vision', 'breathlessness', 'brittle_nails', 
    'bruising', 'burning_micturition', 'chest_pain', 'chills', 'cold_hands_and_feets', 
    'coma', 'congestion', 'constipation', 'continuous_feel_of_urine', 
    'continuous_sneezing', 'cough', 'cramps', 'dark_urine', 'dehydration', 
    'depression', 'diarrhoea', 'dischromic _patches', 'distention_of_abdomen', 
    'dizziness', 'drying_and_tingling_lips', 'enlarged_thyroid', 'excessive_hunger', 
    'extra_marital_contacts', 'family_history', 'fast_heart_rate', 'fatigue', 
    'fluid_overload', 'fluid_overload.1', 'foul_smell_of urine', 'headache', 
    'high_fever', 'hip_joint_pain', 'history_of_alcohol_consumption', 'increased_appetite', 
    'indigestion', 'inflammatory_nails', 'internal_itching', 'irregular_sugar_level', 
    'irritability', 'irritation_in_anus', 'itching', 'joint_pain', 'knee_pain', 
    'lack_of_concentration', 'lethargy', 'loss_of_appetite', 'loss_of_balance', 
    'loss_of_smell', 'malaise', 'mild_fever', 'mood_swings', 'movement_stiffness', 
    'mucoid_sputum', 'muscle_pain', 'muscle_wasting', 'muscle_weakness', 
    'nausea', 'neck_pain', 'nodal_skin_eruptions', 'obesity', 'pain_behind_the_eyes', 
    'pain_during_bowel_movements', 'pain_in_anal_region', 'painful_walking', 
    'palpitations', 'passage_of_gases', 'patches_in_throat', 'phlegm', 
    'polyuria', 'prominent_veins_on_calf', 'puffy_face_and_eyes', 'pus_filled_pimples', 
    'receiving_blood_transfusion', 'receiving_unsterile_injections', 'red_sore_around_nose', 
    'red_spots_over_body', 'redness_of_eyes', 'restlessness', 'runny_nose', 
    'rusty_sputum', 'scurring', 'shivering', 'silver_like_dusting', 'sinus_pressure', 
    'skin_peeling', 'skin_rash', 'slurred_speech', 'small_dents_in_nails', 
    'spinning_movements', 'spotting_ urination', 'stiff_neck', 'stomach_bleeding', 
    'stomach_pain', 'sunken_eyes', 'sweating', 'swelled_lymph_nodes', 
    'swelling_joints', 'swelling_of_stomach', 'swollen_blood_vessels', 
    'swollen_extremeties', 'swollen_legs', 'throat_irritation', 'toxic_look_(typhos)', 
    'ulcers_on_tongue', 'unsteadiness', 'visual_disturbances', 'vomiting', 
    'watering_from_eyes', 'weakness_in_limbs', 'weakness_of_one_body_side', 
    'weight_gain', 'weight_loss', 'yellow_crust_ooze', 'yellow_urine', 
    'yellowish_skin', 'yellowing_of_eyes'
]

# Convert to display format (your original formatting)
display_symptoms = [symptom.replace('_', ' ').title() for symptom in all_symptoms]

# Medical knowledge base (simplified but with your structure)
MEDICAL_KNOWLEDGE = {
    "fungal infection": "Antifungal creams or oral medications may be needed",
    "allergy": "Antihistamines can help relieve symptoms",
    "cold": "Rest and fluids are recommended",
    # Add more conditions as needed
}

def predict_disease(selected_labels):
    if not selected_labels or len(selected_labels) < 4:
        return "⚠️ Please select at least 4 symptoms for accurate results."
    
    # Mock prediction with your symptom list
    return f"""
    <div style='background: #001a33; padding: 15px; border-radius: 8px; margin-bottom: 15px;'>
        <h3 style='color: #4fc3f7; margin-top: 0;'>🩺 Predicted Disease</h3>
        <p style='font-size: 18px; color: white;'>Common Cold <span style='color: #4fc3f7'>(85% confidence)</span></p>
    </div>
    <div style='background: #001a33; padding: 15px; border-radius: 8px;'>
        <h3 style='color: #4fc3f7; margin-top: 0;'>πŸ” Top 3 Possible Conditions</h3>
        <ul style='color: white; padding-left: 20px;'>
            <li><b>1. Common Cold</b> β€” 85%</li>
            <li><b>2. Allergic Reaction</b> β€” 65%</li>
            <li><b>3. Viral Infection</b> β€” 45%</li>
        </ul>
    </div>
    """

def chatbot_respond(message, chat_history):
    response = "This is a demo response. In a real app, this would provide medical advice."
    for condition, advice in MEDICAL_KNOWLEDGE.items():
        if condition in message.lower():
            response = advice
            break
    return chat_history + [(message, response)], ""

# Your original UI with all symptoms
with gr.Blocks(title="Medical Diagnosis Assistant") as demo:
    gr.Markdown("""
    <div style='text-align: center; margin-bottom: 20px;'>
        <h1 style='margin-bottom: 5px; color: #4fc3f7;'>🧬 Medical Diagnosis Assistant</h1>
        <p style='color: #4fc3f7; font-size: 16px;'>Select symptoms for diagnosis</p>
    </div>
    """)

    with gr.Row():
        with gr.Column():
            gr.Markdown("### πŸ” Symptom Checker")
            symptoms_input = gr.CheckboxGroup(
                choices=display_symptoms,
                label="Select your symptoms:",
                interactive=True
            )
            predict_btn = gr.Button("Analyze Symptoms", variant="primary")
            prediction_output = gr.HTML(
                value="<div style='padding: 20px; background: #001a33; border-radius: 8px; color: white;'>Your results will appear here</div>"
            )

        with gr.Column():
            gr.Markdown("### πŸ’¬ Medical Advisor")
            chatbot = gr.Chatbot(bubble_full_width=False)
            with gr.Row():
                user_input = gr.Textbox(placeholder="Ask about symptoms...")
                send_btn = gr.Button("Send")

    predict_btn.click(predict_disease, symptoms_input, prediction_output)
    send_btn.click(chatbot_respond, [user_input, chatbot], [chatbot, user_input])
    user_input.submit(chatbot_respond, [user_input, chatbot], [chatbot, user_input])

demo.launch()