Amit Kumar
commited on
Commit
Β·
df7b2e1
1
Parent(s):
fde6b3b
update app.py
Browse files
app.py
CHANGED
@@ -7,12 +7,10 @@ from torchvision import transforms
|
|
7 |
from timeit import default_timer as timer
|
8 |
from typing import Tuple, Dict
|
9 |
|
10 |
-
# Setup class names
|
11 |
-
class_names = ["Smiling", "Not Smiling",]
|
12 |
|
13 |
-
###
|
14 |
|
15 |
-
model = torch.load(f="smile_classifier
|
16 |
|
17 |
transform = transforms.Compose([
|
18 |
transforms.CenterCrop(size=[178, 178]),
|
@@ -20,7 +18,7 @@ transform = transforms.Compose([
|
|
20 |
transforms.ToTensor()
|
21 |
])
|
22 |
|
23 |
-
###
|
24 |
|
25 |
# Create predict function
|
26 |
def predict(img) -> Tuple[Dict, float]:
|
@@ -50,7 +48,7 @@ def predict(img) -> Tuple[Dict, float]:
|
|
50 |
# Return the prediction dictionary and prediction time
|
51 |
return pred_labels_and_probs, pred_time
|
52 |
|
53 |
-
###
|
54 |
|
55 |
# Create title, description and article strings
|
56 |
title = "Smile Classifier πππ"
|
@@ -59,7 +57,7 @@ article = "Please select an image from provided examples and submit, the model w
|
|
59 |
is smiling or not and will also provide prediction probabilities."
|
60 |
|
61 |
# Create examples list from "examples/" directory
|
62 |
-
example_list = [["
|
63 |
|
64 |
#Create the Gradio demo
|
65 |
demo = gr.Interface(fn=predict, # mapping function from input to output
|
|
|
7 |
from timeit import default_timer as timer
|
8 |
from typing import Tuple, Dict
|
9 |
|
|
|
|
|
10 |
|
11 |
+
### Model and transforms preparation ###
|
12 |
|
13 |
+
model = torch.load(f="smile_classifier.pth")
|
14 |
|
15 |
transform = transforms.Compose([
|
16 |
transforms.CenterCrop(size=[178, 178]),
|
|
|
18 |
transforms.ToTensor()
|
19 |
])
|
20 |
|
21 |
+
### Predict function ###
|
22 |
|
23 |
# Create predict function
|
24 |
def predict(img) -> Tuple[Dict, float]:
|
|
|
48 |
# Return the prediction dictionary and prediction time
|
49 |
return pred_labels_and_probs, pred_time
|
50 |
|
51 |
+
### Gradio app ###
|
52 |
|
53 |
# Create title, description and article strings
|
54 |
title = "Smile Classifier πππ"
|
|
|
57 |
is smiling or not and will also provide prediction probabilities."
|
58 |
|
59 |
# Create examples list from "examples/" directory
|
60 |
+
example_list = [["examples/" + example] for example in os.listdir("examples")]
|
61 |
|
62 |
#Create the Gradio demo
|
63 |
demo = gr.Interface(fn=predict, # mapping function from input to output
|