Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import tensorflow as tf
|
3 |
+
from PIL import Image
|
4 |
+
import numpy as np
|
5 |
+
|
6 |
+
# Load your custom regression model
|
7 |
+
model_path = "pokemon.keras"
|
8 |
+
model = tf.keras.models.load_model(model_path)
|
9 |
+
|
10 |
+
labels = ['Aerodactyl', 'Arbok', 'Alakazam', 'Abra', 'Arcanine']
|
11 |
+
|
12 |
+
# Define regression function
|
13 |
+
def predict_regression(image):
|
14 |
+
# Preprocess image
|
15 |
+
image = Image.fromarray(image.astype('uint8')) # Convert numpy array to PIL image
|
16 |
+
image = image.resize((28, 28)).convert('L') #resize the image to 28x28 and converts it to gray scale
|
17 |
+
image = np.array(image)
|
18 |
+
print(image.shape)
|
19 |
+
# Predict
|
20 |
+
prediction = model.predict(image[None, ...]) # Assuming single regression value
|
21 |
+
confidences = {labels[i]: np.round(float(prediction[0][i]), 2) for i in range(len(labels))}
|
22 |
+
return confidences
|
23 |
+
|
24 |
+
# Create Gradio interface
|
25 |
+
input_image = gr.Image()
|
26 |
+
output_text = gr.Textbox(label="Predicted Value")
|
27 |
+
interface = gr.Interface(fn=predict_regression,
|
28 |
+
inputs=input_image,
|
29 |
+
outputs=gr.Label(),
|
30 |
+
examples=["images/Aerodactyl.png", "images/arbok.jpg", "images/Alakazam.png", "images/abra.gif","images/Arcanine.png"],
|
31 |
+
description="A simple mlp classification model for image classification using the mnist dataset.")
|
32 |
+
interface.launch()
|