Spaces:
Paused
Paused
File size: 1,687 Bytes
bd48304 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | """Offline test of the V5.2 callback chain using fake model outputs.
Does not replace the production models; no network/model download in tests.
"""
from unittest.mock import patch
import numpy as np
import soundfile as sf
import torch
import deepvoice_gradio_app_v45 as app
class MockSpectra(torch.nn.Module):
def forward(self, data):
assert data.device.type == 'cpu'
return torch.tensor([[1.0, 0.0]], dtype=torch.float32)
class MockWhisper:
def __call__(self, data, **kwargs):
assert data['sampling_rate'] == 16000
assert kwargs['generate_kwargs']['language'] == 'korean'
return {'text':'์์ ๊ณ์ข๋ก ์ก๊ธํด ์ฃผ์ธ์.', 'chunks':[
{'text':'์์ ๊ณ์ข๋ก ์ก๊ธํด ์ฃผ์ธ์.', 'timestamp':(0,1.0)}
]}
def test_cpu_inference_and_rules_connected(tmp_path):
sound = .2*np.sin(2*np.pi*220*np.arange(16000,dtype=np.float32)/16000)
filename = tmp_path/'demo.wav'
sf.write(filename, sound, 16000)
with patch.object(app, 'get_detector', return_value=MockSpectra()), \
patch.object(app, 'get_asr_pipeline', return_value=MockWhisper()):
card, stats, raw, transcript, text = app.cpu_infer_and_transcribe(str(filename))
assert 'AI ์์ฑ ์์ฌ ์ ์' in raw
assert '์์ฑ ๊ธธ์ด' in stats
assert '์์ ๊ณ์ข๋ก ์ก๊ธํด ์ฃผ์ธ์' in transcript
assert '์์ ๊ณ์ข๋ก ์ก๊ธํด ์ฃผ์ธ์' in text
summary, advice, laws, status, overview = app.analyze_and_update_overview(
transcript, text, False, False, raw)
assert '์์ ๊ณ์ข' in summary
assert '๋ณด์ด์คํผ์ฑ ์ํ๋' in overview
assert 'AI ์์ฑ ์์ฌ ์ ์' in overview
|