abrar-adnan commited on
Commit
0c2700d
1 Parent(s): 7cc3c5b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -12
app.py CHANGED
@@ -5,20 +5,33 @@ import face_recognition
5
  from fastai.vision.all import load_learner
6
  import time
7
  import chardet
 
 
 
 
 
 
8
 
9
  model = load_learner("gaze-recognizer-v1.pkl")
10
 
11
- def video_processing(video):
12
- print('Type')
13
- print(type(video))
14
- print(video)
15
- #print('video encoding done into = ' + chardet.detect(video)['encoding'])
 
 
 
 
 
 
16
  start_time = time.time()
17
- # Loop through the frames of the video
18
- video_capture = cv2.VideoCapture(video)
19
  on_camera = 0
20
  off_camera = 0
21
  total = 0
 
22
  while True:
23
  # Read a single frame from the video
24
  for i in range(24*3):
@@ -67,14 +80,15 @@ def video_processing(video):
67
  cv2.destroyAllWindows()
68
  end_time = time.time()
69
  print(f'Time taken: {end_time-start_time}')
 
 
70
  print(gaze_percentage)
71
  return str(gaze_percentage)
72
 
73
 
74
- demo = gr.Interface(fn = video_processing,
75
- inputs= 'video',#gr.Video(),
76
- outputs = 'text'
77
- )
78
 
79
  if __name__ == "__main__":
80
- demo.launch()
 
5
  from fastai.vision.all import load_learner
6
  import time
7
  import chardet
8
+ import base64
9
+
10
+ import pathlib
11
+ temp = pathlib.PosixPath
12
+ pathlib.PosixPath = pathlib.WindowsPath
13
+
14
 
15
  model = load_learner("gaze-recognizer-v1.pkl")
16
 
17
+ def video_processing(video_file, encoded_video):
18
+
19
+ if encoded_video != "":
20
+
21
+ decoded_file_data = base64.b64decode(encoded_video)
22
+
23
+ with open("temp_video.mp4", "wb") as f:
24
+ f.write(decoded_file_data)
25
+
26
+ video_file = "temp_video.mp4"
27
+
28
  start_time = time.time()
29
+
30
+ video_capture = cv2.VideoCapture(video_file)
31
  on_camera = 0
32
  off_camera = 0
33
  total = 0
34
+
35
  while True:
36
  # Read a single frame from the video
37
  for i in range(24*3):
 
80
  cv2.destroyAllWindows()
81
  end_time = time.time()
82
  print(f'Time taken: {end_time-start_time}')
83
+ if os.path.exists("temp_video.mp4"):
84
+ os.remove("temp_video.mp4")
85
  print(gaze_percentage)
86
  return str(gaze_percentage)
87
 
88
 
89
+ demo = gr.Interface(fn=video_processing,
90
+ inputs=["video", "text"],
91
+ outputs="text")
 
92
 
93
  if __name__ == "__main__":
94
+ demo.launch()