Dimitre commited on
Commit
f85da4b
·
1 Parent(s): 0f87dda

Adding initial template

Browse files
Files changed (2) hide show
  1. app.py +40 -0
  2. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Workaround to install the lib without "setup.py"
2
+ import sys
3
+ from git import Repo
4
+ Repo.clone_from("https://github.com/dimitreOliveira/hub.git", "./hub")
5
+ sys.path.append("/hub")
6
+
7
+ import requests
8
+ # Download human-readable labels for ImageNet.
9
+ response = requests.get("https://storage.googleapis.com/download.tensorflow.org/data/ImageNetLabels.txt")
10
+ labels = [x for x in response.text.split("\n") if x != ""]
11
+
12
+
13
+ import gradio as gr
14
+ import tensorflow as tf
15
+ from hub.tensorflow_hub.hf_utils import pull_from_hub
16
+
17
+ model = pull_from_hub(repo_id="Dimitre/mobilenet_v3_small")
18
+
19
+ def preprocess(image):
20
+ print(image)
21
+ print("***********")
22
+ image = image.reshape((-1, 224, 224, 3))
23
+ print(image)
24
+ print("***********")
25
+ print(image / 255.)
26
+ return image / 255.
27
+
28
+ def postprocess(prediction):
29
+ return {labels[i]: prediction[i] for i in range(len(labels))}
30
+
31
+ def predict_fn(image):
32
+ image = preprocess(image)
33
+ prediction = model([image])
34
+ scores = postprocess(prediction)
35
+ return scores
36
+
37
+ iface = gr.Interface(fn=predict_fn,
38
+ inputs=gr.Image(shape=(224, 224)),
39
+ outputs=gr.Label(num_top_classes=5))
40
+ iface.launch()
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ GitPython
2
+ tensorflow