Commit
·
b947cf2
1
Parent(s):
fdcbfe1
Updated from colab
Browse files- app.py +15 -0
- requirements.txt +2 -0
app.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import AutoModelForImageClassification, AutoFeatureExtractor
|
| 2 |
+
import gradio as gr
|
| 3 |
+
|
| 4 |
+
import torch
|
| 5 |
+
|
| 6 |
+
def classify_image(image):
|
| 7 |
+
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
| 8 |
+
model = AutoModelForImageClassification.from_pretrained('glopez/cifar-10').to(device)
|
| 9 |
+
feature_extractor = AutoFeatureExtractor.from_pretrained('glopez/cifar-10')
|
| 10 |
+
inp = feature_extractor(image, return_tensors='pt').to(device)
|
| 11 |
+
outp = model(**inp)
|
| 12 |
+
pred = torch.argmax(outp.logits, dim=1).item()
|
| 13 |
+
return model.config.id2label[pred]
|
| 14 |
+
|
| 15 |
+
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
|