Fred808 commited on
Commit
c862922
·
verified ·
1 Parent(s): e329860

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -11
app.py CHANGED
@@ -1,23 +1,45 @@
1
  import os
2
- import json
 
 
3
  from scripts.extract_frames import extract_frames
4
  from scripts.cursor_tracker import track_cursor
5
 
6
- def run_pipeline():
 
 
 
 
 
 
 
 
7
  video_dir = "videos"
8
- frames_dir = "frames"
9
  cursor_dir = "cursors"
10
- annotations_dir = "annotations"
11
- os.makedirs(frames_dir, exist_ok=True)
12
  os.makedirs(cursor_dir, exist_ok=True)
13
- os.makedirs(annotations_dir, exist_ok=True)
14
  # Step 1: Extract frames
15
  for video_file in os.listdir(video_dir):
16
  if video_file.lower().endswith(('.mp4', '.avi', '.mov')):
17
- extract_frames(os.path.join(video_dir, video_file), frames_dir)
18
  # Step 2: Track cursor
19
- track_cursor(frames_dir, cursor_dir, os.path.join(annotations_dir, "cursor_positions.json"))
20
- print("Pipeline complete.")
 
 
 
 
 
 
 
 
 
 
 
 
 
21
 
22
- if __name__ == "__main__":
23
- run_pipeline()
 
 
1
  import os
2
+ import zipfile
3
+ from fastapi import FastAPI
4
+ from fastapi.responses import FileResponse
5
  from scripts.extract_frames import extract_frames
6
  from scripts.cursor_tracker import track_cursor
7
 
8
+ app = FastAPI()
9
+
10
+ FRAMES_DIR = "frames"
11
+ ANNOTATIONS_DIR = "annotations"
12
+ FRAMES_ZIP = "frames.zip"
13
+ ANNOTATIONS_ZIP = "annotations.zip"
14
+
15
+ @app.on_event("startup")
16
+ def run_pipeline_and_zip():
17
  video_dir = "videos"
 
18
  cursor_dir = "cursors"
19
+ os.makedirs(FRAMES_DIR, exist_ok=True)
 
20
  os.makedirs(cursor_dir, exist_ok=True)
21
+ os.makedirs(ANNOTATIONS_DIR, exist_ok=True)
22
  # Step 1: Extract frames
23
  for video_file in os.listdir(video_dir):
24
  if video_file.lower().endswith(('.mp4', '.avi', '.mov')):
25
+ extract_frames(os.path.join(video_dir, video_file), FRAMES_DIR)
26
  # Step 2: Track cursor
27
+ track_cursor(FRAMES_DIR, cursor_dir, os.path.join(ANNOTATIONS_DIR, "cursor_positions.json"))
28
+ # Step 3: Zip frames and annotations
29
+ with zipfile.ZipFile(FRAMES_ZIP, 'w', zipfile.ZIP_DEFLATED) as zipf:
30
+ for root, _, files in os.walk(FRAMES_DIR):
31
+ for file in files:
32
+ zipf.write(os.path.join(root, file), arcname=file)
33
+ with zipfile.ZipFile(ANNOTATIONS_ZIP, 'w', zipfile.ZIP_DEFLATED) as zipf:
34
+ for root, _, files in os.walk(ANNOTATIONS_DIR):
35
+ for file in files:
36
+ zipf.write(os.path.join(root, file), arcname=file)
37
+ print("Pipeline complete and outputs zipped.")
38
+
39
+ @app.get("/download/frames")
40
+ def download_frames():
41
+ return FileResponse(FRAMES_ZIP, filename=FRAMES_ZIP)
42
 
43
+ @app.get("/download/annotations")
44
+ def download_annotations():
45
+ return FileResponse(ANNOTATIONS_ZIP, filename=ANNOTATIONS_ZIP)