Download app.py from glopez/cifar10: direct link, hf CLI and curl.
- Browser
- Download file 669 Bytes
-
https://huggingface.co/spaces/glopez/cifar10/resolve/main/app.py
- Command line
-
hf download hf://spaces/glopez/cifar10/app.py
-
curl -L -o app.py https://huggingface.co/spaces/glopez/cifar10/resolve/main/app.py
669 Bytes
| from transformers import AutoModelForImageClassification, AutoFeatureExtractor | |
| import gradio as gr | |
| import torch | |
| def classify_image(image): | |
| device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') | |
| model = AutoModelForImageClassification.from_pretrained('glopez/cifar-10').to(device) | |
| feature_extractor = AutoFeatureExtractor.from_pretrained('glopez/cifar-10') | |
| inp = feature_extractor(image, return_tensors='pt').to(device) | |
| outp = model(**inp) | |
| pred = torch.argmax(outp.logits, dim=1).item() | |
| return model.config.id2label[pred] | |
| interface = gr.Interface(fn=classify_image, inputs=gr.Image(shape=(224, 224)), outputs="text").launch(debug=True) | |