M. Saad Munawar
commited on
Commit
•
3a1c44f
1
Parent(s):
b1050fa
https://huggingface.co/spaces/Saad123/minima
Browse files- app.py +7 -2
- requirements.txt +1 -0
app.py
CHANGED
@@ -2,6 +2,7 @@ import gradio as gr
|
|
2 |
import numpy as np
|
3 |
import tensorflow as tf
|
4 |
import tensorflow_hub as hub
|
|
|
5 |
|
6 |
loaded_model = tf.keras.models.load_model(
|
7 |
('CatDogmodel.h5'),
|
@@ -9,16 +10,20 @@ loaded_model = tf.keras.models.load_model(
|
|
9 |
)
|
10 |
|
11 |
def model(image):
|
|
|
12 |
im_scaled = image/255
|
13 |
im_reshape = np.reshape(im_scaled,[1,224,224,3])
|
|
|
14 |
pred = loaded_model.predict(im_reshape)
|
|
|
|
|
15 |
cat_pred = pred
|
16 |
dog_pred = 1-pred
|
17 |
pred_label = np.argmax(pred)
|
18 |
if (pred_label == 0):
|
19 |
-
return
|
20 |
if (pred_label == 1):
|
21 |
-
return "The Image is of a Cat."
|
22 |
|
23 |
image = gr.inputs.Image(shape=(224,224))
|
24 |
background='body{background-image:url("https://d2gg9evh47fn9z.cloudfront.net/800px_COLOURBOX35440124.jpg");}'
|
|
|
2 |
import numpy as np
|
3 |
import tensorflow as tf
|
4 |
import tensorflow_hub as hub
|
5 |
+
import time
|
6 |
|
7 |
loaded_model = tf.keras.models.load_model(
|
8 |
('CatDogmodel.h5'),
|
|
|
10 |
)
|
11 |
|
12 |
def model(image):
|
13 |
+
|
14 |
im_scaled = image/255
|
15 |
im_reshape = np.reshape(im_scaled,[1,224,224,3])
|
16 |
+
start = time.time()
|
17 |
pred = loaded_model.predict(im_reshape)
|
18 |
+
end=time.time()
|
19 |
+
t = start-end
|
20 |
cat_pred = pred
|
21 |
dog_pred = 1-pred
|
22 |
pred_label = np.argmax(pred)
|
23 |
if (pred_label == 0):
|
24 |
+
return "The Image is of a Dog."+"Accuracy:" +dog_pred[0]+"Time:"+t
|
25 |
if (pred_label == 1):
|
26 |
+
return "The Image is of a Cat."+"Accuracy:" +cat_pred[1]+"Time"+t
|
27 |
|
28 |
image = gr.inputs.Image(shape=(224,224))
|
29 |
background='body{background-image:url("https://d2gg9evh47fn9z.cloudfront.net/800px_COLOURBOX35440124.jpg");}'
|
requirements.txt
CHANGED
@@ -5,3 +5,4 @@ tensorflow_hub==0.12.0
|
|
5 |
matplotlib==3.5.1
|
6 |
opencv_python==4.6.0.66
|
7 |
Pillow==9.2.0
|
|
|
|
5 |
matplotlib==3.5.1
|
6 |
opencv_python==4.6.0.66
|
7 |
Pillow==9.2.0
|
8 |
+
time
|