Spaces:
Runtime error
Runtime error
app.py
CHANGED
|
@@ -1,14 +1,6 @@
|
|
| 1 |
-
|
| 2 |
-
from
|
| 3 |
-
import torch
|
| 4 |
|
| 5 |
-
|
| 6 |
-
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 7 |
-
model = ViTForImageClassification.from_pretrained( "imjeffhi/pokemon_classifier").to(device)
|
| 8 |
-
feature_extractor = ViTFeatureExtractor.from_pretrained('imjeffhi/pokemon_classifier')
|
| 9 |
|
| 10 |
-
|
| 11 |
-
img = Image.open('test.jpg')
|
| 12 |
-
extracted = feature_extractor(images=img, return_tensors='pt').to(device)
|
| 13 |
-
predicted_id = model(**extracted).logits.argmax(-1).item()
|
| 14 |
-
predicted_pokemon = model.config.id2label[predicted_id]
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
|
|
|
| 3 |
|
| 4 |
+
pipe = pipeline(task="image-classification", model="microsoft/beit-base-patch16-224-pt22k-ft22k")
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
+
gr.Interface.from_pipeline(pipe, title="22k Image Classification", description="Object Recognition using Microsoft BEIT", examples = ['wonder_cat.jpg', 'aki_dog.jpg',], allow_flagging="never").launch(inbrowser=True)
|
|
|
|
|
|
|
|
|
|
|
|