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