Update app.py
Browse files
app.py
CHANGED
|
@@ -1,61 +1,30 @@
|
|
| 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 |
-
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()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|