Spaces:
Sleeping
Sleeping
File size: 903 Bytes
50b0072 44723e0 50b0072 ccd7a2c 50b0072 ccd7a2c 50b0072 ccd7a2c 50b0072 ccd7a2c 50b0072 ccd7a2c 50b0072 ccd7a2c 50b0072 ccd7a2c 50b0072 ccd7a2c 50b0072 ccd7a2c 50b0072 ccd7a2c 50b0072 ce8f693 50b0072 ce8f693 50b0072 ccd7a2c 50b0072 |
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 40 41 42 43 44 45 46 47 48 49 50 51 52 |
import numpy as np
from sklearn import svm
from sklearn.metrics import accuracy_score
from tensorflow import keras
import gradio as gr
(x_train, y_train), (x_test, y_test) = keras.datasets.mnist.load_data()
x_train = x_train.reshape(-1, 28*28) / 255.0
x_test = x_test.reshape(-1, 28*28) / 255.0
clf = svm.SVC()
clf.fit(x_train, y_train)
y_pred = clf.predict(x_test)
accuracy = accuracy_score(y_test, y_pred)
print(f"Accuracy: {accuracy}")
def classify_digit(image):
image = image.reshape(1, 28*28) / 255.0
pred = clf.predict(image)
return int(pred[0])
interface = gr.Interface(
fn=classify_digit,
inputs=gr.Sketchpad(invert_colors=True),
outputs=gr.Text(),
title="MNIST Digit Classifier",
description="Draw a digit on the sketchpad and click 'Submit' to classify it , Draw in centre for better accuracy",
theme="default"
)
interface.launch()
|