Slayer7's picture
Update app.py
ccd7a2c
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()