import gradio as gr import os from useful_functions import * import useful_functions from dotenv import load_dotenv load_dotenv() f_load_cancer_classifier() f_load_cnn_model() HF_TOKEN = os.getenv('HF_TOKEN') hf_writer = gr.HuggingFaceDatasetSaver(HF_TOKEN, "mole-dataset", private=True) def image_classifier(file_path, age, sex, localization): if age == 0: age = 40 if sex == "": sex = "unknown" if localization == "": localization = "unknown" # file_path = file_path if file_path is not None else file_path_webcam preds = f_predict_cnn_with_tta(file_path) label = f_predict_cancer(preds, age, sex, localization) return (dict(zip(useful_functions.lesion_model.dls.vocab, preds)), label) input_img = gr.Image(tool="editor", type="filepath", source="upload") # input_webcam = gr.Image(tool="editor", type="filepath", source="webcam") input_age = gr.Number(label="age (optionnel)") input_sex = gr.Dropdown(label="sex (optionnel)", choices=["male", "female"]) input_localization = gr.Dropdown(label="localization (optionnel)", choices=["abdomen", "back", "chest", "ear", "face", "foot", "genital", "hand", "lower extremity", "neck", "scalp", "trunk", "upper extremity"]) output_lesion = gr.Label(label="Lesion detected") output_malign = gr.Label(label="Classification") list_files_examples = os.listdir("examples") # examples = [[os.path.join("examples", file), 0, "", ""] for file in list_files_examples if file.endswith("jpg")] examples = [] examples.append([os.path.join("examples", "PXL_20221103_153018529.jpg"), 40, "female", "back"]) examples.append([os.path.join("examples", "PXL_20221103_153129579.jpg"), 40, "male", "neck"]) examples.append([os.path.join("examples", "PXL_20221103_153137616.jpg"), 40, "male", "neck"]) examples.append([os.path.join("examples", "PXL_20221103_153217034.jpg"), 40, "male", "back"]) examples.append([os.path.join("examples", "PXL_20221103_153256612.jpg"), 40, "male", "upper extremity"]) examples.append([os.path.join("examples", "ISIC_0025402.jpg"), 70, "male", "lower extremity"]) demo = gr.Interface(title="Skin mole analyzer", description=r"""This is a side project I have been working on to practice working with images. The purpose is to classify skin lesions (Based on kaggle dataset Skin Cancer MNIST: HAM10000). The framework used is FastAI/pytorch and the model used is a pre-trained cnn (resnet152). I added an extra layer to use age, sex, localization and output of resnet152 to classify the lesion as suspicious or not (randomForest model). The lesions detected are the following: