anderni2 commited on
Commit
b2432f8
·
verified ·
1 Parent(s): bf072bd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -10
app.py CHANGED
@@ -1,28 +1,28 @@
1
  import gradio as gr
2
  import tensorflow as tf
3
- from PIL import Image
4
  import numpy as np
5
 
6
- # Lade dein Modell (hier als Beispiel die Keras .h5 Datei)
7
  model = tf.keras.models.load_model('Task_Pokemon.keras')
8
- # Klassennamen
 
9
  class_names = ['Aerodactyl', 'Charizard', 'Victreebel']
10
 
11
  def classify_image(image):
12
- img = image.resize((160, 160))
13
- img_array = tf.keras.preprocessing.image.img_to_array(img)
14
- img_array = tf.expand_dims(img_array, 0) # Erstelle einen Batch
15
  predictions = model.predict(img_array)
16
  predicted_class = class_names[np.argmax(predictions[0])]
17
  confidence = np.max(predictions[0])
18
  return predicted_class, confidence
19
 
20
- image_input = gr.Image(shape=(160, 160))
21
- label = gr.Label(num_top_classes=3)
22
 
23
  iface = gr.Interface(
24
- fn=classify_image,
25
- inputs=image_input,
26
  outputs=label,
27
  title='Pokémon-Bildklassifizierer',
28
  description='Lade ein Bild von Aerodactyl, Charizard oder Victreebel hoch. Unser Klassifizierer wird das Pokémon identifizieren und das Vertrauensniveau der Vorhersage anzeigen.'
 
1
  import gradio as gr
2
  import tensorflow as tf
 
3
  import numpy as np
4
 
5
+ # Laden Sie Ihr benutzerdefiniertes Regressionsmodell
6
  model = tf.keras.models.load_model('Task_Pokemon.keras')
7
+
8
+ # Klassennamen, sollten Ihrem Dataset entsprechen
9
  class_names = ['Aerodactyl', 'Charizard', 'Victreebel']
10
 
11
  def classify_image(image):
12
+ img_pil = image.resize((160, 160)) # Definieren der Größe der Bilder
13
+ img_array = tf.keras.preprocessing.image.img_to_array(img_pil)
14
+ img_array = tf.expand_dims(img_array, 0) # Erstellen eines Batches
15
  predictions = model.predict(img_array)
16
  predicted_class = class_names[np.argmax(predictions[0])]
17
  confidence = np.max(predictions[0])
18
  return predicted_class, confidence
19
 
20
+ image_input = gr.inputs.Image()
21
+ label = gr.outputs.Label(num_top_classes=3)
22
 
23
  iface = gr.Interface(
24
+ fn=classify_image,
25
+ inputs=image_input,
26
  outputs=label,
27
  title='Pokémon-Bildklassifizierer',
28
  description='Lade ein Bild von Aerodactyl, Charizard oder Victreebel hoch. Unser Klassifizierer wird das Pokémon identifizieren und das Vertrauensniveau der Vorhersage anzeigen.'