| import tensorflow as tf |
| from huggingface_hub import snapshot_download |
| from keras.preprocessing import image |
| import numpy as np |
| import gradio as gr |
| from keras.layers import TFSMLayer |
|
|
| |
| local_model_path = snapshot_download("syaha/skin_cancer_detection_model") |
|
|
| |
| model = TFSMLayer(local_model_path, call_endpoint="serving_default") |
|
|
| |
| class_names = ['akiec', 'bcc', 'bkl', 'df', 'nv', 'vasc', 'mel'] |
|
|
| |
| def predict_skin_cancer(image_path): |
| |
| img = image.load_img(image_path, target_size=(224, 224)) |
| img_array = image.img_to_array(img) |
| img_array = np.expand_dims(img_array, axis=0) / 255.0 |
|
|
| |
| predictions = model.predict(img_array) |
| predicted_class = np.argmax(predictions, axis=1)[0] |
| predicted_label = class_names[predicted_class] |
|
|
| return f"Predicted class: {predicted_label}" |
|
|
| |
| iface = gr.Interface(fn=predict_skin_cancer, inputs=gr.Image(type="filepath"), outputs="text", live=True) |
|
|
| |
| iface.launch() |
|
|