Alex Gonzalez
commited on
Commit
·
527bb0a
1
Parent(s):
72fe867
Remove Facial Extration
Browse files- app.py +1 -13
- requirements.txt +0 -1
app.py
CHANGED
@@ -3,26 +3,14 @@ from fastai.vision.all import *
|
|
3 |
from transformers import AutoImageProcessor, AutoModelForImageClassification
|
4 |
from PIL import Image
|
5 |
import requests
|
6 |
-
import face_recognition
|
7 |
|
8 |
learn_inf = load_learner("export.pkl")
|
9 |
processor = AutoImageProcessor.from_pretrained("dima806/facial_emotions_image_detection")
|
10 |
model = AutoModelForImageClassification.from_pretrained("dima806/facial_emotions_image_detection")
|
11 |
|
12 |
-
def extract_face(image)-> Image.Image:
|
13 |
-
# Detect face locations
|
14 |
-
face_locations = face_recognition.face_locations(image)
|
15 |
-
|
16 |
-
# If a face is detected, extract the first one
|
17 |
-
if face_locations:
|
18 |
-
top, right, bottom, left = face_locations[0]
|
19 |
-
face_image = Image.fromarray(image[top:bottom, left:right])
|
20 |
-
return face_image
|
21 |
-
else:
|
22 |
-
return image
|
23 |
|
24 |
def predict(value) -> str:
|
25 |
-
image =
|
26 |
inputs = processor(images=image, return_tensors="pt")
|
27 |
outputs = model(**inputs)
|
28 |
logits = outputs.logits
|
|
|
3 |
from transformers import AutoImageProcessor, AutoModelForImageClassification
|
4 |
from PIL import Image
|
5 |
import requests
|
|
|
6 |
|
7 |
learn_inf = load_learner("export.pkl")
|
8 |
processor = AutoImageProcessor.from_pretrained("dima806/facial_emotions_image_detection")
|
9 |
model = AutoModelForImageClassification.from_pretrained("dima806/facial_emotions_image_detection")
|
10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
def predict(value) -> str:
|
13 |
+
image = Image.fromarray(value).convert("L")
|
14 |
inputs = processor(images=image, return_tensors="pt")
|
15 |
outputs = model(**inputs)
|
16 |
logits = outputs.logits
|
requirements.txt
CHANGED
@@ -1,3 +1,2 @@
|
|
1 |
fastai
|
2 |
transformers
|
3 |
-
face_recognition
|
|
|
1 |
fastai
|
2 |
transformers
|
|