Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -12,37 +12,36 @@ configs = [
|
|
| 12 |
]
|
| 13 |
|
| 14 |
config = configs[0]
|
| 15 |
-
|
| 16 |
new_model = tf.keras.models.load_model(config["model"])
|
| 17 |
|
| 18 |
-
def
|
| 19 |
-
|
| 20 |
-
prediction = new_model.predict(
|
| 21 |
|
| 22 |
if len(prediction) > 1:
|
| 23 |
-
|
| 24 |
else:
|
| 25 |
-
|
| 26 |
|
| 27 |
-
if
|
| 28 |
label = "Glaucoma"
|
| 29 |
-
elif
|
| 30 |
-
label = "
|
| 31 |
else:
|
| 32 |
-
label = "
|
| 33 |
|
| 34 |
-
return {"
|
| 35 |
|
| 36 |
-
|
| 37 |
-
fn=
|
| 38 |
inputs=gr.inputs.Image(shape=(config["size"], config["size"])),
|
| 39 |
outputs=[
|
| 40 |
-
gr.outputs.Textbox(label="
|
| 41 |
-
gr.outputs.Textbox(label="
|
| 42 |
],
|
| 43 |
examples=["001.jpg", "002.jpg", "225.jpg"],
|
| 44 |
-
flagging_options=["
|
| 45 |
allow_flagging="manual"
|
| 46 |
)
|
| 47 |
|
| 48 |
-
|
|
|
|
| 12 |
]
|
| 13 |
|
| 14 |
config = configs[0]
|
|
|
|
| 15 |
new_model = tf.keras.models.load_model(config["model"])
|
| 16 |
|
| 17 |
+
def classificar_imagem(entrada):
|
| 18 |
+
entrada = entrada.reshape((-1, config["size"], config["size"], 3))
|
| 19 |
+
prediction = new_model.predict(entrada).flatten()
|
| 20 |
|
| 21 |
if len(prediction) > 1:
|
| 22 |
+
probabilidade = 100 * math.exp(prediction[0]) / (math.exp(prediction[0]) + math.exp(prediction[1]))
|
| 23 |
else:
|
| 24 |
+
probabilidade = round(100. / (1 + math.exp(-prediction[0])), 2)
|
| 25 |
|
| 26 |
+
if probabilidade > 45:
|
| 27 |
label = "Glaucoma"
|
| 28 |
+
elif probabilidade > 25:
|
| 29 |
+
label = "Incerto"
|
| 30 |
else:
|
| 31 |
+
label = "N茫o glaucoma"
|
| 32 |
|
| 33 |
+
return {"R贸tulo": label, "Probabilidade de glaucoma (0 - 100)": probabilidade}
|
| 34 |
|
| 35 |
+
interface = gr.Interface(
|
| 36 |
+
fn=classificar_imagem,
|
| 37 |
inputs=gr.inputs.Image(shape=(config["size"], config["size"])),
|
| 38 |
outputs=[
|
| 39 |
+
gr.outputs.Textbox(label="R贸tulo"),
|
| 40 |
+
gr.outputs.Textbox(label="Probabilidade de glaucoma (0 - 100)")
|
| 41 |
],
|
| 42 |
examples=["001.jpg", "002.jpg", "225.jpg"],
|
| 43 |
+
flagging_options=["R贸tulo correto", "R贸tulo incorreto"],
|
| 44 |
allow_flagging="manual"
|
| 45 |
)
|
| 46 |
|
| 47 |
+
interface.launch()
|