Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from fastai.vision.all import load_learner, PILImage | |
| # Load the pre-trained FastAI model | |
| model_path = "model.pkl" | |
| learn = load_learner(model_path) | |
| # Define the prediction function | |
| def predict(image): | |
| img = PILImage.create(image) | |
| pred_class, pred_idx, probs = learn.predict(img) | |
| return f"Prediction: {pred_class}, Probability: {probs[pred_idx]:.4f}" | |
| # Create the Gradio interface | |
| demo = gr.Interface( | |
| fn=predict, | |
| inputs=gr.Image(type="file"), | |
| outputs="text", | |
| title="Image validation", | |
| description="Upload an image and get the model's text prediction." | |
| ) | |
| demo.launch() | |