Spaces:
Sleeping
Sleeping
import gradio as gr | |
import tensorflow as tf | |
from PIL import Image | |
import numpy as np | |
# Lade das Modell | |
model = tf.keras.models.load_model("fruit_classifier_model_v2.keras") | |
class_names = ['Apple', 'Banana', 'Grapes', 'Kiwi', 'Orange', 'Pineapple', 'Strawberries'] | |
def classify_fruit(image): | |
image = Image.fromarray(image).resize((224, 224)) | |
image = np.array(image) / 255.0 | |
image = np.expand_dims(image, axis=0) | |
predictions = model.predict(image)[0] | |
results = {class_name: float(predictions[i]) for i, class_name in enumerate(class_names)} | |
return results | |
interface = gr.Interface( | |
fn=classify_fruit, | |
inputs=gr.Image(), | |
outputs=gr.Label(num_top_classes=7), | |
live=True | |
) | |
if __name__ == "__main__": | |
interface.launch(share=True) | |