friesti1 commited on
Commit
4f80c2a
1 Parent(s): 277ceed

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -8
app.py CHANGED
@@ -9,7 +9,7 @@ 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_transferlearning.keras')
13
 
14
  # Load the image from the file path
15
  with Image.open(uploaded_file) as img:
@@ -17,20 +17,18 @@ 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
- confidences = {labels[i]: np.round(float(prediction[0][i]), 2) for i in range(len(labels))}
21
 
22
- # Identify the most confident prediction
23
  confidences = {labels[i]: np.round(float(prediction[0][i]), 2) for i in range(len(labels))}
24
 
25
  return img, confidences
26
 
27
  # Define the Gradio interface
28
  iface = gr.Interface(
29
- fn=predict_pokemon_type, # Function to process the input
30
- inputs=gr.File(label="Upload File"), # File upload widget
31
- outputs=["image", "text"], # Output types for image and text
32
- title="Pokemon Classifier", # Title of the interface
33
- 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 an accuracy of 96%!" # Description of the interface
34
  )
35
 
36
  # Launch the interface
 
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
  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