brxerq commited on
Commit
7b2fb36
1 Parent(s): d9e05c3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -58
app.py CHANGED
@@ -1,61 +1,30 @@
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
+ # Process the frame using the anti-spoofing system
14
+ frame = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
15
+ anti_spoofing_system.run(lambda frame: frame) # Modify 'run' to accept a single frame if necessary
16
+
17
+ # Here you could return whether spoofing is detected, a message, or the modified frame
18
+ return frame
19
+
20
+ iface = gr.Interface(
21
+ fn=process_frame,
22
+ inputs=[
23
+ gr.Image(source="webcam", tool=None, streaming=True),
24
+ gr.Textbox(label="Student ID"),
25
+ gr.Textbox(label="Student Name")
26
+ ],
27
+ outputs=gr.Image()
28
+ )
29
+
30
+ iface.launch()