Open-Source Frontier Voice AI
Python
fix: use weights_only=True with safe_globals for voice preset loading (CWE-502)
pengzhiliang303b2833e01c
diff --git a/demo/realtime_model_inference_from_file.py b/demo/realtime_model_inference_from_file.pyindex 1d56b07..2a2e711 100644--- a/demo/realtime_model_inference_from_file.py+++ b/demo/realtime_model_inference_from_file.py@@ -10,6 +10,8 @@ import globfrom vibevoice.modular.modeling_vibevoice_streaming_inference import VibeVoiceStreamingForConditionalGenerationInferencefrom vibevoice.processor.vibevoice_streaming_processor import VibeVoiceStreamingProcessor+from transformers.cache_utils import DynamicCache+from transformers.modeling_outputs import BaseModelOutputWithPastfrom transformers.utils import logginglogging.set_verbosity_info()@@ -222,7 +224,8 @@ def main():target_device = args.device if args.device != "cpu" else "cpu"voice_sample = voice_mapper.get_voice_path(args.speaker_name)print(f"Using voice preset for {args.speaker_name}: {voice_sample}")- all_prefilled_outputs = torch.load(voice_sample, map_location=target_device, weights_only=False)+ with torch.serialization.safe_globals([BaseModelOutputWithPast, DynamicCache]):+ all_prefilled_outputs = torch.load(voice_sample, map_location=target_device, weights_only=True)# Prepare inputs for the modelinputs = processor.process_input_with_cached_prompt(diff --git a/demo/web/app.py b/demo/web/app.pyindex 1b45117..4985c7d 100644--- a/demo/web/app.py+++ b/demo/web/app.py@@ -11,6 +11,8 @@ from typing import Any, Callable, Dict, Iterator, Optional, Tuple, castimport numpy as npimport torch+from transformers.cache_utils import DynamicCache+from transformers.modeling_outputs import BaseModelOutputWithPastfrom fastapi import FastAPI, WebSocketfrom fastapi.responses import FileResponsefrom fastapi.staticfiles import StaticFiles@@ -158,11 +160,12 @@ class StreamingTTSService:preset_path = self.voice_presets[key]print(f"[startup] Loading voice preset {key} from {preset_path}")print(f"[startup] Loading prefilled prompt from {preset_path}")- prefilled_outputs = torch.load(- preset_path,- map_location=self._torch_device,- weights_only=False,- )+ with torch.serialization.safe_globals([BaseModelOutputWithPast, DynamicCache]):+ prefilled_outputs = torch.load(+ preset_path,+ map_location=self._torch_device,+ weights_only=True,+ )self._voice_cache[key] = prefilled_outputsreturn self._voice_cache[key]