grobram1 commited on
Commit
5ab1783
·
verified ·
1 Parent(s): 4de2db6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -8
app.py CHANGED
@@ -17,21 +17,28 @@ labels = ['Abra', 'Cloyster', 'Dodrio']
17
 
18
  # Vorhersagefunktion
19
  def predict(image):
20
- # Bildvorverarbeitung
21
- image = image.resize((64, 64))
22
- image = np.array(image) / 255.0
23
- image = np.expand_dims(image, axis=0)
24
- predictions = model.predict(image)
25
- confidences = {labels[i]: float(predictions[0][i]) for i in range(len(labels))}
26
- return confidences
 
 
 
 
 
 
27
 
28
  # Gradio-Interface erstellen
29
  iface = gr.Interface(
30
  fn=predict,
31
- inputs=gr.Image(), # Keine shape-Parameter hier
32
  outputs=gr.Label(),
33
  description="Pokémon Classifier"
34
  )
35
 
36
  if __name__ == "__main__":
37
  iface.launch()
 
 
17
 
18
  # Vorhersagefunktion
19
  def predict(image):
20
+ try:
21
+ # Bildvorverarbeitung
22
+ image = image.resize((64, 64))
23
+ image = np.array(image) / 255.0
24
+ image = np.expand_dims(image, axis=0)
25
+
26
+ # Vorhersage
27
+ predictions = model.predict(image)
28
+ confidences = {labels[i]: float(predictions[0][i]) for i in range(len(labels))}
29
+
30
+ return confidences
31
+ except Exception as e:
32
+ return str(e) # Fehlernachricht zurückgeben
33
 
34
  # Gradio-Interface erstellen
35
  iface = gr.Interface(
36
  fn=predict,
37
+ inputs=gr.Image(type="pil"), # Bild als PIL-Objekt
38
  outputs=gr.Label(),
39
  description="Pokémon Classifier"
40
  )
41
 
42
  if __name__ == "__main__":
43
  iface.launch()
44
+