Spaces:
Sleeping
Sleeping
File size: 705 Bytes
c58a525 |
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 |
import gradio as gr
import pickle
import numpy as np
# Load your model
with open('your_mnist_model.pkl', 'rb') as f:
model = pickle.load(f)
def predict(image):
# Preprocess the image
image = image.reshape(1, 28, 28) / 255.0 # Normalize to 0-1
# Make prediction
probabilities = model.predict_proba(image.reshape(1, -1))[0]
# Format output
return {str(i): float(prob) for i, prob in enumerate(probabilities)}
iface = gr.Interface(
fn=predict,
inputs=gr.Sketchpad(shape=(28, 28)),
outputs=gr.Label(num_top_classes=10),
title="MNIST Digit Classifier",
description="Draw a digit (0-9) in the canvas and the model will predict it."
)
iface.launch() |