brxerq commited on
Commit
c74f032
1 Parent(s): b831807

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -58
app.py CHANGED
@@ -1,61 +1,38 @@
1
- import sys
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
- class AntiSpoofingGUI:
10
- def __init__(self, anti_spoofing_system):
11
- self.anti_spoofing_system = anti_spoofing_system
12
- self.window = tk.Tk()
13
- self.window.title("Anti-Spoofing System")
14
-
15
- self.student_id_label = tk.Label(self.window, text="Student ID:")
16
- self.student_id_label.pack()
17
- self.student_id_entry = tk.Entry(self.window)
18
- self.student_id_entry.pack()
19
-
20
- self.student_name_label = tk.Label(self.window, text="Student Name:")
21
- self.student_name_label.pack()
22
- self.student_name_entry = tk.Entry(self.window)
23
- self.student_name_entry.pack()
24
-
25
- self.start_button = tk.Button(self.window, text="Start", command=self.start_anti_spoofing)
26
- self.start_button.pack()
27
-
28
- self.image_label = tk.Label(self.window)
29
- self.image_label.pack()
30
-
31
- # Create a PhotoImage object to use for the video feed
32
- self.photo = ImageTk.PhotoImage("RGB", (640, 480))
33
-
34
- def start_anti_spoofing(self):
35
- self.student_id = self.student_id_entry.get()
36
- self.student_name = self.student_name_entry.get()
37
-
38
- if not self.student_id or not self.student_name:
39
- messagebox.showwarning("Warning", "Please enter both Student ID and Name")
40
- return
41
-
42
- threading.Thread(target=self.run_anti_spoofing, daemon=True).start()
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()