Spaces:
Runtime error
Runtime error
jon-fernandes
commited on
Commit
•
e660ff3
1
Parent(s):
61df708
Updated from colab
Browse files- app.py +17 -0
- requirements.txt +2 -0
app.py
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import AutoModelForImageClassification, AutoFeatureExtractor
|
2 |
+
import gradio as gr
|
3 |
+
import torch
|
4 |
+
|
5 |
+
huggingface_username = 'i-am-holmes'
|
6 |
+
model_name = 'vit-base-patch16-224-finetuned-flower'
|
7 |
+
|
8 |
+
def classify_image(image):
|
9 |
+
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
10 |
+
model = AutoModelForImageClassification.from_pretrained(f'{huggingface_username}/{model_name}').to(device)
|
11 |
+
feature_extractor = AutoFeatureExtractor.from_pretrained(f'{huggingface_username}/{model_name}')
|
12 |
+
inp = feature_extractor(image, return_tensors='pt').to(device)
|
13 |
+
outp = model(**inp)
|
14 |
+
pred = torch.argmax(outp.logits, dim=1).item()
|
15 |
+
return model.config.id2label[pred]
|
16 |
+
|
17 |
+
interface = gr.Interface(fn=classify_image, inputs=gr.Image(shape=(224, 224)), outputs="text").launch(debug=True, share=True)
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
torch
|
2 |
+
transformers
|