Antonio Jesús Acosta López
commited on
Commit
·
aa55e08
1
Parent(s):
d3bf446
Primera versión a probar en el hosting de Hugging Face.
Browse files- 186.jpg +0 -0
- 2.jpg +0 -0
- 37.jpg +0 -0
- keras_model.h5 +3 -0
- nevus_ai.py +52 -0
186.jpg
ADDED
![]() |
2.jpg
ADDED
![]() |
37.jpg
ADDED
![]() |
keras_model.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:b540de92a7222f8b7a8794310ecc8daf96955200b5281d12c7ade8ebc4f69dcc
|
3 |
+
size 2453432
|
nevus_ai.py
ADDED
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Import dependencies
|
2 |
+
from keras.models import load_model
|
3 |
+
from PIL import Image, ImageOps
|
4 |
+
import numpy as np
|
5 |
+
import gradio as gr
|
6 |
+
|
7 |
+
|
8 |
+
# Definition of the main function for predictions
|
9 |
+
def predict_nevus(image):
|
10 |
+
# Load the model
|
11 |
+
model = load_model('keras_model.h5')
|
12 |
+
|
13 |
+
# Create the array of the right shape to feed into the keras model
|
14 |
+
# The 'length' or number of images you can put into the array is
|
15 |
+
# determined by the first position in the shape tuple, in this case 1.
|
16 |
+
data = np.ndarray(shape=(1, 224, 224, 3), dtype=np.float32)
|
17 |
+
|
18 |
+
#turn the image into a numpy array
|
19 |
+
image_array = np.asarray(image)
|
20 |
+
|
21 |
+
# Normalize the image
|
22 |
+
normalized_image_array = (image_array.astype(np.float32) / 127.0) - 1
|
23 |
+
|
24 |
+
# Load the image into the array
|
25 |
+
data[0] = normalized_image_array
|
26 |
+
|
27 |
+
# run the inference
|
28 |
+
prediction = model.predict(data)
|
29 |
+
return {
|
30 |
+
'Melanoma': float(prediction[0][0]),
|
31 |
+
'Lunar': float(prediction[0][1])
|
32 |
+
}
|
33 |
+
|
34 |
+
# Deploy with Gradio
|
35 |
+
examples=[
|
36 |
+
['2.jpg'],
|
37 |
+
['37.jpg'],
|
38 |
+
['186.jpg']
|
39 |
+
]
|
40 |
+
|
41 |
+
iface = gr.Interface(
|
42 |
+
fn=predict_nevus,
|
43 |
+
inputs=gr.inputs.Image(shape=(224, 224)),
|
44 |
+
outputs="label",
|
45 |
+
title="Detector de melanomas",
|
46 |
+
description="Herramienta online que utiliza inteligencia artificial para detectar posibles melanomas en fotografías de lunares.",
|
47 |
+
examples=examples,
|
48 |
+
allow_flagging='never',
|
49 |
+
theme="peach"
|
50 |
+
)
|
51 |
+
|
52 |
+
iface.launch(debug=True)
|