gassmdav commited on
Commit
ee06b6f
1 Parent(s): bb59fb8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -25
app.py CHANGED
@@ -1,40 +1,36 @@
1
- import streamlit as st
2
  import tensorflow as tf
3
  from PIL import Image
4
  import numpy as np
5
 
6
- # Load the pre-trained Pokémon model
7
  model_path = "kia_pokemon_keras_model.h5"
8
  model = tf.keras.models.load_model(model_path)
9
 
10
- # Pokémon classifier labels
11
- labels = ['Bulbasaur', 'Charmander', 'Squirtle']
 
 
12
 
13
  def predict_pokemon(image):
14
- # Preprocess image
15
- image = Image.fromarray(np.array(image).astype('uint8')) # Convert to PIL image
16
- image = image.resize((224, 224)) # Resize image to 224x224
17
- image = np.array(image)
18
- image = np.expand_dims(image, axis=0) # Add batch dimension
19
-
20
  # Predict
21
  predictions = model.predict(image)
22
  prediction = np.argmax(predictions, axis=1)[0]
23
  confidence = np.max(predictions)
24
-
25
- # Prepare output
26
- result = f"Predicted Pokémon: {labels[prediction]} with confidence: {confidence:.2f}%"
27
  return result
28
 
29
- st.title("Pokémon Classifier")
30
-
31
- file_uploader = st.file_uploader("Upload an image of a Pokémon", type=['png', 'jpg', 'jpeg'])
32
-
33
- if file_uploader is not None:
34
- # Display the image
35
- image = Image.open(file_uploader)
36
- st.image(image, caption='Uploaded Image', use_column_width=True)
37
-
38
- # Make prediction
39
- result = predict_pokemon(image)
40
- st.subheader(result)
 
1
+ import gradio as gr
2
  import tensorflow as tf
3
  from PIL import Image
4
  import numpy as np
5
 
6
+ # Laden des vortrainierten Pokémon-Modells
7
  model_path = "kia_pokemon_keras_model.h5"
8
  model = tf.keras.models.load_model(model_path)
9
 
10
+ # Labels für den Pokémon Classifier
11
+ labels = [
12
+ 'Bulbasaur','Charmander','Squirtle'
13
+ ]
14
 
15
  def predict_pokemon(image):
 
 
 
 
 
 
16
  # Predict
17
  predictions = model.predict(image)
18
  prediction = np.argmax(predictions, axis=1)[0]
19
  confidence = np.max(predictions)
20
+
21
+ # Vorbereiten der Ausgabe
22
+ result = f"Predicted Pokémon: {labels[prediction]} with confidence: {confidence:.2f}"
23
  return result
24
 
25
+ # Erstellen der Gradio-Oberfläche
26
+ input_image = gr.Image()
27
+ output_label = gr.Label()
28
+ interface = gr.Interface(fn=predict_pokemon,
29
+ inputs=input_image,
30
+ outputs=output_label,
31
+ examples=["images/bulbasaur.png", "images/charmander.png", "images/squirtle.png"],
32
+ title="Pokémon Classifier",
33
+ description="Drag and drop an image or select an example below to predict the Pokémon.")
34
+
35
+ # Interface starten
36
+ interface.launch()