Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import tensorflow as tf | |
| from PIL import Image | |
| import numpy as np | |
| # Lade dein Modell (hier als Beispiel die Keras .h5 Datei) | |
| model = tf.keras.models.load_model('gym_equipment_transferlearning.keras') | |
| # Klassennamen, sollten deinem Dataset entsprechen | |
| class_names = ['benchPress', 'dumbBell', 'kettleBell', 'treadMill'] | |
| def classify_image(image): | |
| image = Image.fromarray(image.astype('uint8'), 'RGB') | |
| img = image.resize((150, 150)) | |
| img_array = tf.keras.preprocessing.image.img_to_array(img) | |
| img_array = tf.expand_dims(img_array, 0) # Erstelle einen Batch | |
| predictions = model.predict(img_array) | |
| predicted_class = class_names[np.argmax(predictions[0])] | |
| confidence = np.max(predictions[0]) | |
| return {predicted_class: float(confidence)} | |
| image_input = gr.Image() # Entferne den `shape` Parameter | |
| label = gr.Label(num_top_classes=3) | |
| iface = gr.Interface( | |
| fn=classify_image, | |
| inputs=image_input, | |
| outputs=label, | |
| title='Gym Equipment Classifier', | |
| description='Upload an image of gym equipment and the classifier will tell you which one it is and the confidence level of the prediction.' | |
| ) | |
| # Launch the interface | |
| iface.launch() |