Spaces:
Runtime error
Runtime error
snehalsapkale
commited on
Commit
•
97faf4b
1
Parent(s):
bdac52b
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import pipeline
|
3 |
+
from transformers import ViTFeatureExtractor, ViTForImageClassification
|
4 |
+
from PIL import Image
|
5 |
+
import requests
|
6 |
+
|
7 |
+
url = 'http://images.cocodataset.org/val2017/000000039769.jpg'
|
8 |
+
image = Image.open(requests.get(url, stream=True).raw)
|
9 |
+
|
10 |
+
feature_extractor = ViTFeatureExtractor.from_pretrained('google/vit-base-patch16-224')
|
11 |
+
model = ViTForImageClassification.from_pretrained('google/vit-base-patch16-224')
|
12 |
+
|
13 |
+
inputs = feature_extractor(images=image, return_tensors="pt")
|
14 |
+
outputs = model(**inputs)
|
15 |
+
logits = outputs.logits
|
16 |
+
|
17 |
+
predicted_class_idx = logits.argmax(-1).item()
|
18 |
+
print("Predicted class:", model.config.id2label[predicted_class_idx])
|