Spaces:
Sleeping
Sleeping
from fastai.vision.all import * | |
import gradio as gr | |
# Load the trained model | |
learn = load_learner("model.pkl") # Ensure "model.pkl" is in the working directory | |
# Define a function to predict the class | |
def predict(img): | |
pred, pred_idx, probs = learn.predict(img) | |
return {learn.dls.vocab[i]: float(probs[i]) for i in range(len(probs))} | |
# Create a Gradio interface | |
interface = gr.Interface(fn=predict, inputs=gr.Image(type="pil"), outputs=gr.Label()) | |
# Launch the app | |
interface.launch() | |