Download app.py from Dharik/CNN: direct link, hf CLI and curl.
- Browser
- Download file 679 Bytes
-
https://huggingface.co/spaces/Dharik/CNN/resolve/main/app.py
- Command line
-
hf download hf://spaces/Dharik/CNN/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Dharik/CNN/resolve/main/app.py
679 Bytes
| import gradio as gr | |
| import numpy as np | |
| import time | |
| from fastai.vision.all import * | |
| from pathlib import Path | |
| #import pathlib | |
| path_to_model = Path("resnet50_classifier_0.55valloss") | |
| #temp = pathlib.PosixPath | |
| #pathlib.PosixPath = pathlib.WindowsPath | |
| model = load_learner(str(path_to_model)) | |
| model | |
| labels = model.dls.vocab | |
| def classify(img: np.ndarray): | |
| all_labels = [] | |
| pred_label, idx, proba = model.predict(img) | |
| return {label:prob for prob,label in zip( proba, labels )} | |
| im = gr.Image(height=256,width= 100, image_mode='L', sources="upload") | |
| #setup the interface | |
| iface = gr.Interface( | |
| fn = classify, | |
| inputs = im, | |
| outputs = gr.Label() | |
| ) | |
| iface.launch() | |