franckew commited on
Commit
177054a
1 Parent(s): 300fe01

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -19
app.py CHANGED
@@ -2,29 +2,29 @@ import gradio as gr
2
  from PIL import Image
3
  import numpy as np
4
  from tensorflow.keras.preprocessing import image as keras_image
5
- from tensorflow.keras.applications.resnet50 import preprocess_input
6
  from tensorflow.keras.models import load_model
7
 
8
- # Load your trained model
9
- model = load_model('/home/user/app/one_piece_character_classifier.h5') # Ensure this path is correct
10
 
11
- def predict_pokemon(img):
12
- img = Image.fromarray(img.astype('uint8'), 'RGB') # Ensure the image is in RGB
13
- img = img.resize((224, 224)) # Resize the image properly using PIL
14
- img_array = keras_image.img_to_array(img) # Convert the image to an array
15
- img_array = np.expand_dims(img_array, axis=0) # Expand dimensions to fit model input
16
- img_array = preprocess_input(img_array) # Preprocess the input as expected by ResNet50
17
 
18
- prediction = model.predict(img_array) # Predict using the model
19
- classes = ['Brook', 'Chopper', 'Zoro' ] # Specific Pokémon names
20
- return {classes[i]: float(prediction[0][i]) for i in range(3)} # Return the prediction
21
 
22
- # Define Gradio interface
23
- interface = gr.Interface(fn=predict_pokemon,
24
- inputs="image", # Simplified input type
25
- outputs="label", # Simplified output type
26
  title="One Piece Classifier",
27
- description="Upload an image of a OP Character and the classifier will predict its name.")
28
 
29
- # Launch the interface
30
- interface.launch()
 
2
  from PIL import Image
3
  import numpy as np
4
  from tensorflow.keras.preprocessing import image as keras_image
5
+ from tensorflow.keras.applications.inception_v3 import preprocess_input
6
  from tensorflow.keras.models import load_model
7
 
8
+ # Lade dein trainiertes Modell
9
+ model = load_model('/home/user/app/one_piece_character_classifier.h5') # Stelle sicher, dass dieser Pfad korrekt ist
10
 
11
+ def predict_character(img):
12
+ img = Image.fromarray(img.astype('uint8'), 'RGB') # Stelle sicher, dass das Bild im RGB-Format vorliegt
13
+ img = img.resize((299, 299)) # Größe des Bildes anpassen für InceptionV3
14
+ img_array = keras_image.img_to_array(img) # Bild in ein Array umwandeln
15
+ img_array = np.expand_dims(img_array, axis=0) # Dimensionen erweitern, um dem Model-Input zu entsprechen
16
+ img_array = preprocess_input(img_array) # Input für InceptionV3 vorverarbeiten
17
 
18
+ prediction = model.predict(img_array) # Vorhersage mit dem Modell
19
+ classes = ['Brook', 'Chopper', 'Zoro'] # Spezifische Charakter-Namen
20
+ return {classes[i]: float(prediction[0][i]) for i in range(3)} # Vorhersage zurückgeben
21
 
22
+ # Definiere das Gradio-Interface
23
+ interface = gr.Interface(fn=predict_character,
24
+ inputs="image", # Vereinfachter Eingabetyp
25
+ outputs="label", # Vereinfachter Ausgabetyp
26
  title="One Piece Classifier",
27
+ description="Lade ein Bild eines OP-Charakters hoch und der Klassifikator wird den Namen vorhersagen.")
28
 
29
+ # Starte das Interface
30
+ interface.launch()