Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,34 +1,27 @@
|
|
1 |
import gradio as gr
|
2 |
-
|
3 |
-
from
|
4 |
import numpy as np
|
5 |
|
6 |
-
#
|
7 |
-
|
8 |
|
9 |
-
|
10 |
-
|
|
|
|
|
|
|
11 |
|
12 |
-
|
|
|
|
|
13 |
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
image
|
20 |
-
|
21 |
-
# Predict
|
22 |
-
prediction = model.predict(image[None, ...]) # Assuming single regression value
|
23 |
-
confidences = {labels[i]: np.round(float(prediction[0][i]), 2) for i in range(len(labels))}
|
24 |
-
return confidences
|
25 |
|
26 |
-
|
27 |
-
input_image = gr.Image()
|
28 |
-
output_text = gr.Textbox(label="Predicted Value")
|
29 |
-
interface = gr.Interface(fn=predict_regression,
|
30 |
-
inputs=input_image,
|
31 |
-
outputs=gr.Label(),
|
32 |
-
examples=["images/0.jpeg", "images/1.jpeg", "images/2.jpeg", "images/5.jpeg"],
|
33 |
-
description="A simple mlp classification model for image classification using the mnist dataset.")
|
34 |
-
interface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
from tensorflow.keras.models import load_model
|
3 |
+
from tensorflow.keras.preprocessing.image import img_to_array, load_img
|
4 |
import numpy as np
|
5 |
|
6 |
+
# Modell laden
|
7 |
+
model = load_model('pokemon-model.keras')
|
8 |
|
9 |
+
def classify_image(image):
|
10 |
+
image = image.resize((224, 224)) # passende Größe für das Modell
|
11 |
+
image = img_to_array(image) # Bild in Array umwandeln
|
12 |
+
image = np.expand_dims(image, axis=0) # Dimension hinzufügen
|
13 |
+
image /= 255.0 # Normalisierung
|
14 |
|
15 |
+
prediction = model.predict(image) # Vorhersage vom Modell
|
16 |
+
classes = ['Squirtle', 'Pikachu', 'Charizard', 'Butterfree'] # Klassen
|
17 |
+
return {classes[i]: float(prediction[0][i]) for i in range(4)} # Wahrscheinlichkeiten zurückgeben
|
18 |
|
19 |
+
iface = gr.Interface(
|
20 |
+
classify_image,
|
21 |
+
gr.inputs.Image(shape=(224, 224)),
|
22 |
+
gr.outputs.Label(num_top_classes=4),
|
23 |
+
title="Pokémon Classifier",
|
24 |
+
description="Upload an image of a Pokémon and see the model classify it!"
|
25 |
+
)
|
|
|
|
|
|
|
|
|
26 |
|
27 |
+
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|