Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
MPAI-Private
MPAI-CAE
arp
Audio Analyzer
Commits
7f2bb3a1
Commit
7f2bb3a1
authored
Apr 23, 2023
by
Matteo
Browse files
refactor to pythonic package
parent
6b43a93e
Changes
10
Hide whitespace changes
Inline
Side-by-side
.dockerignore
View file @
7f2bb3a1
test/
test
s
/
.editorconfig
.gitignore
.env
\ No newline at end of file
Dockerfile
View file @
7f2bb3a1
...
...
@@ -4,10 +4,10 @@ WORKDIR /app
COPY
. ./
RUN
apt
install
ffmpeg
-y
RUN
apt
update
&&
apt
install
ffmpeg
-y
RUN
poetry
install
--no-cache
--only
main
VOLUME
[ "/data" ]
CMD
["poetry", "run", "python", "src/server.py"]
\ No newline at end of file
CMD
["poetry", "run", "python", "src/audio_analyzer/server.py"]
\ No newline at end of file
Makefile
View file @
7f2bb3a1
...
...
@@ -44,9 +44,6 @@ install:
test
:
$(POETRY)
pytest
test-coverage
:
$(POETRY)
pytest
--cov-config
.coveragerc
--cov-report
term-missing
--cov-report
html
--cov
=
src
format
:
$(POETRY)
ruff check
--fix
./src ./tests
...
...
pyproject.toml
View file @
7f2bb3a1
...
...
@@ -5,6 +5,13 @@ description = "MPAI CAE-ARP Audio Analyser"
authors
=
[
"Matteo Spanio <dev2@audioinnova.com>"
]
license
=
"GPLv3"
readme
=
"README.md"
packages
=
[
{
include
=
"audio_analyzer"
,
from
=
"src"
}
,
{
include
=
"ml"
,
from
=
"src"
}
]
[tool.poetry.scripts]
audio-analyser
=
'audio_analyzer.cli:main'
[tool.poetry.dependencies]
python
=
"^3.10"
...
...
src/audio_analyzer/__init__.py
0 → 100644
View file @
7f2bb3a1
src/classifier.py
→
src/
audio_analyzer/
classifier.py
View file @
7f2bb3a1
...
...
@@ -2,10 +2,10 @@ from pandas import DataFrame
from
mpai_cae_arp.audio
import
AudioWave
from
mpai_cae_arp.types.irregularity
import
Irregularity
,
IrregularityProperties
from
ml
.classification
import
load_model
,
C
lassification
Result
from
ml
import
c
lassification
as
mlc
def
classification_to_irreg_properties
(
classification
:
ClassificationResult
)
->
IrregularityProperties
:
def
classification_to_irreg_properties
(
classification
:
mlc
.
ClassificationResult
)
->
IrregularityProperties
:
return
IrregularityProperties
(
reading_equalisation
=
classification
.
reading_equalization
,
reading_speed
=
classification
.
reading_speed
,
...
...
@@ -19,7 +19,7 @@ def classify(audio_blocks: DataFrame) -> list[IrregularityProperties]:
audio_blocks_classification
=
[]
# classify the audioBlocks
eq_classifier
=
load_model
(
"pretto_and_berio_nono_classifier"
)
eq_classifier
=
mlc
.
load_model
(
"pretto_and_berio_nono_classifier"
)
prediction
=
eq_classifier
.
predict
(
audio_blocks
)
for
i
in
range
(
len
(
prediction
)):
...
...
src/cli.py
→
src/
audio_analyzer/
cli.py
View file @
7f2bb3a1
...
...
@@ -2,13 +2,14 @@ import argparse
import
os
import
sys
from
rich.console
import
Console
import
segment_finder
as
sf
import
classifier
as
cl
from
mpai_cae_arp.types.irregularity
import
IrregularityFile
,
Source
from
mpai_cae_arp.files
import
File
,
FileType
from
mpai_cae_arp.io
import
prettify
,
Style
from
.
import
segment_finder
as
sf
from
.
import
classifier
as
cl
def
get_args
()
->
tuple
[
str
|
None
,
str
|
None
]:
if
len
(
sys
.
argv
)
>
1
:
...
...
@@ -27,7 +28,6 @@ def get_args() -> tuple[str | None, str | None]:
return
os
.
getenv
(
"WORKING_DIRECTORY"
),
os
.
getenv
(
"FILES_NAME"
)
def
exit_with_error
(
error_message
:
str
,
console
)
->
None
:
console
.
print
(
f
"[red bold]Error:
{
error_message
}
"
)
quit
(
os
.
EX_USAGE
)
...
...
src/client.py
→
src/
audio_analyzer/
client.py
View file @
7f2bb3a1
from
rich.console
import
Console
from
rich.markdown
import
Markdown
import
os
import
grpc
...
...
@@ -9,7 +8,7 @@ from mpai_cae_arp.network import arp_pb2_grpc
channels
=
{
"AudioAnalyser"
:
grpc
.
insecure_channel
(
"[::]:50051"
),
"VideoAnalyser"
:
grpc
.
insecure_channel
(
"[::]:50052"
),
"TapeIrregularityClassifier"
:
grpc
.
insecure_channel
(
"[::]:5005
1/tape-irregularity-classifier
"
),
"TapeIrregularityClassifier"
:
grpc
.
insecure_channel
(
"[::]:5005
3
"
),
"TapeAudioRestoration"
:
grpc
.
insecure_channel
(
"[::]:50051/tape-audio-restoration"
),
"Packager"
:
grpc
.
insecure_channel
(
"[::]:50051/packager"
),
}
...
...
@@ -18,15 +17,15 @@ def run(console: Console):
audio_analyser
=
arp_pb2_grpc
.
AIMStub
(
channels
[
"AudioAnalyser"
])
video_analyser
=
arp_pb2_grpc
.
AIMStub
(
channels
[
"VideoAnalyser"
])
tape_irreg_classifier
=
arp_pb2_grpc
.
AIMStub
(
channels
[
"TapeIrregularityClassifier"
])
request
=
arp_pb2
.
InfoRequest
()
for
analyser
in
[
audio_analyser
,
video_analyser
]:
for
analyser
in
[
audio_analyser
,
video_analyser
,
tape_irreg_classifier
]:
response
=
analyser
.
getInfo
(
request
)
console
.
print
(
"[bold]{}[/], v{}"
.
format
(
response
.
title
,
response
.
version
))
console
.
print
(
Markdown
(
response
.
description
))
request
=
arp_pb2
.
JobRequest
(
working_dir
=
"
..
/data"
,
working_dir
=
"/data"
,
files_name
=
"BERIO100"
,
index
=
1
,
)
...
...
@@ -64,8 +63,19 @@ def run(console: Console):
exit
(
os
.
EX_SOFTWARE
)
console
.
print
(
result
.
message
)
with
console
.
status
(
"[bold]Computing TapeIrregularityClassifier..."
,
spinner
=
"bouncingBall"
):
for
result
in
tape_irreg_classifier
.
work
(
request
):
if
result
.
status
==
"error"
:
console
.
print
(
"[bold red]Error![/] :boom:"
)
console
.
print
(
f
"[italic red]
{
result
.
message
}
"
)
for
channel
in
channels
.
values
():
channel
.
close
()
exit
(
os
.
EX_SOFTWARE
)
console
.
print
(
result
.
message
)
channels
[
"AudioAnalyser"
].
close
()
channels
[
"VideoAnalyser"
].
close
()
channels
[
"TapeIrregularityClassifier"
].
close
()
console
.
print
(
"[bold green]Success![/] :tada:"
)
...
...
src/segment_finder.py
→
src/
audio_analyzer/
segment_finder.py
View file @
7f2bb3a1
File moved
src/server.py
→
src/
audio_analyzer/
server.py
View file @
7f2bb3a1
...
...
@@ -16,8 +16,8 @@ from mpai_cae_arp.network.arp_pb2 import (
License
,
)
import
segment_finder
as
sf
import
classifier
as
cl
from
.
import
segment_finder
as
sf
from
.
import
classifier
as
cl
info
=
File
(
'config.yml'
,
FileType
.
YAML
).
get_content
()
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment