Update app.py
Browse files
app.py
CHANGED
@@ -6,6 +6,8 @@ import cv2 as cv
|
|
6 |
import dlib
|
7 |
import logging
|
8 |
from typing import Optional
|
|
|
|
|
9 |
|
10 |
logging.basicConfig(level=logging.INFO)
|
11 |
|
@@ -65,12 +67,22 @@ def grab_faces(img: np.ndarray) -> Optional[np.ndarray]:
|
|
65 |
|
66 |
return None
|
67 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
model = ViTForImageClassification.from_pretrained("ongkn/attraction-classifier")
|
69 |
processor = ViTImageProcessor.from_pretrained("ongkn/attraction-classifier")
|
70 |
|
71 |
pipe = pipeline("image-classification", model=model, feature_extractor=processor)
|
72 |
|
73 |
def classify_image(input):
|
|
|
74 |
face = grab_faces(np.array(input))
|
75 |
if face is None:
|
76 |
return "No face detected", 0, input
|
|
|
6 |
import dlib
|
7 |
import logging
|
8 |
from typing import Optional
|
9 |
+
import os
|
10 |
+
|
11 |
|
12 |
logging.basicConfig(level=logging.INFO)
|
13 |
|
|
|
67 |
|
68 |
return None
|
69 |
|
70 |
+
def increment_visit():
|
71 |
+
if not os.path.exists("visits.txt"):
|
72 |
+
with open("visits.txt", "w") as f:
|
73 |
+
f.write("0")
|
74 |
+
with open("visits.txt", "r") as f:
|
75 |
+
visits = int(f.read())
|
76 |
+
f.seek(0)
|
77 |
+
f.write(str(visits + 1))
|
78 |
+
|
79 |
model = ViTForImageClassification.from_pretrained("ongkn/attraction-classifier")
|
80 |
processor = ViTImageProcessor.from_pretrained("ongkn/attraction-classifier")
|
81 |
|
82 |
pipe = pipeline("image-classification", model=model, feature_extractor=processor)
|
83 |
|
84 |
def classify_image(input):
|
85 |
+
increment_visit() # this is just to keep track of how many people are using this app. no personal data is obviously used
|
86 |
face = grab_faces(np.array(input))
|
87 |
if face is None:
|
88 |
return "No face detected", 0, input
|