ashishkgpian commited on
Commit
a9de279
·
verified ·
1 Parent(s): 36507f0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -13
app.py CHANGED
@@ -1,5 +1,7 @@
1
  import gradio as gr
2
  from transformers import pipeline
 
 
3
 
4
  # Load the model
5
  classifier = pipeline(
@@ -7,26 +9,34 @@ classifier = pipeline(
7
  model="ashishkgpian/biobert_icd9_classifier_ehr"
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
- # Enhanced CSS with better color contrast and readability
24
  custom_css = """
25
  .gradio-container {
26
  max-width: 1200px !important;
27
  margin: auto !important;
28
  padding: 2rem !important;
29
- background-color: #f0f4f7 !important;
30
  }
31
  .main-container {
32
  text-align: center;
@@ -37,12 +47,12 @@ custom_css = """
37
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
38
  }
39
  h1 {
40
- color: #2c3e50 !important;
41
  font-size: 2.5rem !important;
42
  margin-bottom: 0.5rem !important;
43
  }
44
  h3 {
45
- color: #34495e !important;
46
  font-size: 1.2rem !important;
47
  font-weight: normal !important;
48
  }
@@ -55,15 +65,15 @@ h3 {
55
  }
56
  textarea {
57
  background: white !important;
58
- color: #2c3e50 !important;
59
- border: 2px solid #3498db !important;
60
  border-radius: 8px !important;
61
  padding: 1rem !important;
62
  font-size: 1.1rem !important;
63
  min-height: 120px !important;
64
  }
65
  .submit-btn {
66
- background-color: #2ecc71 !important;
67
  color: white !important;
68
  padding: 0.8rem 2rem !important;
69
  border-radius: 8px !important;
@@ -72,7 +82,7 @@ textarea {
72
  transition: background-color 0.3s ease !important;
73
  }
74
  .submit-btn:hover {
75
- background-color: #27ae60 !important;
76
  }
77
  .output-container {
78
  background: white !important;
@@ -82,7 +92,7 @@ textarea {
82
  }
83
  .output-container pre {
84
  background: #f8f9fa !important;
85
- color: #2c3e50 !important;
86
  border-radius: 8px !important;
87
  padding: 1rem !important;
88
  }
@@ -93,6 +103,9 @@ textarea {
93
  margin-top: 1rem !important;
94
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1) !important;
95
  }
 
 
 
96
  .footer {
97
  text-align: center;
98
  margin-top: 2rem;
@@ -100,7 +113,7 @@ textarea {
100
  background: white;
101
  border-radius: 10px;
102
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
103
- color: #2c3e50;
104
  }
105
  """
106
 
@@ -124,7 +137,7 @@ with gr.Blocks(css=custom_css) as demo:
124
 
125
  with gr.Row(elem_classes=["output-container"]):
126
  output = gr.JSON(
127
- label="Suggested ICD9 Diagnostic Codes"
128
  )
129
 
130
  with gr.Row(elem_classes=["examples-container"]):
@@ -136,7 +149,8 @@ with gr.Blocks(css=custom_css) as demo:
136
  ["Elderly patient with chronic knee pain, reduced mobility, and signs of inflammation"]
137
  ],
138
  inputs=input_text,
139
- label="Example Clinical Cases"
 
140
  )
141
 
142
  submit_btn.click(fn=classify_symptoms, inputs=input_text, outputs=output)
 
1
  import gradio as gr
2
  from transformers import pipeline
3
+ import pandas as pd
4
+ import os
5
 
6
  # Load the model
7
  classifier = pipeline(
 
9
  model="ashishkgpian/biobert_icd9_classifier_ehr"
10
  )
11
 
12
+ # Load ICD9 codes data
13
+ icd9_data = pd.read_csv('')
14
+
15
  def classify_symptoms(text):
16
  try:
17
  results = classifier(text, top_k=5)
18
  formatted_results = []
19
  for result in results:
20
+ code = result['label']
21
+ # Look up additional information
22
+ code_info = icd9_data[icd9_data['ICD9_CODE'] == code]
23
  formatted_results.append({
24
+ "ICD9 Code": code,
25
+ "Short Title": code_info['SHORT_TITLE'].iloc[0] if not code_info.empty else "N/A",
26
+ "Long Title": code_info['LONG_TITLE'].iloc[0] if not code_info.empty else "N/A",
27
  "Confidence": f"{result['score']:.2%}"
28
  })
29
  return formatted_results
30
  except Exception as e:
31
  return f"Error processing classification: {str(e)}"
32
 
33
+ # Enhanced CSS with violet theme and better text contrast
34
  custom_css = """
35
  .gradio-container {
36
  max-width: 1200px !important;
37
  margin: auto !important;
38
  padding: 2rem !important;
39
+ background-color: #f5f3f7 !important;
40
  }
41
  .main-container {
42
  text-align: center;
 
47
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
48
  }
49
  h1 {
50
+ color: #4a148c !important;
51
  font-size: 2.5rem !important;
52
  margin-bottom: 0.5rem !important;
53
  }
54
  h3 {
55
+ color: #6a1b9a !important;
56
  font-size: 1.2rem !important;
57
  font-weight: normal !important;
58
  }
 
65
  }
66
  textarea {
67
  background: white !important;
68
+ color: #000000 !important;
69
+ border: 2px solid #7b1fa2 !important;
70
  border-radius: 8px !important;
71
  padding: 1rem !important;
72
  font-size: 1.1rem !important;
73
  min-height: 120px !important;
74
  }
75
  .submit-btn {
76
+ background-color: #6a1b9a !important;
77
  color: white !important;
78
  padding: 0.8rem 2rem !important;
79
  border-radius: 8px !important;
 
82
  transition: background-color 0.3s ease !important;
83
  }
84
  .submit-btn:hover {
85
+ background-color: #4a148c !important;
86
  }
87
  .output-container {
88
  background: white !important;
 
92
  }
93
  .output-container pre {
94
  background: #f8f9fa !important;
95
+ color: #000000 !important;
96
  border-radius: 8px !important;
97
  padding: 1rem !important;
98
  }
 
103
  margin-top: 1rem !important;
104
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1) !important;
105
  }
106
+ .example-text {
107
+ color: #000000 !important;
108
+ }
109
  .footer {
110
  text-align: center;
111
  margin-top: 2rem;
 
113
  background: white;
114
  border-radius: 10px;
115
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
116
+ color: #4a148c;
117
  }
118
  """
119
 
 
137
 
138
  with gr.Row(elem_classes=["output-container"]):
139
  output = gr.JSON(
140
+ label="Suggested ICD9 Diagnostic Codes with Descriptions"
141
  )
142
 
143
  with gr.Row(elem_classes=["examples-container"]):
 
149
  ["Elderly patient with chronic knee pain, reduced mobility, and signs of inflammation"]
150
  ],
151
  inputs=input_text,
152
+ label="Example Clinical Cases",
153
+ elem_classes=["example-text"]
154
  )
155
 
156
  submit_btn.click(fn=classify_symptoms, inputs=input_text, outputs=output)