File size: 805 Bytes
62f2f27
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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)