File size: 660 Bytes
dbc7ca3
 
 
 
 
 
676d2b9
dbc7ca3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import gradio as gr
from fastai.vision.all import *
import pathlib
import os

# Load the exported model
learn = load_learner("model_mnist.pkl")

# Define prediction function
def predict(img):
    pred, pred_idx, probs = learn.predict(img)
    return f"Prediction: {pred} (Confidence: {probs[pred_idx]:.4f})"

# Create Gradio interface
interface = gr.Interface(
    fn=predict,
    inputs=gr.Image(type="pil", label="Upload a digit image (3 or 7 only)"),
    outputs="text",
    title="MNIST Digit Classifier (3 vs 7)",
    description="Upload an image of a handwritten digit. Only digits 3 and 7 will work!"
)

if __name__ == "__main__":
    interface.launch()