Make all debug and progress messages conditional on --debug flag

parent f315edea
...@@ -30,7 +30,7 @@ import time ...@@ -30,7 +30,7 @@ import time
import uuid import uuid
from .comm import SocketCommunicator, Message from .comm import SocketCommunicator, Message
from .models import get_model from .models import get_model
from .config import get_system_prompt_content, get_comm_type, get_backend_worker_port from .config import get_system_prompt_content, get_comm_type, get_backend_worker_port, get_debug
# Set PyTorch CUDA memory management # Set PyTorch CUDA memory management
os.environ['PYTORCH_CUDA_ALLOC_CONF'] = 'expandable_segments:True' os.environ['PYTORCH_CUDA_ALLOC_CONF'] = 'expandable_segments:True'
...@@ -186,6 +186,7 @@ def analyze_media(media_path, prompt, model_path, interval=10, job_id=None, comm ...@@ -186,6 +186,7 @@ def analyze_media(media_path, prompt, model_path, interval=10, job_id=None, comm
'message': 'Initializing analysis job' 'message': 'Initializing analysis job'
}) })
comm.send_message(progress_msg) comm.send_message(progress_msg)
if get_debug():
print(f"PROGRESS: Job {job_id} - 5% - Initializing analysis job") print(f"PROGRESS: Job {job_id} - 5% - Initializing analysis job")
torch.cuda.empty_cache() torch.cuda.empty_cache()
...@@ -205,6 +206,7 @@ def analyze_media(media_path, prompt, model_path, interval=10, job_id=None, comm ...@@ -205,6 +206,7 @@ def analyze_media(media_path, prompt, model_path, interval=10, job_id=None, comm
'message': f'Model {model_path.split("/")[-1]} loaded successfully' 'message': f'Model {model_path.split("/")[-1]} loaded successfully'
}) })
comm.send_message(progress_msg) comm.send_message(progress_msg)
if get_debug():
print(f"PROGRESS: Job {job_id} - 8% - Model loaded successfully") print(f"PROGRESS: Job {job_id} - 8% - Model loaded successfully")
# Get system prompt # Get system prompt
...@@ -231,6 +233,7 @@ def analyze_media(media_path, prompt, model_path, interval=10, job_id=None, comm ...@@ -231,6 +233,7 @@ def analyze_media(media_path, prompt, model_path, interval=10, job_id=None, comm
'message': f'Extracted {total_frames} frames' 'message': f'Extracted {total_frames} frames'
}) })
comm.send_message(progress_msg) comm.send_message(progress_msg)
if get_debug():
print(f"PROGRESS: Job {job_id} - 10% - Extracted {total_frames} frames") print(f"PROGRESS: Job {job_id} - 10% - Extracted {total_frames} frames")
descriptions = [] descriptions = []
...@@ -248,6 +251,7 @@ def analyze_media(media_path, prompt, model_path, interval=10, job_id=None, comm ...@@ -248,6 +251,7 @@ def analyze_media(media_path, prompt, model_path, interval=10, job_id=None, comm
'message': f'Processing frame {i+1}/{total_frames} at {ts:.1f}s' 'message': f'Processing frame {i+1}/{total_frames} at {ts:.1f}s'
}) })
comm.send_message(progress_msg) comm.send_message(progress_msg)
if get_debug():
print(f"PROGRESS: Job {job_id} - {progress_percent}% - Processing frame {i+1}/{total_frames}") print(f"PROGRESS: Job {job_id} - {progress_percent}% - Processing frame {i+1}/{total_frames}")
# Check for cancellation # Check for cancellation
...@@ -283,6 +287,7 @@ def analyze_media(media_path, prompt, model_path, interval=10, job_id=None, comm ...@@ -283,6 +287,7 @@ def analyze_media(media_path, prompt, model_path, interval=10, job_id=None, comm
'message': f'Completed frame {i+1}/{total_frames} ({progress_percent}%)' 'message': f'Completed frame {i+1}/{total_frames} ({progress_percent}%)'
}) })
comm.send_message(progress_msg) comm.send_message(progress_msg)
if get_debug():
print(f"PROGRESS: Job {job_id} - {progress_percent}% - Completed frame {i+1}/{total_frames}") print(f"PROGRESS: Job {job_id} - {progress_percent}% - Completed frame {i+1}/{total_frames}")
if output_dir: if output_dir:
...@@ -300,6 +305,7 @@ def analyze_media(media_path, prompt, model_path, interval=10, job_id=None, comm ...@@ -300,6 +305,7 @@ def analyze_media(media_path, prompt, model_path, interval=10, job_id=None, comm
'message': 'Generating video summary' 'message': 'Generating video summary'
}) })
comm.send_message(progress_msg) comm.send_message(progress_msg)
if get_debug():
print(f"PROGRESS: Job {job_id} - 85% - Generating video summary") print(f"PROGRESS: Job {job_id} - 85% - Generating video summary")
# Check for cancellation before summary # Check for cancellation before summary
...@@ -339,6 +345,7 @@ def analyze_media(media_path, prompt, model_path, interval=10, job_id=None, comm ...@@ -339,6 +345,7 @@ def analyze_media(media_path, prompt, model_path, interval=10, job_id=None, comm
'message': 'Analysis completed' 'message': 'Analysis completed'
}) })
comm.send_message(progress_msg) comm.send_message(progress_msg)
if get_debug():
print(f"PROGRESS: Job {job_id} - 100% - Analysis completed") print(f"PROGRESS: Job {job_id} - 100% - Analysis completed")
result = f"Frame Descriptions:\n" + "\n".join(descriptions) + f"\n\nSummary:\n{summary}" result = f"Frame Descriptions:\n" + "\n".join(descriptions) + f"\n\nSummary:\n{summary}"
...@@ -355,6 +362,7 @@ def analyze_media(media_path, prompt, model_path, interval=10, job_id=None, comm ...@@ -355,6 +362,7 @@ def analyze_media(media_path, prompt, model_path, interval=10, job_id=None, comm
'message': 'Starting image analysis' 'message': 'Starting image analysis'
}) })
comm.send_message(progress_msg) comm.send_message(progress_msg)
if get_debug():
print(f"PROGRESS: Job {job_id} - 20% - Starting image analysis") print(f"PROGRESS: Job {job_id} - 20% - Starting image analysis")
# Check for cancellation before processing image # Check for cancellation before processing image
...@@ -371,6 +379,7 @@ def analyze_media(media_path, prompt, model_path, interval=10, job_id=None, comm ...@@ -371,6 +379,7 @@ def analyze_media(media_path, prompt, model_path, interval=10, job_id=None, comm
'message': 'Processing image with AI model' 'message': 'Processing image with AI model'
}) })
comm.send_message(progress_msg) comm.send_message(progress_msg)
if get_debug():
print(f"PROGRESS: Job {job_id} - 50% - Processing image with AI model") print(f"PROGRESS: Job {job_id} - 50% - Processing image with AI model")
result, tokens = analyze_single_image(media_path, full_prompt, model) result, tokens = analyze_single_image(media_path, full_prompt, model)
...@@ -386,6 +395,7 @@ def analyze_media(media_path, prompt, model_path, interval=10, job_id=None, comm ...@@ -386,6 +395,7 @@ def analyze_media(media_path, prompt, model_path, interval=10, job_id=None, comm
'message': 'Finalizing analysis results' 'message': 'Finalizing analysis results'
}) })
comm.send_message(progress_msg) comm.send_message(progress_msg)
if get_debug():
print(f"PROGRESS: Job {job_id} - 90% - Finalizing analysis results") print(f"PROGRESS: Job {job_id} - 90% - Finalizing analysis results")
# Send final progress update # Send final progress update
...@@ -397,6 +407,7 @@ def analyze_media(media_path, prompt, model_path, interval=10, job_id=None, comm ...@@ -397,6 +407,7 @@ def analyze_media(media_path, prompt, model_path, interval=10, job_id=None, comm
'message': 'Image analysis completed successfully' 'message': 'Image analysis completed successfully'
}) })
comm.send_message(progress_msg) comm.send_message(progress_msg)
if get_debug():
print(f"PROGRESS: Job {job_id} - 100% - Image analysis completed successfully") print(f"PROGRESS: Job {job_id} - 100% - Image analysis completed successfully")
torch.cuda.empty_cache() torch.cuda.empty_cache()
...@@ -434,6 +445,7 @@ def worker_process(backend_type: str): ...@@ -434,6 +445,7 @@ def worker_process(backend_type: str):
model_path = data.get('model_path', 'Qwen/Qwen2.5-VL-7B-Instruct') model_path = data.get('model_path', 'Qwen/Qwen2.5-VL-7B-Instruct')
interval = data.get('interval', 10) interval = data.get('interval', 10)
job_id = message.msg_id # Use message ID for job identification job_id = message.msg_id # Use message ID for job identification
if get_debug():
print(f"PROGRESS: Job {message.msg_id} accepted - Starting analysis") print(f"PROGRESS: Job {message.msg_id} accepted - Starting analysis")
print(f"DEBUG: Starting analysis of {media_path} with model {model_path} for job {job_id}") print(f"DEBUG: Starting analysis of {media_path} with model {model_path} for job {job_id}")
result, tokens_used = analyze_media(media_path, prompt, model_path, interval, job_id, comm) result, tokens_used = analyze_media(media_path, prompt, model_path, interval, job_id, comm)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment