| import gradio as gr |
| from fastai.vision.all import * |
|
|
| |
| learn = load_learner('model.pkl') |
|
|
| |
| def classify_image(input_img): |
| |
| input_img = PILImage.create(input_img) |
| pred, idx, probs = learn.predict(input_img) |
| return input_img, {learn.dls.vocab[i]: float(probs[i]) for i in range(len(probs))} |
|
|
| |
| gradio_app = gr.Interface( |
| fn=classify_image, |
| inputs=gr.Image(label="Upload Image", sources=['upload', 'webcam'], type="pil"), |
| outputs=[ |
| gr.Image(label="Processed Image"), |
| gr.Label(label="Prediction Results", num_top_classes=5) |
| ], |
| title="Image Classification App", |
| examples=["basset.jpg"] |
| ) |
|
|
| |
| if __name__ == "__main__": |
| gradio_app.launch() |