Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,14 +1,16 @@
|
|
1 |
-
from keras.models import load_model
|
2 |
-
from PIL import Image, ImageOps
|
3 |
import numpy as np
|
|
|
4 |
import gradio as gr
|
5 |
-
import
|
|
|
6 |
|
7 |
-
#
|
8 |
model = load_model("keras_model.h5", compile=False)
|
9 |
|
10 |
-
#
|
11 |
-
class_names = open("labels.txt", "r",
|
12 |
|
13 |
def greet(img):
|
14 |
data = np.ndarray(shape=(1, 224, 224, 3), dtype=np.float32)
|
@@ -23,21 +25,11 @@ def greet(img):
|
|
23 |
|
24 |
prediction = model.predict(data)
|
25 |
|
26 |
-
max_index = np.argmax(prediction)
|
27 |
-
class_name = class_names[max_index]
|
28 |
-
|
29 |
-
# ファイルの内容からクラス名を抽出
|
30 |
-
class_name = class_name[2:]
|
31 |
-
|
32 |
-
# 予測されたクラス名を読み上げる
|
33 |
-
speak_text(class_name)
|
34 |
|
35 |
-
|
36 |
|
37 |
-
|
38 |
-
engine = pyttsx3.init()
|
39 |
-
engine.say(text)
|
40 |
-
engine.runAndWait()
|
41 |
|
42 |
demo = gr.Interface(
|
43 |
fn=greet,
|
@@ -45,4 +37,5 @@ demo = gr.Interface(
|
|
45 |
outputs="text",
|
46 |
)
|
47 |
|
48 |
-
demo.launch()
|
|
|
|
1 |
+
from keras.models import load_model # TensorFlow is required for Keras to work
|
2 |
+
from PIL import Image, ImageOps # Install pillow instead of PIL
|
3 |
import numpy as np
|
4 |
+
|
5 |
import gradio as gr
|
6 |
+
import numpy as np
|
7 |
+
# from PIL import Image, ImageOps
|
8 |
|
9 |
+
# Load the model
|
10 |
model = load_model("keras_model.h5", compile=False)
|
11 |
|
12 |
+
# Load the labels
|
13 |
+
class_names = open("labels.txt", "r",encoding="utf-8").readlines()
|
14 |
|
15 |
def greet(img):
|
16 |
data = np.ndarray(shape=(1, 224, 224, 3), dtype=np.float32)
|
|
|
25 |
|
26 |
prediction = model.predict(data)
|
27 |
|
28 |
+
max_index = np.argmax(prediction) # 確率が一番高いインデクスを抽出
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
|
30 |
+
class_name = class_names[max_index]
|
31 |
|
32 |
+
return class_name[2:]
|
|
|
|
|
|
|
33 |
|
34 |
demo = gr.Interface(
|
35 |
fn=greet,
|
|
|
37 |
outputs="text",
|
38 |
)
|
39 |
|
40 |
+
# demo.launch(debug=True, share=True)
|
41 |
+
demo.launch()
|