Update app.py
Browse files
app.py
CHANGED
|
@@ -1,18 +1,27 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from
|
| 3 |
-
import skimage
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
def predict(img):
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
title = "Proliferative Retinopathy Detection"
|
| 15 |
-
description = """Detects severity of diabetic retinopathy -
|
| 16 |
|
| 17 |
0 - No DR
|
| 18 |
|
|
@@ -28,4 +37,4 @@ article="<p style='text-align: center'><a href='https://www.kaggle.com/code/jose
|
|
| 28 |
interpretation='default'
|
| 29 |
enable_queue=True
|
| 30 |
|
| 31 |
-
gr.Interface(fn=predict,inputs=gr.inputs.Image(shape=(512, 512)),outputs=gr.outputs.Label(num_top_classes=6),title=title,description=description,article=article,
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from huggingface_hub import InferenceAPI
|
|
|
|
| 3 |
|
| 4 |
+
# Specify the model name
|
| 5 |
+
model_repo = "jdelgado2002/diabetic_retinopathy_detection"
|
| 6 |
+
|
| 7 |
+
# Initialize the InferenceAPI client
|
| 8 |
+
api = InferenceAPI(model_repo)
|
| 9 |
+
|
| 10 |
+
labels = ["No DR", "Mild", "Moderate", "Severe", "Proliferative DR"]
|
| 11 |
|
| 12 |
def predict(img):
|
| 13 |
+
# Convert the image to a base64 string
|
| 14 |
+
img_str = gr.inputs.Image.to_base64(img, ext="jpeg")
|
| 15 |
+
|
| 16 |
+
# Perform inference
|
| 17 |
+
inputs = {"inputs": img_str}
|
| 18 |
+
result = api(inputs)
|
| 19 |
+
|
| 20 |
+
# Convert the result to the expected format
|
| 21 |
+
return {labels[i]: float(result[i]) for i in range(len(labels))}
|
| 22 |
|
| 23 |
title = "Proliferative Retinopathy Detection"
|
| 24 |
+
description = """Detects severity of diabetic retinopathy -
|
| 25 |
|
| 26 |
0 - No DR
|
| 27 |
|
|
|
|
| 37 |
interpretation='default'
|
| 38 |
enable_queue=True
|
| 39 |
|
| 40 |
+
gr.Interface(fn=predict,inputs=gr.inputs.Image(shape=(512, 512)),outputs=gr.outputs.Label(num_top_classes=6),title=title,description=description,article=article,interpretation=interpretation,enable_queue=enable_queue).launch()
|