anderni2 commited on
Commit
18604a2
·
verified ·
1 Parent(s): 723cb49

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -6
app.py CHANGED
@@ -12,16 +12,17 @@ model = tf.keras.models.load_model('Task_Pokemon.keras')
12
  class_names = ['Aerodactyl', 'Charizard', 'Victreebel']
13
 
14
  def classify_image(image):
15
- img_pil = image.resize((160, 160)) # Definieren der Größe der Bilder
16
- img_array = tf.keras.preprocessing.image.img_to_array(img_pil)
17
- img_array = tf.expand_dims(img_array, 0) # Erstellen eines Batches
 
18
  predictions = model.predict(img_array)
19
  predicted_class = class_names[np.argmax(predictions[0])]
20
  confidence = np.max(predictions[0])
21
- return predicted_class, confidence
22
 
23
- image_input = gr.inputs.Image()
24
- label = gr.outputs.Label(num_top_classes=3)
25
 
26
  iface = gr.Interface(
27
  fn=classify_image,
@@ -32,3 +33,5 @@ iface = gr.Interface(
32
  )
33
 
34
  iface.launch()
 
 
 
12
  class_names = ['Aerodactyl', 'Charizard', 'Victreebel']
13
 
14
  def classify_image(image):
15
+ image = Image.fromarray(image.astype('uint8'), 'RGB')
16
+ img = image.resize((150, 150))
17
+ img_array = tf.keras.preprocessing.image.img_to_array(img)
18
+ img_array = tf.expand_dims(img_array, 0) # Erstelle einen Batch
19
  predictions = model.predict(img_array)
20
  predicted_class = class_names[np.argmax(predictions[0])]
21
  confidence = np.max(predictions[0])
22
+ return {predicted_class: float(confidence)}
23
 
24
+ image_input = gr.Image()
25
+ label = gr.Label(num_top_classes=3)
26
 
27
  iface = gr.Interface(
28
  fn=classify_image,
 
33
  )
34
 
35
  iface.launch()
36
+
37
+