Spaces:
Sleeping
Sleeping
Create pipeline.py
Browse files- pipeline.py +20 -0
pipeline.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from utils_audio import convert_to_wav
|
| 2 |
+
from to_cha import to_cha_from_wav
|
| 3 |
+
from cha_json import cha_to_json_path
|
| 4 |
+
from model_infer import AphasiaClassifier
|
| 5 |
+
from output import format_result
|
| 6 |
+
|
| 7 |
+
def run_pipeline(in_media_path: str, out_style: str = "json") -> str:
|
| 8 |
+
wav = convert_to_wav(in_media_path, sr=16000, mono=True)
|
| 9 |
+
cha = to_cha_from_wav(wav, lang="eng")
|
| 10 |
+
jsn = cha_to_json_path(cha)
|
| 11 |
+
|
| 12 |
+
clf = AphasiaClassifier()
|
| 13 |
+
pred = clf.predict_from_json(jsn)
|
| 14 |
+
|
| 15 |
+
return format_result(pred, style=out_style)
|
| 16 |
+
|
| 17 |
+
if __name__ == "__main__":
|
| 18 |
+
import sys
|
| 19 |
+
media = sys.argv[1]
|
| 20 |
+
print(run_pipeline(media, out_style="text")) # or "json"
|