Spaces:
Build error
Build error
lyangas
commited on
Commit
·
117020a
1
Parent(s):
cbbf9d1
add diagnostic group prediction
Browse files
app.py
CHANGED
@@ -6,21 +6,32 @@ from required_classes import *
|
|
6 |
|
7 |
print('INFO: loading model')
|
8 |
try:
|
9 |
-
with open('
|
10 |
model = pickle.load(f)
|
11 |
model.batch_size = 1
|
12 |
print('INFO: model loaded')
|
13 |
except Exception as e:
|
14 |
-
print(f"ERROR: loading
|
15 |
|
16 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
embed = model._texts2vecs([text])
|
18 |
-
probs = model.
|
19 |
best_n = np.flip(np.argsort(probs, axis=1,)[0,-3:])
|
20 |
-
preds = [f"{model.
|
21 |
output_text = '\n'.join(preds)
|
22 |
return output_text
|
23 |
|
|
|
|
|
|
|
24 |
print('INFO: starting gradio interface')
|
25 |
default_input_text = """Microscopic Evaluation: The specimen is excised into the reticular dermis and demonstrates skin with prominent papillomatosis and hyperkeratosis. The keratinocytes show reactive changes with nuclear enlargement and increased amounts of cytoplasm but no dysplasia is identified. Lymphocytic inflammation is distributed through the base of the lesion. Some pigmentation is present. The lesion approximates the edges of the specimen but appears to be predominantly excised. (GMW/jc) Gross Description: Shave removal and destruction erythematous tender papule with hyperkeratotic scale SCC vs BCC D.. Right medial temple. Final Diagnosis: Pigmented seborrheic keratosis inflamed."""
|
26 |
iface = gr.Interface(
|
|
|
6 |
|
7 |
print('INFO: loading model')
|
8 |
try:
|
9 |
+
with open('model_ds_71k_groups_31052023-3.pkl', 'rb') as f:
|
10 |
model = pickle.load(f)
|
11 |
model.batch_size = 1
|
12 |
print('INFO: model loaded')
|
13 |
except Exception as e:
|
14 |
+
print(f"ERROR: loading models failed with: {str(e)}")
|
15 |
|
16 |
+
def classify_code(text):
|
17 |
+
embed = model._texts2vecs([text])
|
18 |
+
probs = model.classifier_code.predict_proba(embed)
|
19 |
+
best_n = np.flip(np.argsort(probs, axis=1,)[0,-3:])
|
20 |
+
preds = [f"{model.classifier_code.classes_[i]} - {probs[0][i]*100:.1f}%" for i in best_n]
|
21 |
+
output_text = '\n'.join(preds)
|
22 |
+
return output_text
|
23 |
+
|
24 |
+
def classify_group(text):
|
25 |
embed = model._texts2vecs([text])
|
26 |
+
probs = model.classifier_group.predict_proba(embed)
|
27 |
best_n = np.flip(np.argsort(probs, axis=1,)[0,-3:])
|
28 |
+
preds = [f"{model.classifier_group.classes_[i]} - {probs[0][i]*100:.1f}%" for i in best_n]
|
29 |
output_text = '\n'.join(preds)
|
30 |
return output_text
|
31 |
|
32 |
+
def classify(text):
|
33 |
+
return f"Diagnostic code:\n{classify_code(text)}\n\nDiagnostic group:\n{classify_group(text)}"
|
34 |
+
|
35 |
print('INFO: starting gradio interface')
|
36 |
default_input_text = """Microscopic Evaluation: The specimen is excised into the reticular dermis and demonstrates skin with prominent papillomatosis and hyperkeratosis. The keratinocytes show reactive changes with nuclear enlargement and increased amounts of cytoplasm but no dysplasia is identified. Lymphocytic inflammation is distributed through the base of the lesion. Some pigmentation is present. The lesion approximates the edges of the specimen but appears to be predominantly excised. (GMW/jc) Gross Description: Shave removal and destruction erythematous tender papule with hyperkeratotic scale SCC vs BCC D.. Right medial temple. Final Diagnosis: Pigmented seborrheic keratosis inflamed."""
|
37 |
iface = gr.Interface(
|
pretrain_logistic_regression_model.pkl → model_ds_71k_groups_31052023-3.pkl
RENAMED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:90754acb6eb8f265d84fe451b2c21aa3368c355961b8149e9cbaa6f07ef7ccb6
|
3 |
+
size 434857173
|