Spaces:
Build error
Build error
print('INFO: import modules') | |
import gradio as gr | |
import pickle | |
from required_classes import * | |
print('INFO: loading model') | |
try: | |
with open('pretrain_logistic_regression_model.pkl', 'rb') as f: | |
model = pickle.load(f) | |
model.batch_size = 1 | |
print('INFO: model loaded') | |
except Exception as e: | |
print(f"ERROR: loading model failed with: {str(e)}") | |
def classify(text): | |
embed = model._texts2vecs([text]) | |
probs = model.classifier.predict_proba(embed) | |
best_n = np.flip(np.argsort(probs, axis=1,)[0,-3:]) | |
preds = [f"{model.classifier.classes_[i]} - {probs[0][i]*100:.1f}%" for i in best_n] | |
output_text = '\n'.join(preds) | |
return output_text | |
print('INFO: starting gradio interface') | |
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.""" | |
iface = gr.Interface( | |
enable_queue=True, | |
title="ICD10-codes classification", | |
description="", | |
fn=classify, | |
inputs=[gr.Textbox(label="Input text", value=default_input_text)], | |
outputs=gr.outputs.Textbox(label="Result class"), | |
) | |
iface.launch() | |