AustinL commited on
Commit
0ec85cb
·
verified ·
1 Parent(s): 8952ab5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -21
app.py CHANGED
@@ -1,25 +1,21 @@
 
1
  import gradio as gr
2
 
3
- # Assuming no shape needs to be specified directly in the constructor
4
- image = gr.Image()
5
- label = gr.Label()
6
- examples = [
7
- '/kaggle/input/leukemia-cells/allbloodsmear.jpg',
8
- '/kaggle/input/cells-of-sickle/650x450-Sickle-Cell-Trait.jpg',
9
- '/kaggle/input/cells-of-sickle/Sickle Cell Anemia smear 40x.jpg',
10
- '/kaggle/input/healthy-cells/normalbloodsmear.jpg'
11
- ]
12
 
13
- intf = gr.Interface(
14
- fn=classify_image,
15
- inputs=image,
16
- outputs=label,
17
- examples=examples,
18
- title='Blood Disease Identifier',
19
- description="Please upload your blood smear image that is greater than 200x magnification to diagnose the patient with the following blood diseases: Sickle Cell Disease, Leukemia, or Thalassemia. <br><br>Please note that the results are not 100% accurate and should only be used as a first means of detection. Please contact a medical professional for more information and possible future action. HematoTech are not liable for any misdiagnosis that may occur.",
20
- allow_flagging=False,
21
- article='Sickle cell disease (SCD) is a group of inherited red blood cell disorders. In SCD, the red blood cells become hard and sticky and look like a C-shaped farm tool called a “sickle.” The disease can be managed under proper medical supervision.'
22
- )
23
 
24
- # Launch the interface
25
- intf.launch(inline=False)
 
1
+ from fastai.vision.all import *
2
  import gradio as gr
3
 
4
+ def get_label(x):
5
+ return 'dog' if 'dog' in x.name else 'cat'
6
+
7
+ learn = load_learner('cat_or_dog.pkl')
8
+
9
+ # Extract categories directly from the learner to ensure correct order
10
+ categories = learn.dls.vocab
 
 
11
 
12
+ def classify_img(img):
13
+ pred, idx, probs = learn.predict(img)
14
+ return {categories[i]: float(probs[i]) for i in range(len(categories))}
15
+
16
+ image = gr.Image()
17
+ labels = gr.Label()
18
+ examples = ['dog.jpg', 'cat.jpeg']
 
 
 
19
 
20
+ intf = gr.Interface(fn=classify_img, inputs=image, outputs=labels, examples=examples)
21
+ intf.launch(inline=False, share=True)