PhDFlo's picture
correction
1c0c20f
from fastai.vision.all import *
import gradio as gr
import torch
import sys
import fastai
from pathlib import Path
print(f"Python version: {sys.version}")
print(f"Torch version: {torch.__version__}")
print(f"Fastai version: {fastai.__version__}")
try:
# Load the model with CPU as default device
learn = load_learner('model_champi.pkl', cpu=True)
print("Model loaded successfully!")
except TypeError as e:
print("Error: Model version incompatibility detected.")
print("This usually happens when the model was saved with a different PyTorch version.")
print("Please retrain the model using the current environment versions.")
raise e
except Exception as e:
print(f"Unexpected error loading model: {str(e)}")
raise e
categories = ('Amanita', 'Boletus', 'Morchella', 'Truffle')
def classify_image(img):
pred,idx,probs = learn.predict(img)
return dict(zip(categories, map(float,probs)))
image = gr.Image(height=192, width=192)
label = gr.Label()
examples = ['amanita.jpg', 'truffle.jpg', "boletus.jpg"]
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
intf.launch(share=True)