friesti1 commited on
Commit
0c59e8e
1 Parent(s): e85fdbb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -23
app.py CHANGED
@@ -1,39 +1,35 @@
1
- %pip install tensorflow==2.15
2
  import gradio as gr
3
  import tensorflow as tf
4
  from PIL import Image
5
  import numpy as np
6
-
7
-
8
- labels = ['Cubone', 'Ditto', 'Psyduck', 'Snorlax', 'Weedle']
9
-
10
  def predict_pokemon_type(uploaded_file):
11
- """Process the uploaded file and return the image of the most likely Pokémon."""
12
  if uploaded_file is None:
13
  return "No file uploaded."
14
-
15
- model = tf.keras.models.load_model('pokemon-model_transferlearning.keras')
 
16
  with Image.open(uploaded_file) as img:
17
- img = img.resize((150, 150))
18
  img_array = np.array(img)
19
-
20
  prediction = model.predict(np.expand_dims(img_array, axis=0))
21
- max_index = np.argmax(prediction)
22
- predicted_pokemon = labels[max_index]
23
-
24
- # Load and return the image of the predicted Pokémon
25
- result_img_path = f'pokemon_images/{predicted_pokemon}.jpg'
26
- result_img = Image.open(result_img_path)
27
- return result_img
28
-
29
  # Define the Gradio interface
30
  iface = gr.Interface(
31
  fn=predict_pokemon_type, # Function to process the input
32
  inputs=gr.File(label="Upload File"), # File upload widget
33
- outputs=gr.Image(), # Output type is now an image
34
- title="Pokemon Classifier",
35
- description="Upload a picture of a pokemon (preferably Cubone, Ditto, Psyduck, Snorlax, or Weedle), because the model was trained on 'em. 87.5% accuracy :)"
36
  )
37
-
38
  # Launch the interface
39
- iface.launch()
 
 
1
  import gradio as gr
2
  import tensorflow as tf
3
  from PIL import Image
4
  import numpy as np
5
+
6
+ labels = ['Gengar', 'Seel', 'Zapdos']
7
+
 
8
  def predict_pokemon_type(uploaded_file):
9
+
10
  if uploaded_file is None:
11
  return "No file uploaded."
12
+
13
+ model = tf.keras.models.load_model('Gengar-vs-Seel-vs-Zapdos-model_transferlearning.keras')
14
+ # Load the image from the file path
15
  with Image.open(uploaded_file) as img:
16
+ img = img.resize((150, 150)).convert('RGB') # Convert image to RGB
17
  img_array = np.array(img)
18
+
19
  prediction = model.predict(np.expand_dims(img_array, axis=0))
20
+ confidences = {labels[i]: np.round(float(prediction[0][i]), 2) for i in range(len(labels))}
21
+
22
+ return confidences
23
+
24
+
 
 
 
25
  # Define the Gradio interface
26
  iface = gr.Interface(
27
  fn=predict_pokemon_type, # Function to process the input
28
  inputs=gr.File(label="Upload File"), # File upload widget
29
+ outputs="text", # Output type
30
+ title="Pokemon Classifier", # Title of the interface
31
+ description="Upload a picture of a pokemon (preferably Gengar, Seel, Zapdos)" # Description of the interface
32
  )
33
+
34
  # Launch the interface
35
+ iface.launch()