Spaces:
Runtime error
Runtime error
Add application file
Browse files- app.py +41 -0
- requirements.txt +6 -0
app.py
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import cv2
|
2 |
+
import dlib
|
3 |
+
import streamlit as st
|
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 |
+
# Define the prediction function
|
14 |
+
def predict(image):
|
15 |
+
img = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
|
16 |
+
faces = detector(img)
|
17 |
+
if len(faces) > 0:
|
18 |
+
face = faces[0] # Assuming there's only one face in the image
|
19 |
+
x, y, w, h = face.left(), face.top(), face.width(), face.height()
|
20 |
+
cropped_face = img[y: y + h, x: x + w]
|
21 |
+
# Convert the cropped image to a PIL image
|
22 |
+
pil_image = Image.fromarray(cv2.cvtColor(cropped_face, cv2.COLOR_BGR2RGB))
|
23 |
+
pred = model(pil_image)
|
24 |
+
return {o["label"]: o["score"] for o in pred}
|
25 |
+
return {"No Face Detected": 0.0}
|
26 |
+
|
27 |
+
# Create the Streamlit app interface
|
28 |
+
st.title("Down Syndrome Classifier")
|
29 |
+
|
30 |
+
uploaded_image = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
|
31 |
+
|
32 |
+
if uploaded_image is not None:
|
33 |
+
image = Image.open(uploaded_image)
|
34 |
+
st.image(image, caption="Uploaded Image", use_column_width=True)
|
35 |
+
st.write("Classifying...")
|
36 |
+
|
37 |
+
result = predict(image)
|
38 |
+
|
39 |
+
st.write("Classification Results:")
|
40 |
+
for label, score in result.items():
|
41 |
+
st.write(f"{label}: {score:.4f}")
|
requirements.txt
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
pillow
|
2 |
+
opencv-python-headless
|
3 |
+
dlib
|
4 |
+
transformers
|
5 |
+
torch
|
6 |
+
numpy
|