File size: 1,466 Bytes
22d4b15
 
 
 
 
 
 
 
7e10c95
22d4b15
5c0a429
22d4b15
 
 
 
 
c30623a
c8a1d50
 
 
5c1cf37
 
 
22d4b15
5c1cf37
22d4b15
 
 
5c1cf37
22d4b15
 
 
29ba062
22d4b15
 
a0781a3
c8a1d50
 
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
30
31
32
33
34
35
36
37
38
39
import gradio as gr
import tensorflow as tf
from PIL import Image
import numpy as np

# Load your custom regression model
model_path = "pokemon.keras"
model = tf.keras.models.load_model(model_path)
model.summary()  # Check if the model architecture loaded matches the expected one

labels = ['Abra', 'Aerodactyl', 'Alakazam', 'Arbok', 'Arcanine']

# 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))
    # If model expects RGB, convert to RGB
    image = image.convert('RGB')  # Ensure image is in RGB format


    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=["images/abra.gif", "images/Aerodactyl.png", "images/Alakazam.png", "images/arbok.jpg", "images/Arcanine.png" ], 
                         description="A simple mlp classification model for image classification using a few pokemons.")
interface.launch()