jdelgado2002 commited on
Commit
7e9eb72
·
verified ·
1 Parent(s): 1450441

fix upload problem (#1)

Browse files

- fix upload problem (70af086601b9d64eb9887378716cefc3e6ccad06)

Files changed (1) hide show
  1. app.py +13 -32
app.py CHANGED
@@ -1,17 +1,12 @@
1
  import gradio as gr
2
  from fastai.vision.all import *
3
- import skimage
4
-
5
- # Define the functions to get the x and y values from the input dictionary - in this case, the x value is the image and the y value is the diagnosis
6
- # needed to load the model since we defined them during training
7
- def get_x(r): return ""
8
-
9
- def get_y(r): return r['diagnosis']
10
 
 
11
  learn = load_learner('model.pkl')
12
  labels = learn.dls.vocab
13
 
14
- # Define the mapping from label numbers to descriptions
15
  label_descriptions = {
16
  0: "No DR",
17
  1: "Mild",
@@ -20,41 +15,27 @@ label_descriptions = {
20
  4: "Proliferative DR"
21
  }
22
 
 
23
  def predict(img):
24
  img = PILImage.create(img)
25
- pred,pred_idx,probs = learn.predict(img)
26
- # Use the label_descriptions dictionary to return descriptions instead of numbers
27
  return {label_descriptions[labels[i]]: float(probs[i]) for i in range(len(labels))}
28
 
 
29
  title = "Diabetic Retinopathy Detection"
30
- description = """Detects severity of diabetic retinopathy from a given retina image taken using fundus photography -
31
-
32
- 0 - No DR
33
-
34
- 1 - Mild
35
-
36
- 2 - Moderate
37
-
38
- 3 - Severe
39
 
40
- 4 - Proliferative DR
41
- """
42
- article = """
43
- <p style='text-align: center'>
44
- <a href='https://www.kaggle.com/code/josemauriciodelgado/proliferative-retinopathy' target='_blank'>Kaggle Training Notebook</a> |
45
- <a href='https://huggingface.co/jdelgado2002/diabetic_retinopathy_detection' target='_blank'>Model Card</a>
46
- </p>
47
- """
48
- # Get a list of all image paths in the test folder
49
- test_folder = "test" # replace with the actual path to your test folder
50
  image_paths = [os.path.join(test_folder, img) for img in os.listdir(test_folder) if img.endswith(('.png', '.jpg', '.jpeg'))]
51
 
52
  gr.Interface(
53
  fn=predict,
54
- inputs=gr.Image(),
55
  outputs=gr.Label(num_top_classes=5),
56
- examples=image_paths, # set the examples parameter to the list of image paths
57
  article=article,
58
  title=title,
59
  description=description,
60
- ).launch()
 
1
  import gradio as gr
2
  from fastai.vision.all import *
3
+ import os
 
 
 
 
 
 
4
 
5
+ # Load model
6
  learn = load_learner('model.pkl')
7
  labels = learn.dls.vocab
8
 
9
+ # Define label descriptions
10
  label_descriptions = {
11
  0: "No DR",
12
  1: "Mild",
 
15
  4: "Proliferative DR"
16
  }
17
 
18
+ # Prediction function
19
  def predict(img):
20
  img = PILImage.create(img)
21
+ pred, pred_idx, probs = learn.predict(img)
 
22
  return {label_descriptions[labels[i]]: float(probs[i]) for i in range(len(labels))}
23
 
24
+ # Gradio Interface
25
  title = "Diabetic Retinopathy Detection"
26
+ description = """Detects severity of diabetic retinopathy from a given retina image."""
27
+ article = "<p style='text-align: center'>Example article or instructions here</p>"
 
 
 
 
 
 
 
28
 
29
+ # Prepare examples if available
30
+ test_folder = "test"
 
 
 
 
 
 
 
 
31
  image_paths = [os.path.join(test_folder, img) for img in os.listdir(test_folder) if img.endswith(('.png', '.jpg', '.jpeg'))]
32
 
33
  gr.Interface(
34
  fn=predict,
35
+ inputs=gr.Image(type="filepath"),
36
  outputs=gr.Label(num_top_classes=5),
37
+ examples=image_paths,
38
  article=article,
39
  title=title,
40
  description=description,
41
+ ).launch()