ashishkgpian commited on
Commit
5665b89
·
verified ·
1 Parent(s): 1cf2ced

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +75 -65
app.py CHANGED
@@ -11,11 +11,9 @@ classifier = pipeline(
11
 
12
  # Load ICD9 codes data
13
  icd9_data = pd.read_csv('D_ICD_DIAGNOSES.csv')
14
-
15
-
16
  icd9_data.columns = ['ROW_ID', 'ICD9_CODE', 'SHORT_TITLE', 'LONG_TITLE']
17
 
18
- def preprocessing(test_df) :
19
  test_df.loc[
20
  test_df['ICD9_CODE'].str.startswith("V"), 'ICD9_CODE'] = test_df.ICD9_CODE.apply(
21
  lambda x: x[:4])
@@ -27,7 +25,6 @@ def preprocessing(test_df) :
27
  lambda x: x[:3])
28
  return test_df
29
 
30
-
31
  icd9_data = preprocessing(icd9_data)
32
 
33
  def classify_symptoms(text):
@@ -36,7 +33,6 @@ def classify_symptoms(text):
36
  formatted_results = []
37
  for result in results:
38
  code = result['label']
39
- # Look up additional information
40
  code_info = icd9_data[icd9_data['ICD9_CODE'] == code]
41
  formatted_results.append({
42
  "ICD9 Code": code,
@@ -48,30 +44,41 @@ def classify_symptoms(text):
48
  except Exception as e:
49
  return f"Error processing classification: {str(e)}"
50
 
51
- # Enhanced CSS with violet theme and better text contrast
52
  custom_css = """
53
  .gradio-container {
54
- max-width: 1200px !important;
55
- margin: auto !important;
56
- padding: 2rem !important;
 
 
 
 
57
  background-color: #f5f3f7 !important;
58
  }
59
  .main-container {
60
  text-align: center;
61
- padding: 1rem;
62
- margin-bottom: 2rem;
63
  background: #ffffff;
64
- border-radius: 10px;
65
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
 
 
 
 
 
 
 
 
66
  }
67
  h1 {
68
  color: #4a148c !important;
69
- font-size: 2.5rem !important;
70
  margin-bottom: 0.5rem !important;
71
  }
72
  h3 {
73
  color: #6a1b9a !important;
74
- font-size: 1.2rem !important;
75
  font-weight: normal !important;
76
  }
77
  .input-container {
@@ -79,7 +86,8 @@ h3 {
79
  padding: 2rem !important;
80
  border-radius: 10px !important;
81
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1) !important;
82
- margin-bottom: 1.5rem !important;
 
83
  }
84
  textarea {
85
  background: white !important;
@@ -87,17 +95,19 @@ textarea {
87
  border: 2px solid #7b1fa2 !important;
88
  border-radius: 8px !important;
89
  padding: 1rem !important;
90
- font-size: 1.1rem !important;
91
- min-height: 120px !important;
 
92
  }
93
  .submit-btn {
94
  background-color: #6a1b9a !important;
95
  color: white !important;
96
- padding: 0.8rem 2rem !important;
97
  border-radius: 8px !important;
98
- font-size: 1.1rem !important;
99
- margin-top: 1rem !important;
100
  transition: background-color 0.3s ease !important;
 
101
  }
102
  .submit-btn:hover {
103
  background-color: #4a148c !important;
@@ -107,81 +117,81 @@ textarea {
107
  padding: 2rem !important;
108
  border-radius: 10px !important;
109
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1) !important;
 
 
110
  }
111
  .output-container pre {
112
  background: #f8f9fa !important;
113
  color: #000000 !important;
114
  border-radius: 8px !important;
115
- padding: 1rem !important;
 
116
  }
117
  .examples-container {
118
  background: white !important;
119
- padding: 1.5rem !important;
120
  border-radius: 10px !important;
121
- margin-top: 1rem !important;
122
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1) !important;
123
- }
124
- .example-text {
125
- color: #000000 !important;
126
  }
127
  .footer {
128
  text-align: center;
129
- margin-top: 2rem;
130
- padding: 1rem;
131
  background: white;
132
- border-radius: 10px;
133
- box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
 
134
  color: #4a148c;
135
  }
136
  """
137
 
138
  with gr.Blocks(css=custom_css) as demo:
139
  with gr.Row(elem_classes=["main-container"]):
140
- gr.Markdown(
141
- """
142
- # 🏥 Clinical Symptom ICD9 Classifier
143
-
144
- """
145
- )
146
-
147
- with gr.Row():
148
- with gr.Column(elem_classes=["input-container"]):
149
- input_text = gr.Textbox(
150
- label="Clinical Symptom Description",
151
- placeholder="Enter detailed patient symptoms and clinical observations...",
152
- lines=5
153
  )
154
- submit_btn = gr.Button("Analyze Symptoms", elem_classes=["submit-btn"])
155
-
156
- with gr.Row(elem_classes=["output-container"]):
157
- output = gr.JSON(
158
- label="Suggested ICD9 Diagnostic Codes with Descriptions"
159
- )
160
 
161
- with gr.Row(elem_classes=["examples-container"]):
162
- examples = gr.Examples(
163
- examples=[
164
- ["45-year-old male experiencing severe chest pain, radiating to left arm, with shortness of breath and excessive sweating"],
165
- ["Persistent headache for 2 weeks, accompanied by dizziness and occasional blurred vision"],
166
- ["Diabetic patient reporting frequent urination, increased thirst, and unexplained weight loss"],
167
- ["Elderly patient with chronic knee pain, reduced mobility, and signs of inflammation"]
168
- ],
169
- inputs=input_text,
170
- label="Example Clinical Cases"
171
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
172
 
173
  submit_btn.click(fn=classify_symptoms, inputs=input_text, outputs=output)
174
  input_text.submit(fn=classify_symptoms, inputs=input_text, outputs=output)
175
 
176
- with gr.Row():
177
  gr.Markdown(
178
  """
179
- <div class="footer">
180
  ⚕️ <strong>Medical Disclaimer:</strong> This AI tool is designed to assist medical professionals in ICD9 code classification.
181
  Always verify suggestions with clinical judgment and consult appropriate medical resources.
182
- </div>
183
- """,
184
  )
185
 
186
  if __name__ == "__main__":
187
- demo.launch()
 
11
 
12
  # Load ICD9 codes data
13
  icd9_data = pd.read_csv('D_ICD_DIAGNOSES.csv')
 
 
14
  icd9_data.columns = ['ROW_ID', 'ICD9_CODE', 'SHORT_TITLE', 'LONG_TITLE']
15
 
16
+ def preprocessing(test_df):
17
  test_df.loc[
18
  test_df['ICD9_CODE'].str.startswith("V"), 'ICD9_CODE'] = test_df.ICD9_CODE.apply(
19
  lambda x: x[:4])
 
25
  lambda x: x[:3])
26
  return test_df
27
 
 
28
  icd9_data = preprocessing(icd9_data)
29
 
30
  def classify_symptoms(text):
 
33
  formatted_results = []
34
  for result in results:
35
  code = result['label']
 
36
  code_info = icd9_data[icd9_data['ICD9_CODE'] == code]
37
  formatted_results.append({
38
  "ICD9 Code": code,
 
44
  except Exception as e:
45
  return f"Error processing classification: {str(e)}"
46
 
47
+ # Enhanced CSS with fullscreen layout and violet theme
48
  custom_css = """
49
  .gradio-container {
50
+ width: 100% !important;
51
+ max-width: 100% !important;
52
+ margin: 0 !important;
53
+ padding: 0 !important;
54
+ min-height: 100vh !important;
55
+ display: flex !important;
56
+ flex-direction: column !important;
57
  background-color: #f5f3f7 !important;
58
  }
59
  .main-container {
60
  text-align: center;
61
+ padding: 2rem;
62
+ margin: 0;
63
  background: #ffffff;
 
64
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
65
+ width: 100%;
66
+ }
67
+ .content-wrapper {
68
+ max-width: 1400px;
69
+ margin: 0 auto;
70
+ padding: 0 2rem;
71
+ width: 100%;
72
+ box-sizing: border-box;
73
  }
74
  h1 {
75
  color: #4a148c !important;
76
+ font-size: 3rem !important;
77
  margin-bottom: 0.5rem !important;
78
  }
79
  h3 {
80
  color: #6a1b9a !important;
81
+ font-size: 1.4rem !important;
82
  font-weight: normal !important;
83
  }
84
  .input-container {
 
86
  padding: 2rem !important;
87
  border-radius: 10px !important;
88
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1) !important;
89
+ margin: 2rem 0 !important;
90
+ width: 100% !important;
91
  }
92
  textarea {
93
  background: white !important;
 
95
  border: 2px solid #7b1fa2 !important;
96
  border-radius: 8px !important;
97
  padding: 1rem !important;
98
+ font-size: 1.2rem !important;
99
+ min-height: 150px !important;
100
+ width: 100% !important;
101
  }
102
  .submit-btn {
103
  background-color: #6a1b9a !important;
104
  color: white !important;
105
+ padding: 1rem 3rem !important;
106
  border-radius: 8px !important;
107
+ font-size: 1.2rem !important;
108
+ margin-top: 1.5rem !important;
109
  transition: background-color 0.3s ease !important;
110
+ width: auto !important;
111
  }
112
  .submit-btn:hover {
113
  background-color: #4a148c !important;
 
117
  padding: 2rem !important;
118
  border-radius: 10px !important;
119
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1) !important;
120
+ margin: 2rem 0 !important;
121
+ width: 100% !important;
122
  }
123
  .output-container pre {
124
  background: #f8f9fa !important;
125
  color: #000000 !important;
126
  border-radius: 8px !important;
127
+ padding: 1.5rem !important;
128
+ font-size: 1.1rem !important;
129
  }
130
  .examples-container {
131
  background: white !important;
132
+ padding: 2rem !important;
133
  border-radius: 10px !important;
134
+ margin: 2rem 0 !important;
135
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1) !important;
136
+ width: 100% !important;
 
 
137
  }
138
  .footer {
139
  text-align: center;
140
+ padding: 2rem;
 
141
  background: white;
142
+ margin-top: auto;
143
+ width: 100%;
144
+ box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.1);
145
  color: #4a148c;
146
  }
147
  """
148
 
149
  with gr.Blocks(css=custom_css) as demo:
150
  with gr.Row(elem_classes=["main-container"]):
151
+ with gr.Column(elem_classes=["content-wrapper"]):
152
+ gr.Markdown(
153
+ """
154
+ # 🏥 Clinical Symptom ICD9 Classifier
155
+ ### AI-Powered Medical Diagnosis Code Suggestion Tool
156
+ """
 
 
 
 
 
 
 
157
  )
 
 
 
 
 
 
158
 
159
+ with gr.Row():
160
+ with gr.Column(elem_classes=["input-container"]):
161
+ input_text = gr.Textbox(
162
+ label="Clinical Symptom Description",
163
+ placeholder="Enter detailed patient symptoms and clinical observations...",
164
+ lines=5
165
+ )
166
+ submit_btn = gr.Button("Analyze Symptoms", elem_classes=["submit-btn"])
167
+
168
+ with gr.Row(elem_classes=["output-container"]):
169
+ output = gr.JSON(
170
+ label="Suggested ICD9 Diagnostic Codes with Descriptions"
171
+ )
172
+
173
+ with gr.Row(elem_classes=["examples-container"]):
174
+ examples = gr.Examples(
175
+ examples=[
176
+ ["45-year-old male experiencing severe chest pain, radiating to left arm, with shortness of breath and excessive sweating"],
177
+ ["Persistent headache for 2 weeks, accompanied by dizziness and occasional blurred vision"],
178
+ ["Diabetic patient reporting frequent urination, increased thirst, and unexplained weight loss"],
179
+ ["Elderly patient with chronic knee pain, reduced mobility, and signs of inflammation"]
180
+ ],
181
+ inputs=input_text,
182
+ label="Example Clinical Cases"
183
+ )
184
 
185
  submit_btn.click(fn=classify_symptoms, inputs=input_text, outputs=output)
186
  input_text.submit(fn=classify_symptoms, inputs=input_text, outputs=output)
187
 
188
+ with gr.Row(elem_classes=["footer"]):
189
  gr.Markdown(
190
  """
 
191
  ⚕️ <strong>Medical Disclaimer:</strong> This AI tool is designed to assist medical professionals in ICD9 code classification.
192
  Always verify suggestions with clinical judgment and consult appropriate medical resources.
193
+ """
 
194
  )
195
 
196
  if __name__ == "__main__":
197
+ demo.launch(share=True)