grobram1 commited on
Commit
1489275
·
verified ·
1 Parent(s): 31f49a0

Delete app.py

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