CoolFace
Apppublic

VSakhi/classification-1

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
app.py38 linesDownload Raw Back to root
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