Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from PIL import Image | |
| import numpy as np | |
| from tensorflow.keras.preprocessing import image as keras_image | |
| from tensorflow.keras.applications.resnet50 import preprocess_input | |
| from tensorflow.keras.models import load_model | |
| # Load your trained modelC:\Daten\Studium Wirtsc | |
| model = load_model('/home/user/app/model.h5') # Ensure this path is correct | |
| def predict_teigwaren(img): | |
| img = Image.fromarray(img.astype('uint8'), 'RGB') # Ensure the image is in RGB | |
| img = img.resize((224, 224)) # Resize the image properly using PIL | |
| img_array = keras_image.img_to_array(img) # Convert the image to an array | |
| img_array = np.expand_dims(img_array, axis=0) # Expand dimensions to fit model input | |
| img_array = preprocess_input(img_array) # Preprocess the input as expected by ResNet50 | |
| prediction = model.predict(img_array) # Predict using the model | |
| classes = ['Mafaldine', 'Spaghetti', 'Tagliatelle' ] # Specific Teigwaren names | |
| return {classes[i]: float(prediction[0][i]) for i in range(3)} # Return the prediction | |
| # Define Gradio interface | |
| interface = gr.Interface(fn=predict_teigwaren, | |
| inputs="image", # Simplified input type | |
| outputs="label", # Simplified output type | |
| title="Teigwaren Classifier", | |
| description="Lade ein Bild von einer Teigwarensorte hoch und lass den KI-Algorithmus die Sorte bestimmen.") | |
| # Launch the interface | |
| interface.launch() | |