igman101 commited on
Commit
b8e7728
·
verified ·
1 Parent(s): 128ba45

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -11
app.py CHANGED
@@ -3,27 +3,33 @@ import tensorflow as tf
3
  from tensorflow.keras.preprocessing import image
4
  import numpy as np
5
 
6
- # Modell laden
7
- model = tf.keras.models.load_model('pokemon_classifier_model.keras')
 
 
 
8
 
9
  # Klassenlabels
10
  class_names = ['Bisasam', 'Schiggy', 'Glumanda']
11
 
12
  # Vorhersagefunktion
13
  def predict(img):
14
- img = img.resize((224, 224))
15
- img_array = np.array(img)
16
- img_array = np.expand_dims(img_array, axis=0)
17
- img_array = tf.keras.applications.vgg16.preprocess_input(img_array)
 
18
 
19
- predictions = model.predict(img_array)
20
- score = tf.nn.softmax(predictions[0])
21
 
22
- return {class_names[i]: float(score[i]) for i in range(3)}
 
 
23
 
24
  # Gradio Interface erstellen
25
- image_input = gr.inputs.Image(type='pil')
26
- label_output = gr.outputs.Label(num_top_classes=3)
27
 
28
  gr.Interface(fn=predict, inputs=image_input, outputs=label_output,
29
  title="Pokémon Classifier",
 
3
  from tensorflow.keras.preprocessing import image
4
  import numpy as np
5
 
6
+ # Modell laden mit Fehlerbehandlung
7
+ try:
8
+ model = tf.keras.models.load_model('pokemon_classifier_model.keras')
9
+ except Exception as e:
10
+ print(f"Fehler beim Laden des Modells: {e}")
11
 
12
  # Klassenlabels
13
  class_names = ['Bisasam', 'Schiggy', 'Glumanda']
14
 
15
  # Vorhersagefunktion
16
  def predict(img):
17
+ try:
18
+ img = img.resize((224, 224))
19
+ img_array = np.array(img)
20
+ img_array = np.expand_dims(img_array, axis=0)
21
+ img_array = tf.keras.applications.vgg16.preprocess_input(img_array)
22
 
23
+ predictions = model.predict(img_array)
24
+ score = tf.nn.softmax(predictions[0])
25
 
26
+ return {class_names[i]: float(score[i]) for i in range(3)}
27
+ except Exception as e:
28
+ return {"Fehler": str(e)}
29
 
30
  # Gradio Interface erstellen
31
+ image_input = gr.Image(type='pil')
32
+ label_output = gr.Label(num_top_classes=3)
33
 
34
  gr.Interface(fn=predict, inputs=image_input, outputs=label_output,
35
  title="Pokémon Classifier",