Spaces:
Sleeping
Sleeping
fidantokac
commited on
Commit
•
4a83ead
1
Parent(s):
665e8c8
Update app.py
Browse files
app.py
CHANGED
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import cv2
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
# Yüz tespiti için önceden eğitilmiş bir model yüklenir
|
5 |
+
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
|
6 |
+
|
7 |
+
def detect_faces(img):
|
8 |
+
|
9 |
+
if img is None: # Eğer img None ise, None döndür
|
10 |
+
return None
|
11 |
+
|
12 |
+
# Resmi istenen boyuta küçült
|
13 |
+
height, width, _ = img.shape
|
14 |
+
if height > 750 or width > 750:
|
15 |
+
img = cv2.resize(img, (750, 750))
|
16 |
+
|
17 |
+
# Görüntüyü gri tonlamaya çevir
|
18 |
+
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
|
19 |
+
|
20 |
+
# Yüzleri tespit et
|
21 |
+
faces = face_cascade.detectMultiScale(gray, 1.3, 7)
|
22 |
+
|
23 |
+
count = 0
|
24 |
+
for (x, y, w, h) in faces:
|
25 |
+
cv2.rectangle(img, (x, y), (x+w, y+h), (255, 0, 0), 2)
|
26 |
+
count += 1
|
27 |
+
|
28 |
+
cv2.putText(img, f"** {count} people were detect in the photo.", (100, 700), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255,000 ), 2)
|
29 |
+
return img
|
30 |
+
|
31 |
+
# Gradio arayüzünü oluştur
|
32 |
+
|
33 |
+
with gr.Blocks() as demo:
|
34 |
+
gr.Markdown("#Face Detect App-Basic")
|
35 |
+
|
36 |
+
|
37 |
+
with gr.Row():
|
38 |
+
input_image = gr.Image(label="Upload a photo", type="numpy")
|
39 |
+
output_image = gr.Image(label="Detect Area")
|
40 |
+
|
41 |
+
|
42 |
+
apply_button = gr.Button("Detect")
|
43 |
+
clear_button = gr.Button("Clear")
|
44 |
+
|
45 |
+
input_image.change(fn=detect_faces, inputs=input_image, outputs=output_image)
|
46 |
+
apply_button.click(fn=detect_faces, inputs=input_image, outputs=output_image)
|
47 |
+
clear_button.click(fn=lambda: (None, None), inputs=None, outputs=[input_image, output_image]) # Fotoğrafı temizlemek için (None, None) döndür
|
48 |
+
|
49 |
+
|
50 |
+
'''iface = gr.Interface(
|
51 |
+
fn=detect_faces,
|
52 |
+
inputs="image",
|
53 |
+
outputs="image",
|
54 |
+
title="Yüz Tespiti Uygulaması"
|
55 |
+
)'''
|
56 |
+
|
57 |
+
demo.launch()
|