Spaces:
Running
Running
Add application file
Browse files- app.py +29 -0
- requirements.txt +4 -0
app.py
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import cv2
|
2 |
+
import dlib
|
3 |
+
import gradio as gr
|
4 |
+
from PIL import Image
|
5 |
+
from transformers import pipeline
|
6 |
+
|
7 |
+
# Load pre-trained image classification model from transformers library
|
8 |
+
model = pipeline("image-classification", model="0x70DA/down-syndrome-classifier")
|
9 |
+
|
10 |
+
# Load face detector from dlib library
|
11 |
+
detector = dlib.get_frontal_face_detector()
|
12 |
+
|
13 |
+
|
14 |
+
def predict(img):
|
15 |
+
faces = detector(img)
|
16 |
+
if len(faces) > 0:
|
17 |
+
face = faces[0] # Assuming there's only one face in the image
|
18 |
+
x, y, w, h = face.left(), face.top(), face.width(), face.height()
|
19 |
+
cropped_face = img[y : y + h, x : x + w]
|
20 |
+
# Convert the cropped image to a PIL image
|
21 |
+
pil_image = Image.fromarray(cv2.cvtColor(cropped_face, cv2.COLOR_BGR2RGB))
|
22 |
+
pred = model(pil_image)
|
23 |
+
return {o["label"]: o["score"] for o in pred}
|
24 |
+
|
25 |
+
|
26 |
+
demo = gr.Interface(
|
27 |
+
fn=predict, inputs=gr.components.Image(), outputs=gr.components.Label()
|
28 |
+
)
|
29 |
+
demo.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
pillow
|
2 |
+
cv2
|
3 |
+
dlib
|
4 |
+
transfomers
|