jingwora commited on
Commit
e1d63e2
1 Parent(s): 7d0793a

Add application file

Browse files
Files changed (6) hide show
  1. app.py +47 -0
  2. buger.jpg +0 -0
  3. goldfish.jpg +0 -0
  4. lake-house.jpg +0 -0
  5. requirements.txt +2 -0
  6. truck.jpg +0 -0
app.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import requests
3
+ import tensorflow as tf
4
+
5
+ import gradio as gr
6
+
7
+ inception_net = tf.keras.applications.MobileNetV2() # load the model
8
+
9
+ response = requests.get("https://git.io/JJkYN")
10
+ labels = response.text.split("\n")
11
+
12
+
13
+ def classify_image(inp):
14
+ inp = inp.reshape((-1, 224, 224, 3))
15
+ inp = tf.keras.applications.mobilenet_v2.preprocess_input(inp)
16
+ prediction = inception_net.predict(inp).flatten()
17
+ return {labels[i]: float(prediction[i]) for i in range(1000)}
18
+
19
+
20
+ title = "Image Classifiction + Interpretation"
21
+ description = """
22
+ Task: Image Classification\n
23
+ Dataset: COCO 2017, 1,000 classes\n
24
+ Model: https://huggingface.co/google/mobilenet_v2_1.0_224\n
25
+ Developer: Google \n
26
+ """
27
+ image = gr.Image(shape=(224, 224))
28
+ label = gr.Label(num_top_classes=3)
29
+ examples = [
30
+ ["buger.jpg"],
31
+ ["goldfish.jpg"],
32
+ ["lake-house.jpg"],
33
+ ["truck.jpg"],
34
+ ]
35
+
36
+ demo = gr.Interface(
37
+ fn=classify_image,
38
+ inputs=image,
39
+ outputs=label,
40
+ interpretation="default",
41
+ title=title,
42
+ description=description,
43
+ examples=examples,
44
+ theme="freddyaboulton/dracula_revamped",
45
+ )
46
+
47
+ demo.launch()
buger.jpg ADDED
goldfish.jpg ADDED
lake-house.jpg ADDED
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ gradio==3.36.1
2
+ tensorflow==2.12.0
truck.jpg ADDED