mimimimimi commited on
Commit
38dc852
·
verified ·
1 Parent(s): 97f3cff

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -20
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 pyttsx3
 
6
 
7
- # モデルの読み込み
8
  model = load_model("keras_model.h5", compile=False)
9
 
10
- # ラベルの読み込み
11
- class_names = open("labels.txt", "r", encoding="utf-8").readlines()
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
- return class_name
36
 
37
- def speak_text(text):
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()