androstj commited on
Commit
4126fb2
·
0 Parent(s):

initial commit

Browse files
Files changed (6) hide show
  1. .gitattributes +36 -0
  2. .gitignore +164 -0
  3. README.md +14 -0
  4. app.py +134 -0
  5. assets/bach.wav +3 -0
  6. requirements.txt +7 -0
.gitattributes ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tar filter=lfs diff=lfs merge=lfs -text
29
+ *.tflite filter=lfs diff=lfs merge=lfs -text
30
+ *.tgz filter=lfs diff=lfs merge=lfs -text
31
+ *.wasm filter=lfs diff=lfs merge=lfs -text
32
+ *.xz filter=lfs diff=lfs merge=lfs -text
33
+ *.zip filter=lfs diff=lfs merge=lfs -text
34
+ *.zst filter=lfs diff=lfs merge=lfs -text
35
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ *.wav filter=lfs diff=lfs merge=lfs -text
.gitignore ADDED
@@ -0,0 +1,164 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py,cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # poetry
98
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102
+ #poetry.lock
103
+
104
+ # pdm
105
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
106
+ #pdm.lock
107
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
108
+ # in version control.
109
+ # https://pdm.fming.dev/latest/usage/project/#working-with-version-control
110
+ .pdm.toml
111
+ .pdm-python
112
+ .pdm-build/
113
+
114
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
115
+ __pypackages__/
116
+
117
+ # Celery stuff
118
+ celerybeat-schedule
119
+ celerybeat.pid
120
+
121
+ # SageMath parsed files
122
+ *.sage.py
123
+
124
+ # Environments
125
+ .env
126
+ .venv
127
+ env/
128
+ venv/
129
+ ENV/
130
+ env.bak/
131
+ venv.bak/
132
+
133
+ # Spyder project settings
134
+ .spyderproject
135
+ .spyproject
136
+
137
+ # Rope project settings
138
+ .ropeproject
139
+
140
+ # mkdocs documentation
141
+ /site
142
+
143
+ # mypy
144
+ .mypy_cache/
145
+ .dmypy.json
146
+ dmypy.json
147
+
148
+ # Pyre type checker
149
+ .pyre/
150
+
151
+ # pytype static type analyzer
152
+ .pytype/
153
+
154
+ # Cython debug symbols
155
+ cython_debug/
156
+
157
+ # PyCharm
158
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
159
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
160
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
161
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
162
+ # .idea/
163
+ .vscode/
164
+ .ruff_cache/
README.md ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Audiobox Aesthetics
3
+ emoji: 📚
4
+ colorFrom: purple
5
+ colorTo: red
6
+ sdk: gradio
7
+ sdk_version: 5.16.0
8
+ app_file: app.py
9
+ pinned: false
10
+ license: cc-by-4.0
11
+ short_description: Demo for audiobox-aesthetics
12
+ ---
13
+
14
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,134 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (c) Meta Platforms, Inc. and affiliates.
2
+ # All rights reserved.
3
+
4
+ # This source code is licensed under the license found in the
5
+ # LICENSE file in the root directory of this source tree.
6
+
7
+ # This file is copied & modified from UNESCO/MMS/blob/main/asr.py
8
+
9
+ import gradio as gr
10
+ import numpy as np
11
+ import torch
12
+ import torchaudio
13
+ import json
14
+ from audiobox_aesthetics import infer as aes_infer
15
+ import plotly.graph_objects as go
16
+
17
+ ASR_EXAMPLES = [("assets/bach.wav")]
18
+
19
+ aes_predictor = aes_infer.initialize_model(None)
20
+
21
+
22
+ def transcribe(audio_data=None):
23
+ if not audio_data:
24
+ return "<<ERROR: Empty Audio Input>>"
25
+
26
+ if isinstance(audio_data, tuple):
27
+ # microphone
28
+ sr, audio_samples = audio_data
29
+ audio_samples = (audio_samples / 32768.0).astype(np.float32)
30
+ audio_samples = torch.tensor(audio_samples)
31
+ if audio_samples.ndim == 1:
32
+ audio_samples = audio_samples[:, None]
33
+
34
+ assert audio_samples.ndim == 2
35
+ audio_samples = audio_samples.t()
36
+ else:
37
+ # file upload
38
+ if not isinstance(audio_data, str):
39
+ return "<<ERROR: Invalid Audio Input Instance: {}>>".format(
40
+ type(audio_data)
41
+ )
42
+ audio_samples, sr = torchaudio.load(audio_data)
43
+
44
+ transcription = json.loads(
45
+ aes_predictor.forward([{"path": audio_samples, "sample_rate": sr}])[0]
46
+ )
47
+
48
+ # reorder like paper figures
49
+ transcription = {
50
+ "Production Quality": transcription["PQ"],
51
+ "Production Complexity": transcription["PC"],
52
+ "Content Enjoyment": transcription["CE"],
53
+ "Content Usefulness": transcription["CU"],
54
+ }
55
+
56
+ # Create a Plotly bar plot
57
+ fig = go.Figure()
58
+ colors = ["#b1d8ff", "#fee2f5", "#cefac4", "#d2d3ff"]
59
+ values = list(transcription.values())
60
+ keys = list(transcription.keys())
61
+
62
+ fig.add_trace(
63
+ go.Bar(
64
+ x=keys,
65
+ y=values,
66
+ text=[f"{v:.2f}" for v in values], # Format text to 2 decimal places
67
+ textposition="outside", # Position text outside the bars
68
+ marker=dict(color=colors),
69
+ )
70
+ )
71
+
72
+ # Set the range for the y-axis
73
+ fig.update_layout(
74
+ yaxis=dict(range=[0, 10]),
75
+ xaxis_title="Metrics",
76
+ yaxis_title="Scores",
77
+ )
78
+ return fig
79
+
80
+
81
+ main_interface = gr.Interface(
82
+ fn=transcribe,
83
+ inputs=[
84
+ gr.Audio(),
85
+ ],
86
+ # outputs="text",
87
+ outputs=gr.Plot(),
88
+ examples=ASR_EXAMPLES,
89
+ title="Audiobox Aesthetics Demo Prediction",
90
+ description=("Play some audio through microphone or upload the file."),
91
+ article="",
92
+ allow_flagging="never",
93
+ )
94
+
95
+ disclaimer = """
96
+ ## Disclaimer
97
+ """
98
+
99
+ with gr.Blocks() as demo:
100
+ gr.HTML(
101
+ """
102
+ <div style="text-align: center;">
103
+ <h1>
104
+ Meta Audiobox Aesthetics: Unified Automatic Quality Assessment for Speech, Music, and Sound
105
+ </h1>
106
+ </div>
107
+ """
108
+ )
109
+
110
+ gr.Markdown(
111
+ "<p align='center' style='font-size: 20px;'>See our <a href='https://arxiv.org/abs/2502.05139'>paper</a>, Github <a href='https://github.com/facebookresearch/audiobox-aesthetics'>repo</a> and HuggingFace <a href='https://huggingface.co/facebook/audiobox-aesthetics'>repo</a> </p>"
112
+ )
113
+ gr.HTML(
114
+ """<center><a href="https://huggingface.co/spaces/facebook/audiobox-aesthetics?duplicate=true" style="display: inline-block;margin-top: .5em;margin-right: .25em;" target="_blank"><img style="margin-bottom: 0em;display: inline;margin-top: -.25em;" src="https://bit.ly/3gLdBN6" alt="Duplicate Space"></a> for more control and no queue.</center>"""
115
+ )
116
+
117
+ main_interface.render()
118
+
119
+ gr.HTML(
120
+ """
121
+ <div class="footer" style="text-align:center">
122
+ <p>
123
+ Model by <a href="https://ai.facebook.com" style="text-decoration: underline;" target="_blank">Meta AI</a> - Gradio Demo by 🤗 Hugging Face
124
+ </p>
125
+ </div>
126
+ """
127
+ )
128
+
129
+ # with gr.Row():
130
+ # gr.Markdown(disclaimer)
131
+
132
+ if __name__ == "__main__":
133
+ demo.queue()
134
+ demo.launch()
assets/bach.wav ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e2bff9b5066c65e8b983d454f749559122a3039b42c513f8ed565cd9a6433402
3
+ size 1769550
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ pip>=23.2
2
+ gradio==5.16.0
3
+ torch>=2.2.0
4
+ torchaudio
5
+ tqdm
6
+ audiobox_aesthetics>=0.0.2
7
+ plotly==6.0.0