chiraant commited on
Commit
985502b
·
verified ·
1 Parent(s): 9dd57fb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -34
app.py CHANGED
@@ -1,35 +1,35 @@
1
- import gradio as gr
2
- import tensorflow as tf
3
- import numpy as np
4
- from PIL import Image
5
-
6
-
7
- # Modell laden
8
- model = tf.keras.models.load_model('pokemon_classifier.keras')
9
-
10
- def classify_image(image):
11
- # Bild vorverarbeiten
12
- image = Image.fromarray(image.astype('uint8')).convert('RGB')
13
- image = image.resize((150, 150)) # Anpassung der Größe an das Modell
14
- image = np.array(image) / 255.0 # Normalisieren
15
- image = np.expand_dims(image, axis=0) # Hinzufügen der Batch-Dimension
16
-
17
- # Vorhersage machen
18
- prediction = model.predict(image).flatten()
19
- classes = ['Abra', 'Ditto', 'Gengar'] # Namen der Klassen
20
-
21
- # Wahrscheinlichkeiten mit Klassen verbinden und formatieren
22
- return {classes[i]: float(prediction[i]) for i in range(len(classes))}
23
-
24
- # Gradio-Interface erstellen
25
- input_image = gr.Image()
26
- iface = gr.Interface(
27
- fn=classify_image,
28
- inputs=input_image,
29
- outputs=gr.Label(num_top_classes=3),
30
- examples=["pokemon/Abra/00000000.png", "pokemon/Ditto/00000000.jpg", "pokemon/Gengar/00000000.png"], # Beispiele hinzufügen
31
- description="Upload an image of a Pokémon to classify it as Pikachu, Charmander, or Bulbasaur."
32
- )
33
-
34
- # Interface starten
35
  iface.launch()
 
1
+ import gradio as gr
2
+ import tensorflow as tf
3
+ from PIL import Image
4
+ import numpy as np
5
+
6
+
7
+ # Modell laden
8
+ model = tf.keras.models.load_model('pokemon_classifier.keras')
9
+
10
+ def classify_image(image):
11
+ # Bild vorverarbeiten
12
+ image = Image.fromarray(image.astype('uint8')).convert('RGB')
13
+ image = image.resize((150, 150)) # Anpassung der Größe an das Modell
14
+ image = np.array(image) / 255.0 # Normalisieren
15
+ image = np.expand_dims(image, axis=0) # Hinzufügen der Batch-Dimension
16
+
17
+ # Vorhersage machen
18
+ prediction = model.predict(image).flatten()
19
+ classes = ['Abra', 'Ditto', 'Gengar'] # Namen der Klassen
20
+
21
+ # Wahrscheinlichkeiten mit Klassen verbinden und formatieren
22
+ return {classes[i]: float(prediction[i]) for i in range(len(classes))}
23
+
24
+ # Gradio-Interface erstellen
25
+ input_image = gr.Image()
26
+ iface = gr.Interface(
27
+ fn=classify_image,
28
+ inputs=input_image,
29
+ outputs=gr.Label(num_top_classes=3),
30
+ examples=["pokemon/Abra/00000000.png", "pokemon/Ditto/00000000.jpg", "pokemon/Gengar/00000000.png"], # Beispiele hinzufügen
31
+ description="Upload an image of a Pokémon to classify it as Pikachu, Charmander, or Bulbasaur."
32
+ )
33
+
34
+ # Interface starten
35
  iface.launch()