Carlos Aguayo commited on
Commit
3160316
1 Parent(s): 7b9d571

cats vs dogs space

Browse files
Files changed (3) hide show
  1. app.py +34 -0
  2. packages.txt +1 -0
  3. requirements.txt +5 -0
app.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import cv2
3
+ from huggingface_hub import from_pretrained_keras
4
+ from skimage import io
5
+
6
+ ROWS, COLS = 150, 150
7
+
8
+ model = from_pretrained_keras("carlosaguayo/cats_vs_dogs")
9
+
10
+ def process_image(img):
11
+ img = cv2.resize(img, (ROWS, COLS), interpolation=cv2.INTER_CUBIC)
12
+ img = img / 255.0
13
+ img = img.reshape(1,ROWS,COLS,3)
14
+
15
+ prediction = model.predict(img)[0][0]
16
+ if prediction >= 0.5:
17
+ message = 'I am {:.2%} sure this is a Cat'.format(prediction)
18
+ else:
19
+ message = 'I am {:.2%} sure this is a Dog'.format(1-prediction)
20
+ return message
21
+
22
+ title = "Interactive demo: Classify cat vs dog"
23
+ description = "Simple Cat vs Dog classification"
24
+ article = ""
25
+ # examples =[["image_0.png"], ["image_1.png"], ["image_2.png"]]
26
+
27
+ iface = gr.Interface(fn=process_image,
28
+ inputs=gr.inputs.Image(),
29
+ outputs=gr.outputs.Textbox(),
30
+ title=title,
31
+ description=description)
32
+ # article=article,
33
+ # examples=examples)
34
+ iface.launch()
packages.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ python3-opencv
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ gradio
2
+ transformers
3
+ opencv-python
4
+ scikit-image
5
+ tensorflow