jdelgado2002 commited on
Commit
7669f3a
1 Parent(s): 2d500f0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -10
app.py CHANGED
@@ -1,18 +1,27 @@
1
  import gradio as gr
2
- from fastai.vision.all import *
3
- import skimage
4
 
5
- learn = load_learner('model.pkl')
6
- #examples = [['Images/PKG - Breast-Metastases-MSKCC/Breast-Metastases-MSKCC/HobI16-053768896760.jpeg'], ['Images/PKG - CPTAC-BRCA/BRCA/01BR001-4ffefc66-d0ba-4a36-b4fa-35bd91.jpeg']]
7
- labels = learn.dls.vocab
 
 
 
 
8
 
9
  def predict(img):
10
- img = PILImage.create(img)
11
- pred,pred_idx,probs = learn.predict(img)
12
- return {labels[i]: float(probs[i]) for i in range(len(labels))}
 
 
 
 
 
 
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,examples=examples , interpretation=interpretation,enable_queue=enable_queue).launch()
 
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()