VSakhi/classification-1
0
1# app.py2from fastai.vision.all import *3import gradio as gr4import pathlib5 6# π§© Fix WindowsPath β PosixPath issue (for models trained on Windows)7import pathlib8temp = pathlib.PosixPath9pathlib.WindowsPath = temp10 11# π§ Load the trained model12learn = load_learner("export.pkl")13 14# πΆπ± Categories15categories = ('Dog', 'Cat')16 17# π Prediction function18def classify_images(img):19 pred, idx, probs = learn.predict(img)20 return {categories[i]: float(probs[i]) for i in range(len(categories))}21 22# πΌοΈ Gradio Interface23image = gr.Image(type="pil")24label = gr.Label()25examples = ['dog.jpg', 'cat.jpg'] # Optional demo examples26 27intf = gr.Interface(28 fn=classify_images,29 inputs=image,30 outputs=label,31 examples=examples,32 title="πΎ Dog vs Cat Classifier",33 description="Upload an image of a dog or a cat, and the model will predict which one it is!"34)35 36# π Launch the app37intf.launch()38 