Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
import tensorflow as tf
|
3 |
import numpy as np
|
@@ -33,13 +80,16 @@ def classify_image(input_image):
|
|
33 |
class_labels = ["Normal", "Cataract"] # Substitua pelas suas etiquetas de classe reais
|
34 |
predicted_class = class_labels[class_index]
|
35 |
|
36 |
-
|
|
|
|
|
37 |
|
38 |
# Crie uma interface Gradio
|
39 |
input_interface = gr.Interface(
|
40 |
fn=classify_image,
|
41 |
inputs="image", # Especifique o tipo de entrada como "image"
|
42 |
-
outputs="text"
|
|
|
43 |
)
|
44 |
|
45 |
# Inicie o aplicativo Gradio
|
|
|
1 |
+
# import gradio as gr
|
2 |
+
# import tensorflow as tf
|
3 |
+
# import numpy as np
|
4 |
+
|
5 |
+
# # Defina a camada personalizada FixedDropout
|
6 |
+
# class FixedDropout(tf.keras.layers.Dropout):
|
7 |
+
# def _get_noise_shape(self, inputs):
|
8 |
+
# if self.noise_shape is None:
|
9 |
+
# return self.noise_shape
|
10 |
+
# symbolic_shape = tf.shape(inputs)
|
11 |
+
# noise_shape = [symbolic_shape[axis] if shape is None else shape
|
12 |
+
# for axis, shape in enumerate(self.noise_shape)]
|
13 |
+
# return tuple(noise_shape)
|
14 |
+
|
15 |
+
# # Registre a camada personalizada FixedDropout
|
16 |
+
# tf.keras.utils.get_custom_objects()['FixedDropout'] = FixedDropout
|
17 |
+
|
18 |
+
# # Carregue seu modelo TensorFlow treinado
|
19 |
+
# model = tf.keras.models.load_model('modelo_treinado.h5')
|
20 |
+
|
21 |
+
# # Defina uma função para fazer previsões
|
22 |
+
# def classify_image(input_image):
|
23 |
+
# # Redimensione a imagem para as dimensões corretas (192x256)
|
24 |
+
# input_image = tf.image.resize(input_image, (192, 256)) # Redimensione para as dimensões esperadas
|
25 |
+
# input_image = (input_image / 255.0) # Normalize para [0, 1]
|
26 |
+
# input_image = np.expand_dims(input_image, axis=0) # Adicione a dimensão de lote
|
27 |
+
|
28 |
+
# # Faça a previsão usando o modelo
|
29 |
+
# prediction = model.predict(input_image)
|
30 |
+
|
31 |
+
# # Assumindo que o modelo retorna probabilidades para duas classes, você pode retornar a classe com a maior probabilidade
|
32 |
+
# class_index = np.argmax(prediction)
|
33 |
+
# class_labels = ["Normal", "Cataract"] # Substitua pelas suas etiquetas de classe reais
|
34 |
+
# predicted_class = class_labels[class_index]
|
35 |
+
|
36 |
+
# return predicted_class
|
37 |
+
|
38 |
+
# # Crie uma interface Gradio
|
39 |
+
# input_interface = gr.Interface(
|
40 |
+
# fn=classify_image,
|
41 |
+
# inputs="image", # Especifique o tipo de entrada como "image"
|
42 |
+
# outputs="text" # Especifique o tipo de saída como "text"
|
43 |
+
# )
|
44 |
+
|
45 |
+
# # Inicie o aplicativo Gradio
|
46 |
+
# input_interface.launch()
|
47 |
+
|
48 |
import gradio as gr
|
49 |
import tensorflow as tf
|
50 |
import numpy as np
|
|
|
80 |
class_labels = ["Normal", "Cataract"] # Substitua pelas suas etiquetas de classe reais
|
81 |
predicted_class = class_labels[class_index]
|
82 |
|
83 |
+
# Retorne a classe prevista e as probabilidades das classes
|
84 |
+
class_probabilities = {class_labels[i]: round(float(prediction[0][i]), 4) for i in range(len(class_labels))}
|
85 |
+
return predicted_class, class_probabilities
|
86 |
|
87 |
# Crie uma interface Gradio
|
88 |
input_interface = gr.Interface(
|
89 |
fn=classify_image,
|
90 |
inputs="image", # Especifique o tipo de entrada como "image"
|
91 |
+
outputs=["text", "text"], # Especifique dois tipos de saída: classe e probabilidades
|
92 |
+
output_labels=["Predicted Class", "Class Probabilities"] # Rotule as saídas
|
93 |
)
|
94 |
|
95 |
# Inicie o aplicativo Gradio
|