Spaces:
Sleeping
Sleeping
| # prompt: gradio image 分类 | |
| import fastai | |
| from fastai.vision import * | |
| from fastai.vision.all import load_learner,PILImage | |
| import gradio as gr | |
| # Load the model | |
| model = load_learner("model.pkl") | |
| # Define an image classification function | |
| def classify_image(image): | |
| img = PILImage.create(image) | |
| # Make a prediction | |
| pred_class, pred_idx, probs = model.predict(img) | |
| # Return the prediction as a dictionary | |
| return {model.dls.vocab[i]: float(probs[i]) for i in range(len(probs))} | |
| # Create the Gradio interface | |
| image_input = gr.Image() | |
| label_output = gr.Label(num_top_classes=3) | |
| interface = gr.Interface(fn=classify_image, inputs=image_input, outputs=label_output) | |
| # Launch the interface | |
| interface.launch() |