Zhen Ye Claude Opus 4.6 commited on
Commit
1c613aa
·
1 Parent(s): fb09dce

feat(isr): wire mission param through API/background pipeline, add openai dep

Browse files

- Add mission param to /detect/async endpoint
- Pass mission to JobInfo constructor
- Spawn ISR assessor loop in background.py when mission is set
- Cancel ISR task on job completion (final assessment in handler)
- Add openai>=1.0.0 to requirements.txt

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Files changed (3) hide show
  1. app.py +2 -0
  2. jobs/background.py +15 -0
  3. requirements.txt +1 -0
app.py CHANGED
@@ -315,6 +315,7 @@ async def detect_async_endpoint(
315
  depth_scale: float = Form(25.0),
316
  enable_depth: bool = Form(False),
317
  step: int = Form(7),
 
318
  ):
319
  _ttfs_t0 = time.perf_counter()
320
 
@@ -389,6 +390,7 @@ async def detect_async_endpoint(
389
  first_frame_depth_path=str(first_frame_depth_path),
390
  step=step,
391
  ttfs_t0=_ttfs_t0,
 
392
  )
393
  get_job_storage().create(job)
394
  asyncio.create_task(process_video_async(job_id))
 
315
  depth_scale: float = Form(25.0),
316
  enable_depth: bool = Form(False),
317
  step: int = Form(7),
318
+ mission: str = Form(None),
319
  ):
320
  _ttfs_t0 = time.perf_counter()
321
 
 
390
  first_frame_depth_path=str(first_frame_depth_path),
391
  step=step,
392
  ttfs_t0=_ttfs_t0,
393
+ mission=mission,
394
  )
395
  get_job_storage().create(job)
396
  asyncio.create_task(process_video_async(job_id))
jobs/background.py CHANGED
@@ -6,6 +6,7 @@ from jobs.models import JobStatus
6
  from jobs.storage import get_job_storage
7
  from jobs.streaming import create_stream, remove_stream
8
  from inference import run_inference, run_grounded_sam2_tracking
 
9
 
10
 
11
  async def process_video_async(job_id: str) -> None:
@@ -18,11 +19,17 @@ async def process_video_async(job_id: str) -> None:
18
  depth_path = None
19
  depth_error = None
20
  partial_success = False
 
21
 
22
  # Create stream for live view
23
  stream_queue = create_stream(job_id)
24
 
25
  try:
 
 
 
 
 
26
  # Run detection or segmentation first
27
  if job.mode == "segmentation":
28
  detection_path = await asyncio.to_thread(
@@ -76,6 +83,14 @@ async def process_video_async(job_id: str) -> None:
76
  depth_path = detection_path
77
  logging.info("Depth estimation included in main video for job %s", job_id)
78
 
 
 
 
 
 
 
 
 
79
  # Mark as completed (with or without depth)
80
  storage.update(
81
  job_id,
 
6
  from jobs.storage import get_job_storage
7
  from jobs.streaming import create_stream, remove_stream
8
  from inference import run_inference, run_grounded_sam2_tracking
9
+ from models.isr.loop import run_isr_assessor_loop
10
 
11
 
12
  async def process_video_async(job_id: str) -> None:
 
19
  depth_path = None
20
  depth_error = None
21
  partial_success = False
22
+ isr_task = None
23
 
24
  # Create stream for live view
25
  stream_queue = create_stream(job_id)
26
 
27
  try:
28
+ # Start ISR assessor if mission is provided
29
+ if job.mission:
30
+ isr_task = asyncio.create_task(
31
+ run_isr_assessor_loop(job_id, job.mission)
32
+ )
33
  # Run detection or segmentation first
34
  if job.mode == "segmentation":
35
  detection_path = await asyncio.to_thread(
 
83
  depth_path = detection_path
84
  logging.info("Depth estimation included in main video for job %s", job_id)
85
 
86
+ # Stop ISR assessor (final assessment runs in cancellation handler)
87
+ if isr_task and not isr_task.done():
88
+ isr_task.cancel()
89
+ try:
90
+ await isr_task
91
+ except asyncio.CancelledError:
92
+ pass
93
+
94
  # Mark as completed (with or without depth)
95
  storage.update(
96
  job_id,
requirements.txt CHANGED
@@ -15,3 +15,4 @@ hydra-core>=1.3.2
15
  iopath>=0.1.10
16
  psutil
17
  dill
 
 
15
  iopath>=0.1.10
16
  psutil
17
  dill
18
+ openai>=1.0.0