Spaces:
Sleeping
Sleeping
ashishkgpian
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -8,116 +8,87 @@ classifier = pipeline(
|
|
8 |
)
|
9 |
|
10 |
def classify_symptoms(text):
|
11 |
-
"""
|
12 |
-
Classify medical symptoms and return top ICD9 codes
|
13 |
-
|
14 |
-
Args:
|
15 |
-
text (str): Input medical symptom description
|
16 |
-
|
17 |
-
Returns:
|
18 |
-
dict: Top classification results with ICD9 codes and probabilities
|
19 |
-
"""
|
20 |
try:
|
21 |
-
# Get classification results
|
22 |
results = classifier(text, top_k=5)
|
23 |
-
|
24 |
-
# Format results for more readable output
|
25 |
formatted_results = []
|
26 |
for result in results:
|
27 |
formatted_results.append({
|
28 |
"ICD9 Code": result['label'],
|
29 |
"Confidence": f"{result['score']:.2%}"
|
30 |
})
|
31 |
-
|
32 |
return formatted_results
|
33 |
-
|
34 |
except Exception as e:
|
35 |
return f"Error processing classification: {str(e)}"
|
36 |
|
37 |
-
# Custom CSS
|
38 |
custom_css = """
|
39 |
-
/* Medical-inspired color palette and design */
|
40 |
.gradio-container {
|
41 |
-
background-color: #
|
42 |
-
font-family: 'Arial', 'Helvetica Neue', sans-serif;
|
43 |
}
|
44 |
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
padding: 15px;
|
52 |
}
|
53 |
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
border-left: 5px solid #2ecc71;
|
58 |
-
margin-bottom: 10px;
|
59 |
-
padding: 10px;
|
60 |
-
border-radius: 5px;
|
61 |
-
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
62 |
}
|
63 |
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
font-weight: bold;
|
69 |
}
|
70 |
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
color:
|
75 |
-
|
76 |
-
transition: all 0.3s ease;
|
77 |
-
}
|
78 |
-
|
79 |
-
.submit-button:hover {
|
80 |
-
background-color: #27ae60 !important;
|
81 |
-
transform: scale(1.05);
|
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 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
)
|
121 |
|
122 |
if __name__ == "__main__":
|
123 |
demo.launch()
|
|
|
8 |
)
|
9 |
|
10 |
def classify_symptoms(text):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
try:
|
|
|
12 |
results = classifier(text, top_k=5)
|
|
|
|
|
13 |
formatted_results = []
|
14 |
for result in results:
|
15 |
formatted_results.append({
|
16 |
"ICD9 Code": result['label'],
|
17 |
"Confidence": f"{result['score']:.2%}"
|
18 |
})
|
|
|
19 |
return formatted_results
|
|
|
20 |
except Exception as e:
|
21 |
return f"Error processing classification: {str(e)}"
|
22 |
|
23 |
+
# Custom CSS without theme dependencies
|
24 |
custom_css = """
|
|
|
25 |
.gradio-container {
|
26 |
+
background-color: #f8f9fa;
|
|
|
27 |
}
|
28 |
|
29 |
+
.contain {
|
30 |
+
background-color: white !important;
|
31 |
+
border-radius: 8px !important;
|
32 |
+
padding: 20px !important;
|
33 |
+
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1) !important;
|
34 |
+
margin-bottom: 20px !important;
|
|
|
35 |
}
|
36 |
|
37 |
+
.textbox {
|
38 |
+
border: 2px solid #4a90e2 !important;
|
39 |
+
border-radius: 6px !important;
|
|
|
|
|
|
|
|
|
|
|
40 |
}
|
41 |
|
42 |
+
.label {
|
43 |
+
color: #2c3e50 !important;
|
44 |
+
font-weight: bold !important;
|
45 |
+
font-size: 1.1em !important;
|
|
|
46 |
}
|
47 |
|
48 |
+
footer {
|
49 |
+
text-align: center;
|
50 |
+
padding: 20px;
|
51 |
+
color: #666;
|
52 |
+
font-size: 0.9em;
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
}
|
54 |
"""
|
55 |
|
56 |
+
with gr.Blocks(css=custom_css) as demo:
|
57 |
+
gr.Markdown(
|
58 |
+
"""
|
59 |
+
# MedAI: Clinical Symptom ICD9 Classifier
|
60 |
+
### AI-Powered Diagnostic Code Suggestion Tool
|
61 |
+
"""
|
62 |
+
)
|
63 |
+
|
64 |
+
with gr.Row():
|
65 |
+
with gr.Column():
|
66 |
+
input_text = gr.Textbox(
|
67 |
+
label="Patient Symptom Description",
|
68 |
+
placeholder="Enter detailed patient symptoms (e.g., 'Patient reports persistent chest pain radiating to left arm, accompanied by shortness of breath')",
|
69 |
+
lines=4
|
70 |
+
)
|
71 |
+
|
72 |
+
examples = gr.Examples(
|
73 |
+
examples=[
|
74 |
+
["45-year-old male experiencing severe chest pain, radiating to left arm, with shortness of breath and excessive sweating"],
|
75 |
+
["Persistent headache for 2 weeks, accompanied by dizziness and occasional blurred vision"],
|
76 |
+
["Diabetic patient reporting frequent urination, increased thirst, and unexplained weight loss"],
|
77 |
+
["Elderly patient with chronic knee pain, reduced mobility, and signs of inflammation"]
|
78 |
+
],
|
79 |
+
inputs=input_text
|
80 |
+
)
|
81 |
+
|
82 |
+
output = gr.JSON(label="Diagnostic Suggestions")
|
83 |
+
|
84 |
+
input_text.submit(fn=classify_symptoms, inputs=input_text, outputs=output)
|
85 |
+
|
86 |
+
gr.Markdown(
|
87 |
+
"""
|
88 |
+
---
|
89 |
+
**Disclaimer:** This is an AI-assisted diagnostic tool. Always consult with a healthcare professional for accurate diagnosis and treatment.
|
90 |
+
"""
|
91 |
+
)
|
92 |
|
93 |
if __name__ == "__main__":
|
94 |
demo.launch()
|