Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,61 +1,38 @@
|
|
1 |
-
import
|
2 |
-
import tkinter as tk
|
3 |
-
from tkinter import messagebox
|
4 |
-
from PIL import Image, ImageTk
|
5 |
-
import threading
|
6 |
import cv2
|
7 |
from anti_spoofing import AntiSpoofingSystem
|
8 |
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
def run_anti_spoofing(self):
|
45 |
-
self.anti_spoofing_system.student_id = self.student_id
|
46 |
-
self.anti_spoofing_system.student_name = self.student_name
|
47 |
-
self.anti_spoofing_system.run(self.update_frame)
|
48 |
-
|
49 |
-
def update_frame(self, frame):
|
50 |
-
cv2image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGBA)
|
51 |
-
self.photo.paste(Image.fromarray(cv2image))
|
52 |
-
self.image_label.config(image=self.photo)
|
53 |
-
self.image_label.update_idletasks()
|
54 |
-
|
55 |
-
def run(self):
|
56 |
-
self.window.mainloop()
|
57 |
-
|
58 |
-
if __name__ == "__main__":
|
59 |
-
anti_spoofing_system = AntiSpoofingSystem()
|
60 |
-
gui = AntiSpoofingGUI(anti_spoofing_system)
|
61 |
-
gui.run()
|
|
|
1 |
+
import gradio as gr
|
|
|
|
|
|
|
|
|
2 |
import cv2
|
3 |
from anti_spoofing import AntiSpoofingSystem
|
4 |
|
5 |
+
# Initialize the anti-spoofing system
|
6 |
+
anti_spoofing_system = AntiSpoofingSystem()
|
7 |
+
|
8 |
+
def process_frame(image, student_id, student_name):
|
9 |
+
# Set student details in the anti-spoofing system
|
10 |
+
anti_spoofing_system.student_id = student_id
|
11 |
+
anti_spoofing_system.student_name = student_name
|
12 |
+
|
13 |
+
# Convert the Gradio image format to OpenCV format
|
14 |
+
frame = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
|
15 |
+
|
16 |
+
# Process the frame using the anti-spoofing system
|
17 |
+
processed_frame = frame.copy() # If needed, adapt the anti-spoofing system to take individual frames
|
18 |
+
anti_spoofing_system.detect_smartphone(processed_frame)
|
19 |
+
|
20 |
+
# Display a message if a smartphone is detected or blinks are counted
|
21 |
+
message = "Mobile phone detected, can't record attendance" if anti_spoofing_system.smartphone_detected else "Processing attendance..."
|
22 |
+
|
23 |
+
return cv2.cvtColor(processed_frame, cv2.COLOR_BGR2RGB), message
|
24 |
+
|
25 |
+
iface = gr.Interface(
|
26 |
+
fn=process_frame,
|
27 |
+
inputs=[
|
28 |
+
gr.Image(source="webcam", tool=None, streaming=True, label="Webcam Feed"),
|
29 |
+
gr.Textbox(label="Student ID"),
|
30 |
+
gr.Textbox(label="Student Name")
|
31 |
+
],
|
32 |
+
outputs=[
|
33 |
+
gr.Image(label="Processed Frame"),
|
34 |
+
gr.Textbox(label="Status Message")
|
35 |
+
]
|
36 |
+
)
|
37 |
+
|
38 |
+
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|