Spaces:
Sleeping
Sleeping
File size: 4,885 Bytes
973bffe a7ec3bd 973bffe 52cf31b 1948f3b 9bfcdc8 1948f3b 5aec74c 9bfcdc8 5aec74c 9bfcdc8 5aec74c 9bfcdc8 5aec74c 52cf31b 9bfcdc8 a0b81f5 9bfcdc8 1948f3b 52cf31b 9bfcdc8 1948f3b 52cf31b 9bfcdc8 a0b81f5 9bfcdc8 52cf31b 9bfcdc8 1948f3b a0b81f5 5aec74c 9bfcdc8 a0b81f5 9bfcdc8 5aec74c a0b81f5 52cf31b a0b81f5 5aec74c 9bfcdc8 5aec74c 9bfcdc8 5aec74c a0b81f5 52cf31b a0b81f5 9bfcdc8 973bffe |
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 |
import gradio as gr
from transformers import pipeline
# Load the model
classifier = pipeline(
"text-classification",
model="ashishkgpian/biobert_icd9_classifier_ehr"
)
def classify_symptoms(text):
try:
results = classifier(text, top_k=5)
formatted_results = []
for result in results:
formatted_results.append({
"ICD9 Code": result['label'],
"Confidence": f"{result['score']:.2%}"
})
return formatted_results
except Exception as e:
return f"Error processing classification: {str(e)}"
# Enhanced CSS with better color contrast and readability
custom_css = """
.gradio-container {
max-width: 1200px !important;
margin: auto !important;
padding: 2rem !important;
background-color: #f0f4f7 !important;
}
.main-container {
text-align: center;
padding: 1rem;
margin-bottom: 2rem;
background: #ffffff;
border-radius: 10px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}
h1 {
color: #2c3e50 !important;
font-size: 2.5rem !important;
margin-bottom: 0.5rem !important;
}
h3 {
color: #34495e !important;
font-size: 1.2rem !important;
font-weight: normal !important;
}
.input-container {
background: white !important;
padding: 2rem !important;
border-radius: 10px !important;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1) !important;
margin-bottom: 1.5rem !important;
}
textarea {
background: white !important;
color: #2c3e50 !important;
border: 2px solid #3498db !important;
border-radius: 8px !important;
padding: 1rem !important;
font-size: 1.1rem !important;
min-height: 120px !important;
}
.submit-btn {
background-color: #2ecc71 !important;
color: white !important;
padding: 0.8rem 2rem !important;
border-radius: 8px !important;
font-size: 1.1rem !important;
margin-top: 1rem !important;
transition: background-color 0.3s ease !important;
}
.submit-btn:hover {
background-color: #27ae60 !important;
}
.output-container {
background: white !important;
padding: 2rem !important;
border-radius: 10px !important;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1) !important;
}
.output-container pre {
background: #f8f9fa !important;
color: #2c3e50 !important;
border-radius: 8px !important;
padding: 1rem !important;
}
.examples-container {
background: white !important;
padding: 1.5rem !important;
border-radius: 10px !important;
margin-top: 1rem !important;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1) !important;
}
.footer {
text-align: center;
margin-top: 2rem;
padding: 1rem;
background: white;
border-radius: 10px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
color: #2c3e50;
}
"""
with gr.Blocks(css=custom_css) as demo:
with gr.Row(elem_classes=["main-container"]):
gr.Markdown(
"""
# 🏥 MedAI: Clinical Symptom ICD9 Classifier
### Advanced AI-Powered Diagnostic Code Assistant
"""
)
with gr.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.Row(elem_classes=["output-container"]):
output = gr.JSON(
label="Suggested ICD9 Diagnostic Codes"
)
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():
gr.Markdown(
"""
<div class="footer">
⚕️ <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.
</div>
""",
)
if __name__ == "__main__":
demo.launch() |