Spaces:
Runtime error
Runtime error
snehalsapkale
commited on
Commit
•
cf2df42
1
Parent(s):
97faf4b
Update app.py
Browse files
app.py
CHANGED
@@ -4,15 +4,17 @@ from transformers import ViTFeatureExtractor, ViTForImageClassification
|
|
4 |
from PIL import Image
|
5 |
import requests
|
6 |
|
7 |
-
|
8 |
-
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
-
|
11 |
-
|
|
|
12 |
|
13 |
-
|
14 |
-
|
15 |
-
logits = outputs.logits
|
16 |
-
|
17 |
-
predicted_class_idx = logits.argmax(-1).item()
|
18 |
-
print("Predicted class:", model.config.id2label[predicted_class_idx])
|
|
|
4 |
from PIL import Image
|
5 |
import requests
|
6 |
|
7 |
+
img_file_buffer = st.file_uploader('Upload a PNG image', type='png')
|
8 |
+
if img_file_buffer is not None:
|
9 |
+
image = Image.open(img_file_buffer)
|
10 |
+
img_array = np.array(image)
|
11 |
+
|
12 |
+
feature_extractor = ViTFeatureExtractor.from_pretrained('rizvandwiki/gender-classification')
|
13 |
+
model = ViTForImageClassification.from_pretrained('rizvandwiki/gender-classification')
|
14 |
|
15 |
+
inputs = feature_extractor(images=image, return_tensors="pt")
|
16 |
+
outputs = model(**inputs)
|
17 |
+
logits = outputs.logits
|
18 |
|
19 |
+
predicted_class_idx = logits.argmax(-1).item()
|
20 |
+
print("Predicted class:", model.config.id2label[predicted_class_idx])
|
|
|
|
|
|
|
|