Spaces:
Sleeping
Sleeping
File size: 7,455 Bytes
973bffe a9de279 973bffe 5f82978 973bffe a9de279 dd25d29 4bd7a10 95c4177 5665b89 95c4177 4bd7a10 95c4177 4bd7a10 95c4177 4bd7a10 95c4177 973bffe a9de279 973bffe a9de279 973bffe 7e41ac7 a455fe1 1948f3b 5665b89 1ea454c 1948f3b 5aec74c 9bfcdc8 5665b89 1ea454c 5665b89 1ea454c 5665b89 1ea454c 9bfcdc8 5aec74c 1ea454c 5665b89 5aec74c 324b7a2 9bfcdc8 5aec74c 1ea454c 5665b89 324b7a2 9bfcdc8 a455fe1 9bfcdc8 1ea454c 9bfcdc8 324b7a2 1ea454c a455fe1 1ea454c a455fe1 324b7a2 1ea454c 324b7a2 1ea454c 9bfcdc8 5aec74c 1ea454c 324b7a2 a0b81f5 9bfcdc8 5665b89 1948f3b 52cf31b 324b7a2 52cf31b 5665b89 52cf31b 5665b89 324b7a2 5665b89 324b7a2 52cf31b 324b7a2 52cf31b 9bfcdc8 1ea454c 9bfcdc8 324b7a2 1ea454c a455fe1 1ea454c a455fe1 324b7a2 1ea454c 324b7a2 1ea454c 52cf31b 9bfcdc8 1ea454c 5665b89 324b7a2 5665b89 1ea454c 5665b89 1ea454c 324b7a2 1ea454c 324b7a2 1ea454c a9de279 9bfcdc8 a0b81f5 5665b89 1ea454c 5665b89 1ea454c 9bfcdc8 1948f3b a0b81f5 5aec74c 5665b89 a455fe1 5665b89 a0b81f5 9bfcdc8 a455fe1 5665b89 a455fe1 5665b89 a0b81f5 52cf31b a0b81f5 5665b89 9bfcdc8 5665b89 9bfcdc8 973bffe 5665b89 |
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 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
import gradio as gr
from transformers import pipeline
import pandas as pd
import os
# Load the model
classifier = pipeline(
"text-classification",
model="ashishkgpian/biobert_icd9_classifier_ehr"
)
# Load ICD9 codes data
icd9_data = pd.read_csv('D_ICD_DIAGNOSES.csv')
icd9_data.columns = ['ROW_ID', 'ICD9_CODE', 'SHORT_TITLE', 'LONG_TITLE']
def preprocessing(test_df):
test_df.loc[
test_df['ICD9_CODE'].str.startswith("V"), 'ICD9_CODE'] = test_df.ICD9_CODE.apply(
lambda x: x[:4])
test_df.loc[
test_df['ICD9_CODE'].str.startswith("E"), 'ICD9_CODE'] = test_df.ICD9_CODE.apply(
lambda x: x[:4])
test_df.loc[(~test_df.ICD9_CODE.str.startswith("E")) & (
~test_df.ICD9_CODE.str.startswith("V")), 'ICD9_CODE'] = test_df.ICD9_CODE.apply(
lambda x: x[:3])
return test_df
icd9_data = preprocessing(icd9_data)
def classify_symptoms(text):
try:
results = classifier(text, top_k=5)
formatted_results = []
for result in results:
code = result['label']
code_info = icd9_data[icd9_data['ICD9_CODE'] == code]
formatted_results.append({
"ICD9 Code": code,
"Short Title": code_info['SHORT_TITLE'].iloc[0] if not code_info.empty else "N/A",
"Long Title": code_info['LONG_TITLE'].iloc[0] if not code_info.empty else "N/A",
"Confidence": f"{result['score']:.2%}"
})
return formatted_results
except Exception as e:
return f"Error processing classification: {str(e)}"
# Enhanced CSS with white background and black text
custom_css = """
.gradio-container {
width: 100% !important;
max-width: 100% !important;
margin: 0 !important;
padding: 0 !important;
min-height: 100vh !important;
display: flex !important;
flex-direction: column !important;
background-color: #000000 !important;
color: #ffffff !important;
}
.main-container {
text-align: center;
padding: 2rem;
margin: 0;
background: #000000;
width: 100%;
color: #ffffff;
}
.content-wrapper {
max-width: 1400px;
margin: 0 auto;
padding: 0 2rem;
width: 100%;
box-sizing: border-box;
background: #000000;
color: #ffffff;
}
h1 {
color: #b388ff !important;
font-size: 3rem !important;
margin-bottom: 0.5rem !important;
font-weight: 700 !important;
}
h3 {
color: #9575cd !important;
font-size: 1.4rem !important;
font-weight: 500 !important;
margin-bottom: 2rem !important;
}
.input-output-row {
display: flex !important;
gap: 2rem !important;
margin: 2rem 0 !important;
}
.input-container {
background: #121212 !important;
padding: 2rem !important;
border-radius: 12px !important;
box-shadow: 0 4px 6px rgba(255, 255, 255, 0.05) !important;
width: 50% !important;
border: 1px solid #333333 !important;
flex: 1 !important;
}
.input-container label {
color: #ffffff !important;
font-weight: 600 !important;
font-size: 1.1rem !important;
margin-bottom: 0.5rem !important;
background: transparent !important;
}
textarea {
background: #1e1e1e !important;
color: #ffffff !important;
border: 2px solid #673ab7 !important;
border-radius: 8px !important;
padding: 1rem !important;
font-size: 1.2rem !important;
min-height: 150px !important;
width: 100% !important;
}
.submit-btn {
background-color: #673ab7 !important;
color: white !important;
padding: 1rem 3rem !important;
border-radius: 8px !important;
font-size: 1.2rem !important;
margin-top: 1.5rem !important;
transition: all 0.3s ease !important;
width: auto !important;
font-weight: 600 !important;
border: none !important;
}
.submit-btn:hover {
background-color: #5e35b1 !important;
}
.output-container {
background: #121212 !important;
padding: 2rem !important;
border-radius: 12px !important;
box-shadow: 0 4px 6px rgba(255, 255, 255, 0.05) !important;
width: 50% !important;
border: 1px solid #333333 !important;
color: #ffffff !important;
flex: 1 !important;
}
.output-container label {
color: #ffffff !important;
font-weight: 600 !important;
font-size: 1.1rem !important;
margin-bottom: 1rem !important;
background: transparent !important;
}
.examples-container {
background: #121212 !important;
padding: 2rem !important;
border-radius: 12px !important;
margin: 2rem 0 !important;
box-shadow: 0 4px 6px rgba(255, 255, 255, 0.05) !important;
width: 100% !important;
border: 1px solid #333333 !important;
color: #ffffff !important;
}
.examples-container label {
color: #ffffff !important;
font-weight: 600 !important;
font-size: 1.1rem !important;
background: transparent !important;
}
.footer {
text-align: center;
padding: 2rem;
background: #000000;
margin-top: auto;
width: 100%;
border-top: 1px solid #333333;
color: #ffffff;
}
"""
with gr.Blocks(css=custom_css) as demo:
with gr.Row(elem_classes=["main-container"]):
with gr.Column(elem_classes=["content-wrapper"]):
gr.Markdown(
"""
# 🏥 Clinical Symptom ICD9 Classifier
### AI-Powered Medical Diagnosis Code Suggestion Tool
"""
)
with gr.Row(elem_classes=["input-output-row"]):
with gr.Column(elem_classes=["input-container"]):
input_text = gr.Textbox(
label="Clinical Symptom Description",
placeholder="Enter detailed patient symptoms and clinical observations...",
lines=5
)
submit_btn = gr.Button("Analyze Symptoms", elem_classes=["submit-btn"])
with gr.Column(elem_classes=["output-container"]):
output = gr.JSON(
label="Suggested ICD9 Diagnostic Codes with Descriptions"
)
with gr.Row(elem_classes=["examples-container"]):
examples = gr.Examples(
examples=[
["45-year-old male experiencing severe chest pain, radiating to left arm, with shortness of breath and excessive sweating"],
["Persistent headache for 2 weeks, accompanied by dizziness and occasional blurred vision"],
["Diabetic patient reporting frequent urination, increased thirst, and unexplained weight loss"],
["Elderly patient with chronic knee pain, reduced mobility, and signs of inflammation"]
],
inputs=input_text,
label="Example Clinical Cases"
)
submit_btn.click(fn=classify_symptoms, inputs=input_text, outputs=output)
input_text.submit(fn=classify_symptoms, inputs=input_text, outputs=output)
with gr.Row(elem_classes=["footer"]):
gr.Markdown(
"""
⚕️ <strong>Medical Disclaimer:</strong> This AI tool is designed to assist medical professionals in ICD9 code classification.
Always verify suggestions with clinical judgment and consult appropriate medical resources.
"""
)
if __name__ == "__main__":
demo.launch(share=True) |