Spaces:
Sleeping
Sleeping
Download app.py from ananthakrishnan171/Skin_Cancer_CNN: direct link, hf CLI and curl.
- Browser
- Download file 1.13 kB
-
https://huggingface.co/spaces/ananthakrishnan171/Skin_Cancer_CNN/resolve/main/app.py
- Command line
-
hf download hf://spaces/ananthakrishnan171/Skin_Cancer_CNN/app.py
-
curl -L -o app.py https://huggingface.co/spaces/ananthakrishnan171/Skin_Cancer_CNN/resolve/main/app.py
1.13 kB
| import gradio as gr | |
| import tensorflow as tf | |
| import numpy as np | |
| from PIL import Image | |
| # Load the trained model | |
| model = tf.keras.models.load_model('Skin Cancer.h5') | |
| # Preprocess function to prepare image for model | |
| def preprocess_image(img): | |
| img = img.resize((224, 224)) # Resize as per model input | |
| img = np.array(img) / 255.0 # Normalize | |
| img = np.expand_dims(img, axis=0) | |
| return img | |
| # Prediction function | |
| def predict(image): | |
| img = preprocess_image(image) | |
| prediction = model.predict(img)[0][0] | |
| if prediction > 0.5: | |
| result = "Cancer Detected ❌" | |
| confidence = f"Confidence: {prediction*100:.2f}%" | |
| else: | |
| result = "No Cancer ✅" | |
| confidence = f"Confidence: {(1 - prediction)*100:.2f}%" | |
| return result, confidence | |
| # Gradio UI | |
| iface = gr.Interface( | |
| fn=predict, | |
| inputs=gr.Image(type="pil", label="Upload Skin Image"), | |
| outputs=[gr.Text(label="Prediction"), gr.Text(label="Confidence")], | |
| title="Skin Cancer Detection App", | |
| description="Upload a skin image to detect whether it has cancer or not using CNN model." | |
| ) | |
| # Launch app | |
| iface.launch() | |