Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -1,81 +1,77 @@
|
|
1 |
-
# import gradio as gr
|
2 |
-
# import tensorflow as tf
|
3 |
-
# from PIL import Image
|
4 |
-
# import numpy as np
|
5 |
-
|
6 |
-
# # Teachable Machineで作成したモデルのパス
|
7 |
-
# model_path = "keras_model.h5"
|
8 |
-
|
9 |
-
# # モデルの読み込み
|
10 |
-
# model = tf.keras.models.load_model(model_path)
|
11 |
-
|
12 |
-
# # クラスのラベル(Teachable Machineで指定したクラス名と同じ順序で設定)
|
13 |
-
# class_labels = [
|
14 |
-
# "Cotton",
|
15 |
-
# "Linen",
|
16 |
-
# "Silk",
|
17 |
-
# "Wool",
|
18 |
-
# "Polyester",
|
19 |
-
# "Nylon",
|
20 |
-
# "Rayon",
|
21 |
-
# "Fleece",
|
22 |
-
# "Leather",
|
23 |
-
# "Synth Leather"
|
24 |
-
# ]
|
25 |
-
|
26 |
-
# # GradioのUIの設定
|
27 |
-
# def classify_image(img):
|
28 |
-
# # 画像の前処理
|
29 |
-
# img = Image.fromarray((img * 255).astype(np.uint8))
|
30 |
-
# img = img.resize((224, 224))
|
31 |
-
# img_array = tf.keras.preprocessing.image.img_to_array(img)
|
32 |
-
# img_array = tf.expand_dims(img_array, 0) # バッチの次元を追加
|
33 |
-
|
34 |
-
# # モデルの予測
|
35 |
-
# predictions = model.predict(img_array)
|
36 |
-
# predicted_class = class_labels[np.argmax(predictions)]
|
37 |
-
|
38 |
-
# return predicted_class
|
39 |
-
|
40 |
-
# # Gradio UIの作成
|
41 |
-
# iface = gr.Interface(
|
42 |
-
# fn=classify_image,
|
43 |
-
# inputs=gr.Image(),
|
44 |
-
# outputs=gr.Textbox(),
|
45 |
-
# # live=True,
|
46 |
-
# )
|
47 |
-
|
48 |
-
# # UIの起動
|
49 |
-
# iface.launch(share=True)
|
50 |
-
from fastai.vision.all import *
|
51 |
import gradio as gr
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
def classify_image(img):
|
59 |
-
|
60 |
-
|
61 |
-
|
|
|
|
|
62 |
|
|
|
|
|
|
|
63 |
|
|
|
64 |
|
|
|
65 |
iface = gr.Interface(
|
66 |
fn=classify_image,
|
67 |
inputs=gr.Image(),
|
68 |
outputs=gr.Textbox(),
|
69 |
-
title = title,
|
70 |
-
examples = ['dress.jpg', 'shirt.jpg', 'pants.jpg', 'shorts.jpg'],
|
71 |
-
|
72 |
# live=True,
|
73 |
)
|
|
|
|
|
74 |
iface.launch(share=True)
|
75 |
-
# image = gr.Image(shape=(512, 512))
|
76 |
-
# label = gr.Label()
|
77 |
-
# examples = ['dress.jpg', 'shirt.jpg', 'pants.jpg', 'shorts.jpg']
|
78 |
|
79 |
-
# intf = gr.Interface(fn=classify_image, title=title, inputs=image, outputs=label, examples=examples)
|
80 |
-
# intf.launch(inline=False)
|
81 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
import tensorflow as tf
|
3 |
+
from PIL import Image
|
4 |
+
import numpy as np
|
5 |
+
|
6 |
+
# Teachable Machineで作成したモデルのパス
|
7 |
+
model_path = "keras_model.h5"
|
8 |
+
|
9 |
+
# モデルの読み込み
|
10 |
+
model = tf.keras.models.load_model(model_path)
|
11 |
+
|
12 |
+
# クラスのラベル(Teachable Machineで指定したクラス名と同じ順序で設定)
|
13 |
+
class_labels = [
|
14 |
+
"Cotton",
|
15 |
+
"Linen",
|
16 |
+
"Silk",
|
17 |
+
"Wool",
|
18 |
+
"Polyester",
|
19 |
+
"Nylon",
|
20 |
+
"Rayon",
|
21 |
+
"Fleece",
|
22 |
+
"Leather",
|
23 |
+
"Synth Leather"
|
24 |
+
]
|
25 |
+
|
26 |
+
# GradioのUIの設定
|
27 |
def classify_image(img):
|
28 |
+
# 画像の前処理
|
29 |
+
img = Image.fromarray((img * 255).astype(np.uint8))
|
30 |
+
img = img.resize((224, 224))
|
31 |
+
img_array = tf.keras.preprocessing.image.img_to_array(img)
|
32 |
+
img_array = tf.expand_dims(img_array, 0) # バッチの次元を追加
|
33 |
|
34 |
+
# モデルの予測
|
35 |
+
predictions = model.predict(img_array)
|
36 |
+
predicted_class = class_labels[np.argmax(predictions)]
|
37 |
|
38 |
+
return predicted_class
|
39 |
|
40 |
+
# Gradio UIの作成
|
41 |
iface = gr.Interface(
|
42 |
fn=classify_image,
|
43 |
inputs=gr.Image(),
|
44 |
outputs=gr.Textbox(),
|
|
|
|
|
|
|
45 |
# live=True,
|
46 |
)
|
47 |
+
|
48 |
+
# UIの起動
|
49 |
iface.launch(share=True)
|
|
|
|
|
|
|
50 |
|
|
|
|
|
51 |
|
52 |
+
|
53 |
+
# from fastai.vision.all import *
|
54 |
+
# import gradio as gr
|
55 |
+
|
56 |
+
# learn = load_learner('export.pkl')
|
57 |
+
|
58 |
+
# categories = ('Blouse', 'Dress', 'Pants', 'Shirt', 'Shorts')
|
59 |
+
# title = "Clothing Identifier"
|
60 |
+
|
61 |
+
# def classify_image(img):
|
62 |
+
# pred, idx, probs = learn.predict(img)
|
63 |
+
# highest_prob_index = probs.argmax() # Find the index of the highest probability
|
64 |
+
# return categories[highest_prob_index] # Return the class with the highest probability
|
65 |
+
|
66 |
+
|
67 |
+
|
68 |
+
# iface = gr.Interface(
|
69 |
+
# fn=classify_image,
|
70 |
+
# inputs=gr.Image(),
|
71 |
+
# outputs=gr.Textbox(),
|
72 |
+
# title = title,
|
73 |
+
# examples = ['dress.jpg', 'shirt.jpg', 'pants.jpg', 'shorts.jpg'],
|
74 |
+
|
75 |
+
# # live=True,
|
76 |
+
# )
|
77 |
+
# iface.launch(share=True)
|