Spaces:
Runtime error
Runtime error
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() |