File size: 3,983 Bytes
ab4526c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import pickle
import torch
from sentence_transformers import SentenceTransformer, util

# Load symptom embeddings (from models/)
with open("models/symptom_embeddings.pkl", "rb") as f:
    symptom_data = pickle.load(f)

# Function to identify disease
def identify_disease(user_symptom):
    embedding_model = SentenceTransformer('all-MiniLM-L6-v2')
    input_embedding = embedding_model.encode(user_symptom, convert_to_tensor=True)
    similarities = util.pytorch_cos_sim(input_embedding, symptom_data['embeddings'])[0]
    idx = similarities.argmax().item()
    return symptom_data['diseases'][idx], symptom_data['treatments'][idx]

# Clear button logic
def clear_symptoms():
    return "", "", ""

# Main UI layout for Symptom Checker tab
def symptom_checker_tab():
    gr.Markdown("## 🧠 TherapyBot++", elem_classes="centered-text")
    gr.Markdown("Describe your symptoms to get a possible diagnosis and treatment.", elem_classes="centered-text")

    with gr.Row():
        with gr.Column(scale=1):
            symptom_input = gr.Textbox(placeholder="e.g., I have a fever and rash", label="Enter your symptoms", lines=2)
            symptom_btn = gr.Button("Check", elem_id="symptom-btn")
            symptom_clear = gr.Button("Clear")
        with gr.Column(scale=1):
            predicted_disease = gr.Textbox(label="Predicted Disease", interactive=False, lines=2.2)
            suggested_treatment = gr.Textbox(label="Suggested Treatment", interactive=False, lines=2.2)

    symptom_btn.click(identify_disease, symptom_input, outputs=[predicted_disease, suggested_treatment])
    symptom_clear.click(clear_symptoms, outputs=[symptom_input, predicted_disease, suggested_treatment])

    gr.Markdown("""
    <!-- Scrolling Example Symptom Statements -->
    <div style="height: auto; min-height: 100px; width: 100%; max-width: 65%; margin: 15px auto; overflow: hidden; position: relative; background: linear-gradient(to right, #1c2f3a 0%, #000000 50%, #1c2f3a 100%); border-radius: 12px; box-shadow: 0 2px 12px rgba(0,0,0,0.4); text-align: center; padding: 16px 24px; box-sizing: border-box;">
        <div style="font-size: 15px; color: #e0e0e0; font-weight: 600; margin-bottom: 14px; position: relative; z-index: 2;">
            📌 <em>You may refer to these example symptom statements:</em>
        </div>
        <div class="scroll-wrapper">
            <div class="scroll-content">
                <div class="scroll-inner">
                    <div>I have chest pain.</div>
                    <div>I've been vomiting.</div>
                    <div>I'm feeling a lot of tiredness.</div>
                    <div>I'm experiencing nausea.</div>
                    <div>I have diarrhea.</div>
                    <div>I've developed a rash.</div>
                    <div>I have a headache.</div>
                    <div>I'm experiencing muscle pain.</div>
                    <div>I have a fever.</div>
                    <div>I'm feeling short of breath.</div>
                    <div>I have joint pain.</div>
                    <div>I have a sore throat.</div>
                    <div>I have a cough.</div>
                </div>
            </div>
        </div>
    </div>
    <style>
        .scroll-wrapper {
          height: 50px;
          overflow: hidden;
          position: relative;
        }
        .scroll-content {
          height: auto;
          width: 100%;
          position: absolute;
          animation: scroll-vertical 40s linear infinite;
          will-change: transform;
        }
        .scroll-inner {
          display: flex;
          flex-direction: column;
          gap: 20px;
          color: #bbbbbb;
          font-size: 13.8px;
          line-height: 1.5;
        }
        @keyframes scroll-vertical {
          0% {
            transform: translateY(0);
          }
          100% {
            transform: translateY(-60%);
          }
        }
    </style>
    """, elem_classes="centered-text")