Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -16,9 +16,6 @@ from sklearn.metrics import accuracy_score
|
|
| 16 |
# VECTORIZATION the u factor
|
| 17 |
import matplotlib.pyplot as plt
|
| 18 |
import os
|
| 19 |
-
import torch
|
| 20 |
-
import torchvision.transforms as transforms
|
| 21 |
-
import torchvision.models as models
|
| 22 |
from PIL import Image
|
| 23 |
from tensorflow.keras.models import Sequential
|
| 24 |
from tensorflow.keras.layers import Dense, Conv1D, MaxPooling1D, Flatten, Dropout
|
|
@@ -165,6 +162,7 @@ st.markdown("<p class='st-text'>قم بقراءة شروط الاستخدام ف
|
|
| 165 |
|
| 166 |
picture = st.camera_input("Take a picture")
|
| 167 |
|
|
|
|
| 168 |
if picture:
|
| 169 |
bytes_data = picture.getvalue()
|
| 170 |
frm = cv2.imdecode(np.frombuffer(bytes_data, np.uint8), cv2.IMREAD_COLOR)
|
|
@@ -176,58 +174,64 @@ if picture:
|
|
| 176 |
gray = cv2.cvtColor(frm, cv2.COLOR_BGR2GRAY)
|
| 177 |
average_brightness = cv2.mean(gray)[0]
|
| 178 |
# st.text(str(average_brightness))
|
|
|
|
| 179 |
if average_brightness < 100:
|
| 180 |
st.text("إضاءة غير جيدة")
|
| 181 |
st.text("انتقل الى مكان جيد الإضاءة")
|
| 182 |
else:
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 231 |
else:
|
| 232 |
st.text("لا يوجد وجه")
|
| 233 |
# Provide guidance for users
|
|
|
|
| 16 |
# VECTORIZATION the u factor
|
| 17 |
import matplotlib.pyplot as plt
|
| 18 |
import os
|
|
|
|
|
|
|
|
|
|
| 19 |
from PIL import Image
|
| 20 |
from tensorflow.keras.models import Sequential
|
| 21 |
from tensorflow.keras.layers import Dense, Conv1D, MaxPooling1D, Flatten, Dropout
|
|
|
|
| 162 |
|
| 163 |
picture = st.camera_input("Take a picture")
|
| 164 |
|
| 165 |
+
|
| 166 |
if picture:
|
| 167 |
bytes_data = picture.getvalue()
|
| 168 |
frm = cv2.imdecode(np.frombuffer(bytes_data, np.uint8), cv2.IMREAD_COLOR)
|
|
|
|
| 174 |
gray = cv2.cvtColor(frm, cv2.COLOR_BGR2GRAY)
|
| 175 |
average_brightness = cv2.mean(gray)[0]
|
| 176 |
# st.text(str(average_brightness))
|
| 177 |
+
|
| 178 |
if average_brightness < 100:
|
| 179 |
st.text("إضاءة غير جيدة")
|
| 180 |
st.text("انتقل الى مكان جيد الإضاءة")
|
| 181 |
else:
|
| 182 |
+
# Initialize the face detector
|
| 183 |
+
faceDetector = dlib.get_frontal_face_detector()
|
| 184 |
+
|
| 185 |
+
# Assuming 'frm' is your input image
|
| 186 |
+
faces = faceDetector(frm, 0)
|
| 187 |
+
|
| 188 |
+
# Check if there are any faces detected
|
| 189 |
+
if len(faces) > 0:
|
| 190 |
+
largest_face = None
|
| 191 |
+
max_area = 0
|
| 192 |
+
|
| 193 |
+
# Find the largest face
|
| 194 |
+
for face in faces:
|
| 195 |
+
w = face.right() - face.left()
|
| 196 |
+
h = face.bottom() - face.top()
|
| 197 |
+
area = w * h
|
| 198 |
+
if area > max_area:
|
| 199 |
+
max_area = area
|
| 200 |
+
largest_face = face
|
| 201 |
+
|
| 202 |
+
# If a largest face is detected
|
| 203 |
+
if largest_face is not None:
|
| 204 |
+
# Extract the largest face
|
| 205 |
+
face_img = frm[largest_face.top():largest_face.bottom(), largest_face.left():largest_face.right()]
|
| 206 |
+
# Now, 'face_img' contains the largest face. You can process it further as needed.
|
| 207 |
+
if np.array(face_img).size != 0 :
|
| 208 |
+
target_size = (512, 512)
|
| 209 |
+
resized_face = cv2.resize(face_img, target_size)
|
| 210 |
+
# Perform spatial pyramid feature extraction
|
| 211 |
+
rgb_features = spatial_pyramid(cv2.cvtColor(resized_face, cv2.COLOR_BGR2RGB), num_bins)
|
| 212 |
+
hsv_features = spatial_pyramid(cv2.cvtColor(resized_face, cv2.COLOR_BGR2HSV), num_bins)
|
| 213 |
+
ycbcr_features = spatial_pyramid(cv2.cvtColor(resized_face, cv2.COLOR_BGR2YCrCb), num_bins)
|
| 214 |
+
|
| 215 |
+
|
| 216 |
+
if rgb_features.size > 0 and hsv_features.size > 0 and ycbcr_features.size > 0:
|
| 217 |
+
combined_features = np.concatenate((rgb_features, hsv_features, ycbcr_features))
|
| 218 |
+
features_list.append(combined_features)
|
| 219 |
+
if len(features_list) > 0:
|
| 220 |
+
X_array = np.array(features_list)
|
| 221 |
+
# print(X_array.shape)
|
| 222 |
+
X_test_array_reshaped = np.expand_dims(X_array, axis=-1)
|
| 223 |
+
prediction = model.predict(X_test_array_reshaped)
|
| 224 |
+
prediction2 = model2.predict(X_test_array_reshaped)
|
| 225 |
+
if prediction >= 0.80 and prediction2 >= 0.00000000000001:
|
| 226 |
+
st.text("صورة حقيقية")
|
| 227 |
+
# st.text(str(prediction[0]))
|
| 228 |
+
# st.text(str(prediction2[0]))
|
| 229 |
+
else:
|
| 230 |
+
st.text("صورة مزيفة")
|
| 231 |
+
st.text(str(prediction[0]))
|
| 232 |
+
# st.text(str(prediction2[0]))
|
| 233 |
+
else:
|
| 234 |
+
st.text("لا يوجد وجه")
|
| 235 |
else:
|
| 236 |
st.text("لا يوجد وجه")
|
| 237 |
# Provide guidance for users
|