import gradio as gr import tensorflow as tf from PIL import Image import numpy as np # Load your custom regression model model_path = "Doggos.keras" model = tf.keras.models.load_model(model_path) labels = ['Bedlington_terrier', 'Bernese_mountain_dog', 'Dandie_Dinmont', 'Gordon_setter', 'Ibizan_hound', 'Norwegian_elkhound'] # corrected labels list # Define regression function def predict_regression(image): # Preprocess image image = Image.fromarray(image.astype('uint8')) # Convert numpy array to PIL image image = image.resize((150, 150)).convert('RGB') # Resize the image to 150x150 and convert to RGB image = np.array(image) print(image.shape) # Predict prediction = model.predict(image[None, ...]) # Assuming single regression value confidences = {labels[i]: np.round(float(prediction[0][i]), 2) for i in range(len(labels))} return confidences # Create Gradio interface input_image = gr.Image() output_text = gr.Textbox(label="Predicted Value") interface = gr.Interface(fn=predict_regression, inputs=input_image, outputs=gr.Label(), examples=["1.jpg","2.jpg","3.jpg","4.jpg","5.jpg","6.jpg"], description="Wer ist ein guter Junge? Du bist ein aber ganz feiner und braver Junge! hechel hechel hechel :)") interface.launch()