Spaces:
Runtime error
Runtime error
File size: 1,121 Bytes
45d6962 30ac140 |
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 |
import numpy as np
import matplotlib.pyplot as plt
from tensorflow.keras.datasets import mnist
from tensorflow import keras
import keras.backend as K
from tensorflow.keras.layers import Dense, Flatten, Reshape, Input, Lambda, BatchNormalization, Dropout
(x_train, y_train), (x_test, y_test) = mnist.load_data()
x_train = x_train / 255
x_test = x_test / 255
y_train = keras.utils.to_categorical(y_train, 10)
input_img = Input((28, 28))
x = Flatten()(input_img)
x = Dense(256, activation='relu')(x)
x = Dense(128, activation='relu')(x)
x = Dense(64, activation='relu')(x)
Classif = Dense(10, activation='softmax')(x)
model = keras.Model(input_img, Classif)
model.compile(optimizer='adam', loss='categorical_crossentropy')
model.fit(x_train, y_train, epochs=5, batch_size=30, shuffle=True)
import gradio as gr
import numpy as np
from huggingface_hub import from_pretrained_keras
model = from_pretrained_keras("ISYS/MyNewModel")
def greet(img):
img = np.expand_dims(img, axis=0)
return np.argmax(model.predict(img)[0])
iface = gr.Interface(fn=greet, inputs="sketchpad", outputs="text")
iface.launch() |