ashishkgpian commited on
Commit
4a02f51
·
verified ·
1 Parent(s): a455fe1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -102
app.py CHANGED
@@ -1,51 +1,3 @@
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(
8
- "text-classification",
9
- model="ashishkgpian/biobert_icd9_classifier_ehr"
10
- )
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])
20
- test_df.loc[
21
- test_df['ICD9_CODE'].str.startswith("E"), 'ICD9_CODE'] = test_df.ICD9_CODE.apply(
22
- lambda x: x[:4])
23
- test_df.loc[(~test_df.ICD9_CODE.str.startswith("E")) & (
24
- ~test_df.ICD9_CODE.str.startswith("V")), 'ICD9_CODE'] = test_df.ICD9_CODE.apply(
25
- lambda x: x[:3])
26
- return test_df
27
-
28
- icd9_data = preprocessing(icd9_data)
29
-
30
- def classify_symptoms(text):
31
- try:
32
- results = classifier(text, top_k=5)
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,
39
- "Short Title": code_info['SHORT_TITLE'].iloc[0] if not code_info.empty else "N/A",
40
- "Long Title": code_info['LONG_TITLE'].iloc[0] if not code_info.empty else "N/A",
41
- "Confidence": f"{result['score']:.2%}"
42
- })
43
- return formatted_results
44
- except Exception as e:
45
- return f"Error processing classification: {str(e)}"
46
-
47
- # Enhanced CSS with white background and black text
48
-
49
  custom_css = """
50
  .gradio-container {
51
  width: 100% !important;
@@ -75,95 +27,89 @@ custom_css = """
75
  background: #000000;
76
  color: #ffffff;
77
  }
78
- h1 {
79
- color: #b388ff !important;
80
- font-size: 3rem !important;
81
- margin-bottom: 0.5rem !important;
82
- font-weight: 700 !important;
83
- }
84
- h3 {
85
- color: #9575cd !important;
86
- font-size: 1.4rem !important;
87
- font-weight: 500 !important;
88
- margin-bottom: 2rem !important;
89
- }
90
  .input-output-row {
91
  display: flex !important;
92
  gap: 2rem !important;
93
  margin: 2rem 0 !important;
94
  }
95
  .input-container {
96
- background: #121212 !important;
97
- padding: 2rem !important;
98
  border-radius: 12px !important;
99
- box-shadow: 0 4px 6px rgba(255, 255, 255, 0.05) !important;
100
  width: 50% !important;
101
- border: 1px solid #333333 !important;
102
  flex: 1 !important;
 
 
 
 
 
 
 
 
 
 
 
103
  }
104
  .input-container label {
105
  color: #ffffff !important;
106
- font-weight: 600 !important;
107
- font-size: 1.1rem !important;
108
  margin-bottom: 0.5rem !important;
109
  background: transparent !important;
110
  }
111
  textarea {
112
- background: #1e1e1e !important;
113
  color: #ffffff !important;
114
- border: 2px solid #673ab7 !important;
115
  border-radius: 8px !important;
116
  padding: 1rem !important;
117
- font-size: 1.2rem !important;
118
- min-height: 150px !important;
119
  width: 100% !important;
 
120
  }
121
  .submit-btn {
122
- background-color: #673ab7 !important;
123
  color: white !important;
124
- padding: 1rem 3rem !important;
125
  border-radius: 8px !important;
126
- font-size: 1.2rem !important;
127
- margin-top: 1.5rem !important;
128
  transition: all 0.3s ease !important;
129
- width: auto !important;
130
- font-weight: 600 !important;
131
  border: none !important;
132
  }
133
  .submit-btn:hover {
134
- background-color: #5e35b1 !important;
135
  }
136
  .output-container {
137
- background: #121212 !important;
138
- padding: 2rem !important;
139
  border-radius: 12px !important;
140
- box-shadow: 0 4px 6px rgba(255, 255, 255, 0.05) !important;
141
  width: 50% !important;
142
- border: 1px solid #333333 !important;
143
- color: #ffffff !important;
144
  flex: 1 !important;
 
145
  }
146
  .output-container label {
147
  color: #ffffff !important;
148
- font-weight: 600 !important;
149
- font-size: 1.1rem !important;
150
  margin-bottom: 1rem !important;
151
  background: transparent !important;
152
  }
153
  .examples-container {
154
- background: #121212 !important;
155
- padding: 2rem !important;
156
  border-radius: 12px !important;
157
  margin: 2rem 0 !important;
158
- box-shadow: 0 4px 6px rgba(255, 255, 255, 0.05) !important;
159
  width: 100% !important;
160
- border: 1px solid #333333 !important;
161
  color: #ffffff !important;
162
  }
163
  .examples-container label {
164
  color: #ffffff !important;
165
- font-weight: 600 !important;
166
- font-size: 1.1rem !important;
167
  background: transparent !important;
168
  }
