friesti1 commited on
Commit
a3ea565
1 Parent(s): 76391f1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -8
app.py CHANGED
@@ -3,13 +3,13 @@ import tensorflow as tf
3
  from PIL import Image
4
  import numpy as np
5
 
6
- labels = ['Cubone', 'Ditto', 'Psyduck', 'Snorlax', 'Weedle']
7
 
8
  def predict_pokemon_type(uploaded_file):
9
  if uploaded_file is None:
10
  return "No file uploaded.", None, "No prediction"
11
 
12
- model = tf.keras.models.load_model('pokemon-model.keras')
13
 
14
  # Load the image from the file path
15
  with Image.open(uploaded_file) as img:
@@ -17,18 +17,19 @@ def predict_pokemon_type(uploaded_file):
17
  img_array = np.array(img)
18
 
19
  prediction = model.predict(np.expand_dims(img_array, axis=0))
20
-
 
21
  confidences = {labels[i]: np.round(float(prediction[0][i]), 2) for i in range(len(labels))}
22
 
23
  return img, confidences
24
 
25
  # Define the Gradio interface
26
  iface = gr.Interface(
27
- fn=predict_pokemon_type,
28
- inputs=gr.File(label="Upload File"),
29
- outputs=["image", "text"],
30
- title="Pokemon Classifier",
31
- description="Upload a picture of a Pokemon (preferably Cubone, Ditto, Psyduck, Snorlax, or Weedle) to see its type and confidence level. The trained model has a test accuracy of 99.17%!"
32
  )
33
 
34
  # Launch the interface
 
3
  from PIL import Image
4
  import numpy as np
5
 
6
+ labels = ['Birch Forest', 'Cave', 'Cherry Grove', 'Dark Forest', 'Deep Dark', 'Desert', 'End', 'Forest', 'Jungle', 'Mushroom Fields', 'Nether', 'Ocean', 'Plains', 'Savanna', 'Swamp', 'Taiga']
7
 
8
  def predict_pokemon_type(uploaded_file):
9
  if uploaded_file is None:
10
  return "No file uploaded.", None, "No prediction"
11
 
12
+ model = tf.keras.models.load_model('biomes-xception-model.keras')
13
 
14
  # Load the image from the file path
15
  with Image.open(uploaded_file) as img:
 
17
  img_array = np.array(img)
18
 
19
  prediction = model.predict(np.expand_dims(img_array, axis=0))
20
+
21
+ # Identify the most confident prediction
22
  confidences = {labels[i]: np.round(float(prediction[0][i]), 2) for i in range(len(labels))}
23
 
24
  return img, confidences
25
 
26
  # Define the Gradio interface
27
  iface = gr.Interface(
28
+ fn=predict_pokemon_type, # Function to process the input
29
+ inputs=gr.File(label="Upload File"), # File upload widget
30
+ outputs=["image", "text"], # Output types for image and text
31
+ title="Minecraft Biomes Classifier", # Title of the interface
32
+ description="Upload a picture of a Fruit (preferably a Birch Forest, Cave, Cherry Grove, Dark Forest, Deep Dark, Desert, End, Forest, Jungle, Mushroom Fields, Nether, Ocean, Plains, Savanna, Swamp or Taiga) to see what fruit it is and the models confidence level." # Description of the interface
33
  )
34
 
35
  # Launch the interface