Spaces:
Paused
Paused
Download tests/test_cpu_callback_mock.py from jhk131/deepvoice-hackathon: direct link, hf CLI and curl.
- Browser
- Download file 1.69 kB
-
https://huggingface.co/spaces/jhk131/deepvoice-hackathon/resolve/main/tests/test_cpu_callback_mock.py
- Command line
-
hf download hf://spaces/jhk131/deepvoice-hackathon/tests/test_cpu_callback_mock.py
-
curl -L -o test_cpu_callback_mock.py https://huggingface.co/spaces/jhk131/deepvoice-hackathon/resolve/main/tests/test_cpu_callback_mock.py
1.69 kB
| """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 | |