diff --git a/demo/basic_text.py b/demo/basic_text.py index 6593b01d4f..8711de8b0a 100644 --- a/demo/basic_text.py +++ b/demo/basic_text.py @@ -1,5 +1,5 @@ import gradio as gr -from time import sleep + def answer_question(quantity, animal, place, activity_list, morning, etc): return f"""The {quantity} {animal}s went to the {place} where they {" and ".join(activity_list)} until the {"morning" if morning else "night"}""", "OK" @@ -15,8 +15,8 @@ gr.Interface(answer_question, gr.inputs.Textbox(default="What else?"), ], [ - gr.outputs.Textbox(lines=8), - gr.outputs.Textbox(lines=1), + gr.outputs.Textbox(), + gr.outputs.Textbox(), ], examples=[ [2, "cat", "park", ["ran", "swam"], True], diff --git a/demo/digit_classifier.py b/demo/digit_classifier.py index 37874d82a8..796e5a017f 100644 --- a/demo/digit_classifier.py +++ b/demo/digit_classifier.py @@ -5,7 +5,7 @@ from tensorflow.keras.layers import * import gradio as gr (x_train, y_train),(x_test, y_test) = tf.keras.datasets.mnist.load_data() -x_train, x_test = x_train.reshape(-1,784) / 255.0, x_test.reshape(-1,784) / 255.0 +x_train, x_test = x_train.reshape(-1, 784) / 255.0, x_test.reshape(-1,784) / 255.0 def get_trained_model(n): model = tf.keras.models.Sequential() @@ -23,6 +23,7 @@ def get_trained_model(n): print(model.evaluate(x_test, y_test)) return model + if not os.path.exists("models/mnist.h5"): model = get_trained_model(n=50000) model.save('models/mnist.h5') @@ -32,12 +33,14 @@ else: graph = tf.get_default_graph() sess = tf.keras.backend.get_session() + def recognize_digit(image): with graph.as_default(): with sess.as_default(): prediction = model.predict(image).tolist()[0] return {str(i): prediction[i] for i in range(10)} + gr.Interface( recognize_digit, gradio.inputs.Sketchpad(flatten=True),