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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -0
app.py CHANGED
@@ -1,3 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  custom_css = """
2
  .gradio-container {
3
  width: 100% !important;
 
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
  custom_css = """
48
  .gradio-container {
49
  width: 100% !important;