grobram1 commited on
Commit
168e71d
·
verified ·
1 Parent(s): 8c73c82

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -45
app.py CHANGED
@@ -1,45 +1,45 @@
1
- import gradio as gr
2
- import tensorflow as tf
3
- from PIL import Image
4
- import numpy as np
5
-
6
- # Modellpfad relativ zum aktuellen Arbeitsverzeichnis
7
- model_path = 'models/chess_piece_classifier.keras'
8
-
9
- # Modell laden
10
- model = tf.keras.models.load_model(model_path)
11
-
12
- # Klassenlabels (Passe diese entsprechend deinem Modell an)
13
- labels = ['Black bishop', 'Black king', 'Black knight', 'Black pawn', 'Black queen', 'Black rook', 'White bishop', 'White king', 'White knight', 'White pawn', 'White queen', 'White rook']
14
-
15
- # Vorhersagefunktion
16
- def predict(image):
17
- try:
18
- # Bildvorverarbeitung
19
- image = image.resize((224, 224)) # Bildgröße auf 224x224 ändern
20
- image = np.array(image) / 255.0
21
- image = np.expand_dims(image, axis=0)
22
-
23
- # Vorhersage
24
- predictions = model.predict(image)
25
- confidences = {labels[i]: float(predictions[0][i]) for i in range(len(labels))}
26
-
27
- return confidences
28
- except Exception as e:
29
- return str(e) # Fehlernachricht zurückgeben
30
-
31
- # Gradio-Interface erstellen
32
- iface = gr.Interface(
33
- fn=predict,
34
- inputs=gr.Image(type="pil"), # Bild als PIL-Objekt
35
- outputs=gr.Label(),
36
- description="Chess Piece Classifier",
37
- examples=[
38
- ['data/example1.png'],
39
- ['data/example2.png'],
40
- ['data/example3.png']
41
- ]
42
- )
43
-
44
- if __name__ == "__main__":
45
- iface.launch()
 
1
+ import gradio as gr
2
+ import tensorflow as tf
3
+ from PIL import Image
4
+ import numpy as np
5
+
6
+ # Modellpfad relativ zum aktuellen Arbeitsverzeichnis
7
+ model_path = 'chess_piece_classifier.keras'
8
+
9
+ # Modell laden
10
+ model = tf.keras.models.load_model(model_path)
11
+
12
+ # Klassenlabels (Passe diese entsprechend deinem Modell an)
13
+ labels = ['Black bishop', 'Black king', 'Black knight', 'Black pawn', 'Black queen', 'Black rook', 'White bishop', 'White king', 'White knight', 'White pawn', 'White queen', 'White rook']
14
+
15
+ # Vorhersagefunktion
16
+ def predict(image):
17
+ try:
18
+ # Bildvorverarbeitung
19
+ image = image.resize((224, 224)) # Bildgröße auf 224x224 ändern
20
+ image = np.array(image) / 255.0
21
+ image = np.expand_dims(image, axis=0)
22
+
23
+ # Vorhersage
24
+ predictions = model.predict(image)
25
+ confidences = {labels[i]: float(predictions[0][i]) for i in range(len(labels))}
26
+
27
+ return confidences
28
+ except Exception as e:
29
+ return str(e) # Fehlernachricht zurückgeben
30
+
31
+ # Gradio-Interface erstellen
32
+ iface = gr.Interface(
33
+ fn=predict,
34
+ inputs=gr.Image(type="pil"), # Bild als PIL-Objekt
35
+ outputs=gr.Label(),
36
+ description="Chess Piece Classifier",
37
+ examples=[
38
+ ['data/example1.png'],
39
+ ['data/example2.png'],
40
+ ['data/example3.png']
41
+ ]
42
+ )
43
+
44
+ if __name__ == "__main__":
45
+ iface.launch()