Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from model_service import ACCURACY, predict_digit | |
| with gr.Blocks(title="MNIST Digit API") as demo: | |
| gr.Markdown("# MNIST Digit API") | |
| gr.Markdown(f"Model-as-a-service endpoint. Test accuracy: `{ACCURACY:.4f}`.") | |
| gr.Markdown("Use a clear, centered, high-contrast digit image.") | |
| image = gr.Image( | |
| label="Digit image", | |
| image_mode="L", | |
| type="numpy", | |
| sources=["upload", "clipboard"], | |
| ) | |
| digit = gr.Textbox(label="Predicted digit") | |
| confidence = gr.Number(label="Confidence") | |
| probabilities = gr.Label(label="Probabilities") | |
| preview = gr.Image(label="28x28 model input", image_mode="L") | |
| gr.Button("Predict").click( | |
| predict_digit, | |
| inputs=image, | |
| outputs=[digit, confidence, probabilities, preview], | |
| api_name="predict_digit", | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch(show_error=True) | |