snehalsapkale commited on
Commit
cf2df42
1 Parent(s): 97faf4b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -10
app.py CHANGED
@@ -4,15 +4,17 @@ 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])
 
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])