169
  .footer {
@@ -180,20 +126,15 @@ textarea {
180
  with gr.Blocks(css=custom_css) as demo:
181
  with gr.Row(elem_classes=["main-container"]):
182
  with gr.Column(elem_classes=["content-wrapper"]):
183
- gr.Markdown(
184
- """
185
- # 🏥 Clinical Symptom ICD9 Classifier
186
- ### AI-Powered Medical Diagnosis Code Suggestion Tool
187
- """
188
- )
189
-
190
  with gr.Row(elem_classes=["input-output-row"]):
191
  with gr.Column(elem_classes=["input-container"]):
192
- input_text = gr.Textbox(
193
- label="Clinical Symptom Description",
194
- placeholder="Enter detailed patient symptoms and clinical observations...",
195
- lines=5
196
- )
 
 
197
  submit_btn = gr.Button("Analyze Symptoms", elem_classes=["submit-btn"])
198
 
199
  with gr.Column(elem_classes=["output-container"]):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  custom_css = """
2
  .gradio-container {
3
  width: 100% !important;
 
27
  background: #000000;
28
  color: #ffffff;
29
  }
 
 
 
 
 
 
 
 
 
 
 
 
30
  .input-output-row {
31
  display: flex !important;
32
  gap: 2rem !important;
33
  margin: 2rem 0 !important;
34
  }
35
  .input-container {
36
+ background: #1a1a1a !important;
37
+ padding: 1.5rem !important;
38
  border-radius: 12px !important;
 
39
  width: 50% !important;
 
40
  flex: 1 !important;
41
+ display: flex !important;
42
+ flex-direction: column !important;
43
+ gap: 1rem !important;
44
+ }
45
+ .inner-input-container {
46
+ background: #262626 !important;
47
+ padding: 1.5rem !important;
48
+ border-radius: 8px !important;
49
+ display: flex !important;
50
+ flex-direction: column !important;
51
+ gap: 1rem !important;
52
  }
53
  .input-container label {
54
  color: #ffffff !important;
55
+ font-weight: 500 !important;
56
+ font-size: 1rem !important;
57
  margin-bottom: 0.5rem !important;
58
  background: transparent !important;
59
  }
60
  textarea {
61
+ background: #262626 !important;
62
  color: #ffffff !important;
63
+ border: 2px solid #7c4dff !important;
64
  border-radius: 8px !important;
65
  padding: 1rem !important;
66
+ font-size: 1rem !important;
67
+ min-height: 120px !important;
68
  width: 100% !important;
69
+ resize: none !important;
70
  }
71
  .submit-btn {
72
+ background-color: #7c4dff !important;
73
  color: white !important;
74
+ padding: 0.75rem !important;
75
  border-radius: 8px !important;
76
+ font-size: 1rem !important;
77
+ margin-top: 0.5rem !important;
78
  transition: all 0.3s ease !important;
79
+ width: 100% !important;
80
+ font-weight: 500 !important;
81
  border: none !important;
82
  }
83
  .submit-btn:hover {
84
+ background-color: #6c3fff !important;
85
  }
86
  .output-container {
87
+ background: #1a1a1a !important;
88
+ padding: 1.5rem !important;
89
  border-radius: 12px !important;
 
90
  width: 50% !important;
 
 
91
  flex: 1 !important;
92
+ color: #ffffff !important;
93
  }
94
  .output-container label {
95
  color: #ffffff !important;
96
+ font-weight: 500 !important;
97
+ font-size: 1rem !important;
98
  margin-bottom: 1rem !important;
99
  background: transparent !important;
100
  }
101
  .examples-container {
102
+ background: #1a1a1a !important;
103
+ padding: 1.5rem !important;
104
  border-radius: 12px !important;
105
  margin: 2rem 0 !important;
 
106
  width: 100% !important;
 
107
  color: #ffffff !important;
108
  }
109
  .examples-container label {
110
  color: #ffffff !important;
111
+ font-weight: 500 !important;
112
+ font-size: 1rem !important;
113
  background: transparent !important;
114
  }
115
  .footer {
 
126
  with gr.Blocks(css=custom_css) as demo:
127
  with gr.Row(elem_classes=["main-container"]):
128
  with gr.Column(elem_classes=["content-wrapper"]):
 
 
 
 
 
 
 
129
  with gr.Row(elem_classes=["input-output-row"]):
130
  with gr.Column(elem_classes=["input-container"]):
131
+ gr.Markdown("Clinical Symptom Description")
132
+ with gr.Column(elem_classes=["inner-input-container"]):
133
+ input_text = gr.Textbox(
134
+ show_label=False,
135
+ placeholder="Enter detailed patient symptoms and clinical observations...",
136
+ lines=5
137
+ )
138
  submit_btn = gr.Button("Analyze Symptoms", elem_classes=["submit-btn"])
139
 
140
  with gr.Column(elem_classes=["output-container"]):