yusyel commited on
Commit
25c2cee
1 Parent(s): ef57b20
app.py ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from huggingface_hub import from_pretrained_keras
3
+ from tensorflow.keras.preprocessing.image import load_img
4
+ from tensorflow.keras.preprocessing.image import img_to_array
5
+ from tensorflow.keras.preprocessing import image
6
+ import numpy as np
7
+
8
+ model = from_pretrained_keras("yusyel/clothing")
9
+
10
+ class_names=["dress.jpg",
11
+ "hat.jpg",
12
+ "longsleee.jpg",
13
+ "outwear.pg",
14
+ "pants.jpg",
15
+ "shirt.jpg",
16
+ "shoes.jpg",
17
+ "shorts.jpg",
18
+ "skirt.jpg",
19
+ "t-shirt.jpg"]
20
+
21
+
22
+
23
+ def preprocess_image(img):
24
+ img = load_img(img, target_size=(249, 249, 3))
25
+ img = image.img_to_array(img)
26
+ img = np.expand_dims(img, axis=0)
27
+ img /= 255.0
28
+ print(img.shape)
29
+ return img
30
+
31
+
32
+
33
+ def predict(img):
34
+ img = preprocess_image(img)
35
+ pred = model.predict(img)
36
+ pred = np.squeeze(pred).astype(float)
37
+ print(pred)
38
+ return dict(zip(class_names, pred))
39
+
40
+
41
+ demo = gr.Interface(
42
+ fn=predict,
43
+ inputs=[gr.inputs.Image(type="filepath")],
44
+ outputs=gr.outputs.Label(),
45
+ examples=[
46
+ ["./img/dress.jpg"],
47
+ ["./img/hat.jpg"],
48
+ ["./img/longsleeve.jpg"],
49
+ ["./img/outwear.jpg"],
50
+ ["./img/pants.jpg"],
51
+ ["./img/shirt.jpg"],
52
+ ["./img/shoes.jpg"],
53
+ ["./img/shorts.jpg"],
54
+ ["./img/skirt.jpg"],
55
+ ["./img/t-shirt.jpg"],
56
+ ],
57
+ title="fish classification",
58
+ )
59
+ demo.launch(server_name="0.0.0.0", server_port=7860)
img/dress.jpg ADDED
img/hat.jpg ADDED
img/longsleeve.jpg ADDED
img/outwear.jpg ADDED
img/pants.jpg ADDED
img/shirt.jpg ADDED
img/shoes.jpg ADDED
img/shorts.jpg ADDED
img/skirt.jpg ADDED
img/t-shirt.jpg ADDED
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ gradio==3.39.0
2
+ numpy==1.23.3
3
+ tensorflow==2.9.1