limwoojae0445 commited on
Commit
1ab2ab7
β€’
1 Parent(s): 9991384

Add application file

Browse files
Files changed (5) hide show
  1. .gitignore +163 -0
  2. app.py +110 -0
  3. favicon.ico +0 -0
  4. packages.txt +1 -0
  5. requirements.txt +7 -0
.gitignore ADDED
@@ -0,0 +1,163 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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/#use-with-ide
110
+ .pdm.toml
111
+
112
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
113
+ __pypackages__/
114
+
115
+ # Celery stuff
116
+ celerybeat-schedule
117
+ celerybeat.pid
118
+
119
+ # SageMath parsed files
120
+ *.sage.py
121
+
122
+ # Environments
123
+ .env
124
+ .venv
125
+ env/
126
+ venv/
127
+ ENV/
128
+ env.bak/
129
+ venv.bak/
130
+ .vscode
131
+
132
+ # Spyder project settings
133
+ .spyderproject
134
+ .spyproject
135
+
136
+ # Rope project settings
137
+ .ropeproject
138
+
139
+ # mkdocs documentation
140
+ /site
141
+
142
+ # mypy
143
+ .mypy_cache/
144
+ .dmypy.json
145
+ dmypy.json
146
+
147
+ # Pyre type checker
148
+ .pyre/
149
+
150
+ # pytype static type analyzer
151
+ .pytype/
152
+
153
+ # Cython debug symbols
154
+ cython_debug/
155
+
156
+ # PyCharm
157
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
158
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
159
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
160
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
161
+ #.idea/
162
+
163
+ enhanced_*
app.py ADDED
@@ -0,0 +1,110 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import glob
3
+ import torchaudio
4
+ import torchaudio.transforms as T
5
+ import numpy as np
6
+ from matplotlib import pyplot as plt
7
+ import librosa
8
+ import librosa.display
9
+ from df import enhance, init_df
10
+ import streamlit as st
11
+ from streamlit.components.v1 import html
12
+
13
+ app_title = "μ†ŒμŒ μ–΅μ œ 도ꡬ"
14
+ model, df_state, _ = init_df() # Load default model
15
+ df_sr = 48000
16
+
17
+
18
+ def display_audio_info(audio, title):
19
+ # 두 개의 컬럼 생성
20
+ col1, col2 = st.columns(2)
21
+
22
+ audio = np.clip(audio, -1.0, 1.0)
23
+ if len(np.shape(audio)) == 2:
24
+ audio = audio[0]
25
+
26
+ # μ™Όμͺ½ μ»¬λŸΌμ— μŠ€νŽ™νŠΈλ‘œκ·Έλž¨ ν‘œμ‹œ
27
+ with col1:
28
+ st.markdown(f"### {title} - Spectrogram")
29
+ D = librosa.stft(audio) # STFT of y
30
+ S_db = librosa.amplitude_to_db(np.abs(D), ref=np.max)
31
+ fig, ax = plt.subplots()
32
+ img = librosa.display.specshow(
33
+ S_db, x_axis='time', y_axis='linear', ax=ax)
34
+ fig.colorbar(img, ax=ax, format="%+2.f dB")
35
+ st.pyplot(fig)
36
+
37
+ # 였λ₯Έμͺ½ μ»¬λŸΌμ— νŒŒν˜• ν‘œμ‹œ
38
+ with col2:
39
+ st.markdown(f"### {title} - Waveform")
40
+ fig, ax = plt.subplots()
41
+ plt.plot(audio)
42
+ ax.set_xticks([])
43
+ ax.set_ylim(-1, 1)
44
+ st.pyplot(fig)
45
+
46
+
47
+ def main():
48
+ st.set_page_config(page_title=app_title, page_icon="favicon.ico",
49
+ layout="centered", initial_sidebar_state="auto", menu_items=None)
50
+
51
+ button = """<script type="text/javascript" src="https://cdnjs.buymeacoffee.com/1.0.0/button.prod.min.js" data-name="bmc-button" data-slug="woojae" data-color="#FFDD00" data-emoji="β˜•" data-font="Cookie" data-text="Buy me a coffee" data-outline-color="#000000" data-font-color="#000000" data-coffee-color="#ffffff" ></script>"""
52
+
53
+ st.title(app_title)
54
+ st.divider()
55
+ st.header('μ†μ‰½κ²Œ λΆˆν•„μš”ν•œ μ†ŒμŒμ„ μ œκ±°ν•˜μ„Έμš”!')
56
+
57
+ uploaded_file = st.file_uploader(
58
+ "λ³€ν™˜ν•  νŒŒμΌμ„ μ—…λ‘œλ“œ ν•΄μ£Όμ„Έμš”. (지원 ν˜•μ‹: .wav, .mp3, .opus)")
59
+
60
+ if uploaded_file:
61
+ # 이전에 λ‹€μš΄λ‘œλ“œ ν•œ νŒŒμΌμ„ μ‚­μ œ
62
+ files_to_remove = glob.glob('enhanced_*')
63
+ for file in files_to_remove:
64
+ os.remove(file)
65
+
66
+ uploaded_file_type = uploaded_file.type.split('/')[-1]
67
+ print(uploaded_file_type)
68
+ if uploaded_file_type not in ['wav', 'mpeg', 'ogg']:
69
+ st.text('μ§€μ›ν•˜μ§€ μ•ŠλŠ” 파일 ν˜•μ‹μž…λ‹ˆλ‹€.')
70
+ else:
71
+ with st.spinner('μ†ŒμŒ μ œκ±°ν•˜λŠ” 쀑'):
72
+ noisy_audio, sr = torchaudio.load(uploaded_file)
73
+ print("np.shape(noisy_audio)", np.shape(noisy_audio))
74
+ st.audio(noisy_audio.numpy(), sample_rate=sr)
75
+
76
+ # μƒ˜ν”Œλ§ λ ˆμ΄νŠΈκ°€ 48000Hzκ°€ 아닐 경우 λ¦¬μƒ˜ν”Œλ§
77
+ if sr != df_sr:
78
+ resampler = T.Resample(orig_freq=sr, new_freq=df_sr)
79
+ noisy_audio = resampler(noisy_audio)
80
+ display_audio_info(noisy_audio.numpy(), "μž…λ ₯")
81
+
82
+ with st.spinner('μ†ŒμŒ μ œκ±°ν•˜λŠ” 쀑'):
83
+ output_audio = enhance(model, df_state, noisy_audio)
84
+ enhanced_audio = output_audio
85
+ st.divider()
86
+ # μƒ˜ν”Œλ§ λ ˆμ΄νŠΈκ°€ 48000Hzκ°€ 아닐 경우 λ¦¬μƒ˜ν”Œλ§
87
+ if sr != df_sr:
88
+ resampler = T.Resample(orig_freq=df_sr, new_freq=sr)
89
+ enhanced_audio = resampler(enhanced_audio)
90
+ st.audio(enhanced_audio.numpy(), sample_rate=sr)
91
+ display_audio_info(output_audio.numpy(), "좜λ ₯")
92
+
93
+ html(button, height=70, width=240)
94
+
95
+ st.markdown(
96
+ """
97
+ <style>
98
+ iframe[width="240"] {
99
+ position: fixed;
100
+ bottom: 30px;
101
+ right: 10px;
102
+ }
103
+ </style>
104
+ """,
105
+ unsafe_allow_html=True,
106
+ )
107
+
108
+
109
+ if __name__ == '__main__':
110
+ main()
favicon.ico ADDED
packages.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ ffmpeg
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ numpy
2
+ torch
3
+ torchaudio
4
+ deepfilternet
5
+ librosa
6
+ matplotlib
7
+ streamlit