Spaces:
Runtime error
Runtime error
File size: 773 Bytes
97faf4b 0687788 97faf4b cf2df42 53edacb cf2df42 97faf4b cf2df42 97faf4b cf2df42 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
import streamlit as st
from transformers import pipeline
from transformers import ViTFeatureExtractor, ViTForImageClassification
from PIL import Image
import requests
import numpy as np
img_file_buffer = st.file_uploader('Upload a PNG image', type='png')
if img_file_buffer is not None:
image = Image.open(img_file_buffer)
feature_extractor = ViTFeatureExtractor.from_pretrained('rizvandwiki/gender-classification')
model = ViTForImageClassification.from_pretrained('rizvandwiki/gender-classification')
inputs = feature_extractor(images=image, return_tensors="pt")
outputs = model(**inputs)
logits = outputs.logits
predicted_class_idx = logits.argmax(-1).item()
print("Predicted class:", model.config.id2label[predicted_class_idx])
|