Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,3 @@
|
|
| 1 |
-
|
| 2 |
import gradio as gr
|
| 3 |
import os
|
| 4 |
import uuid
|
|
@@ -19,10 +18,12 @@ def clean_file_name(file_path):
|
|
| 19 |
cleaned = re.sub(r'[^a-zA-Z\d]+', '_', file_name)
|
| 20 |
clean_name = re.sub(r'_+', '_', cleaned).strip('_')
|
| 21 |
random_uuid = uuid.uuid4().hex[:6]
|
|
|
|
| 22 |
clean_file_path = os.path.join(
|
| 23 |
os.path.dirname(file_path),
|
| 24 |
clean_name + f"_{random_uuid}" + file_extension
|
| 25 |
)
|
|
|
|
| 26 |
return clean_file_path
|
| 27 |
|
| 28 |
|
|
@@ -37,6 +38,7 @@ def calculate_duration(file_path):
|
|
| 37 |
|
| 38 |
FILE_TIMESTAMPS = {}
|
| 39 |
|
|
|
|
| 40 |
def track_file(file_path):
|
| 41 |
FILE_TIMESTAMPS[file_path] = time.time()
|
| 42 |
|
|
@@ -44,6 +46,7 @@ def track_file(file_path):
|
|
| 44 |
def cleanup_tracked_files(max_age_seconds=3600):
|
| 45 |
now = time.time()
|
| 46 |
to_delete = []
|
|
|
|
| 47 |
for file_path, created_time in FILE_TIMESTAMPS.items():
|
| 48 |
if now - created_time > max_age_seconds:
|
| 49 |
if os.path.exists(file_path):
|
|
@@ -52,7 +55,9 @@ def cleanup_tracked_files(max_age_seconds=3600):
|
|
| 52 |
print(f"Deleted: {file_path}")
|
| 53 |
except Exception as e:
|
| 54 |
print(f"Error deleting {file_path}: {e}")
|
|
|
|
| 55 |
to_delete.append(file_path)
|
|
|
|
| 56 |
for f in to_delete:
|
| 57 |
FILE_TIMESTAMPS.pop(f, None)
|
| 58 |
|
|
@@ -63,6 +68,7 @@ def start_cleanup_worker(interval=3600):
|
|
| 63 |
print("Cleaning tracked files...")
|
| 64 |
cleanup_tracked_files()
|
| 65 |
time.sleep(interval)
|
|
|
|
| 66 |
import threading
|
| 67 |
threading.Thread(target=worker, daemon=True).start()
|
| 68 |
|
|
@@ -73,37 +79,57 @@ def start_cleanup_worker(interval=3600):
|
|
| 73 |
|
| 74 |
def remove_silence(file_path, minimum_silence=50):
|
| 75 |
sound = AudioSegment.from_file(file_path)
|
|
|
|
| 76 |
audio_chunks = split_on_silence(
|
| 77 |
sound,
|
| 78 |
min_silence_len=100,
|
| 79 |
silence_thresh=-45,
|
| 80 |
keep_silence=minimum_silence
|
| 81 |
)
|
|
|
|
| 82 |
combined = AudioSegment.empty()
|
|
|
|
| 83 |
for chunk in audio_chunks:
|
| 84 |
combined += chunk
|
|
|
|
| 85 |
output_path = clean_file_name(file_path)
|
| 86 |
combined.export(output_path)
|
|
|
|
| 87 |
return output_path
|
| 88 |
|
| 89 |
|
| 90 |
def process_audio(audio_file, seconds=0.05):
|
| 91 |
if audio_file is None:
|
| 92 |
return None, None, "No file uploaded", None
|
|
|
|
| 93 |
if not os.path.exists(audio_file):
|
| 94 |
return None, None, "File not found", None
|
| 95 |
|
| 96 |
track_file(audio_file)
|
|
|
|
| 97 |
keep_silence = int(seconds * 1000)
|
| 98 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
track_file(output_audio_file)
|
| 100 |
|
| 101 |
before = calculate_duration(audio_file)
|
| 102 |
-
after
|
| 103 |
-
text = f"Old Duration: {before:.3f} seconds\nNew Duration: {after:.3f} seconds"
|
| 104 |
|
| 105 |
-
|
| 106 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
|
| 108 |
|
| 109 |
def enhance_audio(file_path):
|
|
@@ -112,20 +138,32 @@ def enhance_audio(file_path):
|
|
| 112 |
1. Noise Reduction (noisereduce, if installed β optional)
|
| 113 |
2. High-Pass Filter (scipy, removes rumble below 80 Hz)
|
| 114 |
3. Normalization (pydub effects.normalize)
|
|
|
|
| 115 |
Gracefully skips unavailable libraries.
|
| 116 |
"""
|
|
|
|
| 117 |
if file_path is None:
|
| 118 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
if not os.path.exists(file_path):
|
| 120 |
return None, None, "File not found."
|
| 121 |
|
| 122 |
-
sound
|
| 123 |
-
|
| 124 |
-
|
|
|
|
| 125 |
sample_width = sound.sample_width
|
| 126 |
|
| 127 |
# Convert to float32 in range [-1, 1]
|
| 128 |
-
raw = np.array(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 129 |
if sample_width == 1:
|
| 130 |
raw = (raw - 128.0) / 128.0
|
| 131 |
elif sample_width == 2:
|
|
@@ -139,49 +177,87 @@ def enhance_audio(file_path):
|
|
| 139 |
# Step 1 β Noise Reduction
|
| 140 |
try:
|
| 141 |
import noisereduce as nr
|
|
|
|
| 142 |
if channels == 2:
|
| 143 |
-
raw[:, 0] = nr.reduce_noise(
|
| 144 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 145 |
else:
|
| 146 |
-
raw = nr.reduce_noise(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 147 |
except Exception:
|
| 148 |
pass
|
| 149 |
|
| 150 |
-
# Step 2 β High-Pass Filter
|
| 151 |
try:
|
| 152 |
from scipy.signal import butter, sosfilt
|
| 153 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 154 |
if channels == 2:
|
| 155 |
raw[:, 0] = sosfilt(sos, raw[:, 0])
|
| 156 |
raw[:, 1] = sosfilt(sos, raw[:, 1])
|
| 157 |
else:
|
| 158 |
raw = sosfilt(sos, raw)
|
|
|
|
| 159 |
except Exception:
|
| 160 |
pass
|
| 161 |
|
| 162 |
if channels == 2:
|
| 163 |
raw = raw.flatten()
|
| 164 |
|
| 165 |
-
raw
|
|
|
|
| 166 |
out_samples = (raw * 32768.0).astype(np.int16)
|
| 167 |
|
| 168 |
enhanced_segment = AudioSegment(
|
| 169 |
out_samples.tobytes(),
|
| 170 |
-
frame_rate
|
| 171 |
-
sample_width
|
| 172 |
-
channels
|
| 173 |
)
|
| 174 |
|
| 175 |
# Step 3 β Normalize volume
|
| 176 |
enhanced_segment = effects.normalize(enhanced_segment)
|
| 177 |
|
| 178 |
-
base
|
|
|
|
|
|
|
|
|
|
| 179 |
output_path = base + "_enhanced.wav"
|
| 180 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 181 |
track_file(output_path)
|
| 182 |
|
| 183 |
duration = calculate_duration(output_path)
|
| 184 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 185 |
return output_path, output_path, text
|
| 186 |
|
| 187 |
|
|
@@ -190,13 +266,23 @@ def enhance_audio(file_path):
|
|
| 190 |
# βββββββββββββββββββββββββββββββββββββββββββββ
|
| 191 |
|
| 192 |
def ui():
|
|
|
|
| 193 |
theme = gr.themes.Soft(
|
| 194 |
-
font=[
|
|
|
|
|
|
|
|
|
|
|
|
|
| 195 |
)
|
| 196 |
|
| 197 |
css = """
|
| 198 |
-
.gradio-container {
|
| 199 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 200 |
|
| 201 |
@keyframes rgb-glow {
|
| 202 |
0% { color: #ff0080; text-shadow: 0 0 12px #ff0080, 0 0 24px #ff0080; }
|
|
@@ -207,6 +293,7 @@ def ui():
|
|
| 207 |
83% { color: #a855f7; text-shadow: 0 0 12px #a855f7, 0 0 24px #a855f7; }
|
| 208 |
100% { color: #ff0080; text-shadow: 0 0 12px #ff0080, 0 0 24px #ff0080; }
|
| 209 |
}
|
|
|
|
| 210 |
@keyframes rgb-border {
|
| 211 |
0% { border-color: #ff0080; box-shadow: 0 0 10px #ff0080; }
|
| 212 |
16% { border-color: #ff8c00; box-shadow: 0 0 10px #ff8c00; }
|
|
@@ -216,14 +303,25 @@ def ui():
|
|
| 216 |
83% { border-color: #a855f7; box-shadow: 0 0 10px #a855f7; }
|
| 217 |
100% { border-color: #ff0080; box-shadow: 0 0 10px #ff0080; }
|
| 218 |
}
|
|
|
|
| 219 |
@keyframes gradient-shift {
|
| 220 |
0% { background-position: 0% 50%; }
|
| 221 |
50% { background-position: 100% 50%; }
|
| 222 |
100% { background-position: 0% 50%; }
|
| 223 |
}
|
|
|
|
| 224 |
@keyframes pulse-glow {
|
| 225 |
-
0%, 100% {
|
| 226 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 227 |
}
|
| 228 |
|
| 229 |
.rgb-title {
|
|
@@ -241,60 +339,209 @@ def ui():
|
|
| 241 |
font-weight: 800;
|
| 242 |
letter-spacing: 3px;
|
| 243 |
text-transform: uppercase;
|
| 244 |
-
animation:
|
|
|
|
|
|
|
| 245 |
background: rgba(0,0,0,0.04);
|
| 246 |
margin-top: 10px;
|
| 247 |
}
|
| 248 |
|
| 249 |
/* Remove Silence primary button */
|
| 250 |
button.primary {
|
| 251 |
-
background: linear-gradient(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 252 |
color: white !important;
|
| 253 |
font-weight: 700 !important;
|
| 254 |
border: none !important;
|
| 255 |
border-radius: 12px !important;
|
| 256 |
padding: 13px 20px !important;
|
| 257 |
font-size: 1.05em !important;
|
| 258 |
-
|
|
|
|
|
|
|
|
|
|
| 259 |
transition: all 0.3s ease !important;
|
| 260 |
}
|
|
|
|
| 261 |
button.primary:hover {
|
| 262 |
-
background: linear-gradient(
|
| 263 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 264 |
transform: translateY(-1px) !important;
|
| 265 |
}
|
| 266 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 267 |
/* Animated divider */
|
| 268 |
.enhance-divider {
|
| 269 |
margin: 36px auto 22px;
|
| 270 |
max-width: 95%;
|
| 271 |
height: 2px;
|
| 272 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 273 |
background-size: 200% 200%;
|
| 274 |
animation: gradient-shift 4s ease infinite;
|
| 275 |
border-radius: 2px;
|
| 276 |
}
|
| 277 |
|
| 278 |
/* Enhance header card */
|
| 279 |
-
.enhance-header {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 280 |
.enhance-label {
|
| 281 |
display: inline-flex;
|
| 282 |
flex-direction: column;
|
| 283 |
align-items: center;
|
| 284 |
gap: 4px;
|
| 285 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 286 |
border: 2px solid #00c8ff;
|
| 287 |
border-radius: 16px;
|
| 288 |
padding: 12px 32px;
|
|
|
|
| 289 |
animation: rgb-border 3s linear infinite;
|
| 290 |
}
|
|
|
|
| 291 |
.etitle {
|
| 292 |
font-size: 1.2em;
|
| 293 |
font-weight: 800;
|
| 294 |
letter-spacing: 2px;
|
| 295 |
text-transform: uppercase;
|
|
|
|
| 296 |
animation: rgb-glow 3s linear infinite;
|
| 297 |
}
|
|
|
|
| 298 |
.esub {
|
| 299 |
font-size: 0.75em;
|
| 300 |
color: #94a3b8;
|
|
@@ -303,94 +550,241 @@ def ui():
|
|
| 303 |
|
| 304 |
/* Enhance button */
|
| 305 |
.enhance-btn button {
|
| 306 |
-
background: linear-gradient(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 307 |
background-size: 200% 200% !important;
|
| 308 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 309 |
color: #00c8ff !important;
|
| 310 |
font-weight: 800 !important;
|
|
|
|
| 311 |
border: 2px solid #00c8ff !important;
|
| 312 |
border-radius: 12px !important;
|
|
|
|
| 313 |
padding: 13px 20px !important;
|
| 314 |
font-size: 1.05em !important;
|
|
|
|
| 315 |
letter-spacing: 1px !important;
|
| 316 |
text-transform: uppercase !important;
|
| 317 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 318 |
}
|
|
|
|
| 319 |
.enhance-btn button:hover {
|
| 320 |
color: #ffffff !important;
|
| 321 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 322 |
border-color: transparent !important;
|
|
|
|
| 323 |
transform: translateY(-2px) !important;
|
| 324 |
-
|
|
|
|
|
|
|
|
|
|
| 325 |
animation: none !important;
|
| 326 |
}
|
| 327 |
"""
|
| 328 |
|
| 329 |
-
with gr.Blocks(
|
|
|
|
|
|
|
|
|
|
| 330 |
|
| 331 |
processed_file_state = gr.State(value=None)
|
| 332 |
|
| 333 |
# ββ HEADER ββ
|
| 334 |
gr.HTML("""
|
| 335 |
<div style="text-align:center; margin:24px auto 20px; max-width:820px;">
|
| 336 |
-
<h1 class="rgb-title"
|
|
|
|
| 337 |
π Remove Silence From Audio
|
| 338 |
</h1>
|
|
|
|
| 339 |
<p style="font-size:1.05em; color:#555; margin:0 0 8px;">
|
| 340 |
Upload an MP3 or WAV file, and it will remove silent parts from it.
|
| 341 |
</p>
|
|
|
|
| 342 |
<p style="font-size:0.8em; color:#999; margin-bottom:16px;">
|
| 343 |
β οΈ Please don't upload copyrighted content β it can take this Space offline.
|
| 344 |
</p>
|
| 345 |
-
|
|
|
|
|
|
|
|
|
|
| 346 |
</div>
|
| 347 |
""")
|
| 348 |
|
| 349 |
# ββ REMOVE SILENCE ββ
|
| 350 |
with gr.Row():
|
|
|
|
| 351 |
with gr.Column(scale=1):
|
|
|
|
| 352 |
audio_input = gr.Audio(
|
| 353 |
label="π Upload Audio",
|
| 354 |
type="filepath",
|
| 355 |
sources=["upload", "microphone"]
|
| 356 |
)
|
|
|
|
| 357 |
silence_threshold = gr.Number(
|
| 358 |
label="Keep Silence Upto (In seconds)",
|
| 359 |
value=0.05
|
| 360 |
)
|
| 361 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 362 |
|
| 363 |
with gr.Column(scale=1):
|
| 364 |
-
|
| 365 |
-
|
| 366 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 367 |
|
| 368 |
submit_btn.click(
|
| 369 |
-
fn=
|
| 370 |
-
inputs=[
|
| 371 |
-
outputs=[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 372 |
)
|
| 373 |
|
| 374 |
# ββ DIVIDER ββ
|
| 375 |
-
gr.HTML(
|
|
|
|
|
|
|
| 376 |
|
| 377 |
# ββ ENHANCE HEADER ββ
|
| 378 |
gr.HTML("""
|
| 379 |
<div class="enhance-header">
|
| 380 |
<div class="enhance-label">
|
| 381 |
-
<span class="etitle">
|
| 382 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 383 |
</div>
|
| 384 |
</div>
|
| 385 |
""")
|
| 386 |
|
| 387 |
# ββ ENHANCE SECTION ββ
|
| 388 |
with gr.Row():
|
|
|
|
| 389 |
with gr.Column(scale=1):
|
|
|
|
| 390 |
enhance_btn = gr.Button(
|
| 391 |
"β¨ Enhance Audio",
|
| 392 |
elem_classes=["enhance-btn"]
|
| 393 |
)
|
|
|
|
| 394 |
enhance_status = gr.Textbox(
|
| 395 |
label="β‘ Status",
|
| 396 |
interactive=False,
|
|
@@ -398,13 +792,23 @@ def ui():
|
|
| 398 |
)
|
| 399 |
|
| 400 |
with gr.Column(scale=1):
|
| 401 |
-
|
| 402 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 403 |
|
| 404 |
enhance_btn.click(
|
| 405 |
fn=enhance_audio,
|
| 406 |
inputs=[processed_file_state],
|
| 407 |
-
outputs=[
|
|
|
|
|
|
|
|
|
|
|
|
|
| 408 |
)
|
| 409 |
|
| 410 |
return demo
|
|
@@ -416,13 +820,31 @@ def ui():
|
|
| 416 |
|
| 417 |
import click
|
| 418 |
|
|
|
|
| 419 |
@click.command()
|
| 420 |
-
@click.option(
|
| 421 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 422 |
def main(debug, share):
|
|
|
|
| 423 |
start_cleanup_worker()
|
|
|
|
| 424 |
demo = ui()
|
| 425 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 426 |
|
| 427 |
if __name__ == "__main__":
|
| 428 |
main()
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import os
|
| 3 |
import uuid
|
|
|
|
| 18 |
cleaned = re.sub(r'[^a-zA-Z\d]+', '_', file_name)
|
| 19 |
clean_name = re.sub(r'_+', '_', cleaned).strip('_')
|
| 20 |
random_uuid = uuid.uuid4().hex[:6]
|
| 21 |
+
|
| 22 |
clean_file_path = os.path.join(
|
| 23 |
os.path.dirname(file_path),
|
| 24 |
clean_name + f"_{random_uuid}" + file_extension
|
| 25 |
)
|
| 26 |
+
|
| 27 |
return clean_file_path
|
| 28 |
|
| 29 |
|
|
|
|
| 38 |
|
| 39 |
FILE_TIMESTAMPS = {}
|
| 40 |
|
| 41 |
+
|
| 42 |
def track_file(file_path):
|
| 43 |
FILE_TIMESTAMPS[file_path] = time.time()
|
| 44 |
|
|
|
|
| 46 |
def cleanup_tracked_files(max_age_seconds=3600):
|
| 47 |
now = time.time()
|
| 48 |
to_delete = []
|
| 49 |
+
|
| 50 |
for file_path, created_time in FILE_TIMESTAMPS.items():
|
| 51 |
if now - created_time > max_age_seconds:
|
| 52 |
if os.path.exists(file_path):
|
|
|
|
| 55 |
print(f"Deleted: {file_path}")
|
| 56 |
except Exception as e:
|
| 57 |
print(f"Error deleting {file_path}: {e}")
|
| 58 |
+
|
| 59 |
to_delete.append(file_path)
|
| 60 |
+
|
| 61 |
for f in to_delete:
|
| 62 |
FILE_TIMESTAMPS.pop(f, None)
|
| 63 |
|
|
|
|
| 68 |
print("Cleaning tracked files...")
|
| 69 |
cleanup_tracked_files()
|
| 70 |
time.sleep(interval)
|
| 71 |
+
|
| 72 |
import threading
|
| 73 |
threading.Thread(target=worker, daemon=True).start()
|
| 74 |
|
|
|
|
| 79 |
|
| 80 |
def remove_silence(file_path, minimum_silence=50):
|
| 81 |
sound = AudioSegment.from_file(file_path)
|
| 82 |
+
|
| 83 |
audio_chunks = split_on_silence(
|
| 84 |
sound,
|
| 85 |
min_silence_len=100,
|
| 86 |
silence_thresh=-45,
|
| 87 |
keep_silence=minimum_silence
|
| 88 |
)
|
| 89 |
+
|
| 90 |
combined = AudioSegment.empty()
|
| 91 |
+
|
| 92 |
for chunk in audio_chunks:
|
| 93 |
combined += chunk
|
| 94 |
+
|
| 95 |
output_path = clean_file_name(file_path)
|
| 96 |
combined.export(output_path)
|
| 97 |
+
|
| 98 |
return output_path
|
| 99 |
|
| 100 |
|
| 101 |
def process_audio(audio_file, seconds=0.05):
|
| 102 |
if audio_file is None:
|
| 103 |
return None, None, "No file uploaded", None
|
| 104 |
+
|
| 105 |
if not os.path.exists(audio_file):
|
| 106 |
return None, None, "File not found", None
|
| 107 |
|
| 108 |
track_file(audio_file)
|
| 109 |
+
|
| 110 |
keep_silence = int(seconds * 1000)
|
| 111 |
+
|
| 112 |
+
output_audio_file = remove_silence(
|
| 113 |
+
audio_file,
|
| 114 |
+
minimum_silence=keep_silence
|
| 115 |
+
)
|
| 116 |
+
|
| 117 |
track_file(output_audio_file)
|
| 118 |
|
| 119 |
before = calculate_duration(audio_file)
|
| 120 |
+
after = calculate_duration(output_audio_file)
|
|
|
|
| 121 |
|
| 122 |
+
text = (
|
| 123 |
+
f"Old Duration: {before:.3f} seconds\n"
|
| 124 |
+
f"New Duration: {after:.3f} seconds"
|
| 125 |
+
)
|
| 126 |
+
|
| 127 |
+
return (
|
| 128 |
+
output_audio_file,
|
| 129 |
+
output_audio_file,
|
| 130 |
+
text,
|
| 131 |
+
output_audio_file
|
| 132 |
+
)
|
| 133 |
|
| 134 |
|
| 135 |
def enhance_audio(file_path):
|
|
|
|
| 138 |
1. Noise Reduction (noisereduce, if installed β optional)
|
| 139 |
2. High-Pass Filter (scipy, removes rumble below 80 Hz)
|
| 140 |
3. Normalization (pydub effects.normalize)
|
| 141 |
+
|
| 142 |
Gracefully skips unavailable libraries.
|
| 143 |
"""
|
| 144 |
+
|
| 145 |
if file_path is None:
|
| 146 |
+
return (
|
| 147 |
+
None,
|
| 148 |
+
None,
|
| 149 |
+
"No audio to enhance. Please run Remove Silence first."
|
| 150 |
+
)
|
| 151 |
+
|
| 152 |
if not os.path.exists(file_path):
|
| 153 |
return None, None, "File not found."
|
| 154 |
|
| 155 |
+
sound = AudioSegment.from_file(file_path)
|
| 156 |
+
|
| 157 |
+
sample_rate = sound.frame_rate
|
| 158 |
+
channels = sound.channels
|
| 159 |
sample_width = sound.sample_width
|
| 160 |
|
| 161 |
# Convert to float32 in range [-1, 1]
|
| 162 |
+
raw = np.array(
|
| 163 |
+
sound.get_array_of_samples(),
|
| 164 |
+
dtype=np.float32
|
| 165 |
+
)
|
| 166 |
+
|
| 167 |
if sample_width == 1:
|
| 168 |
raw = (raw - 128.0) / 128.0
|
| 169 |
elif sample_width == 2:
|
|
|
|
| 177 |
# Step 1 β Noise Reduction
|
| 178 |
try:
|
| 179 |
import noisereduce as nr
|
| 180 |
+
|
| 181 |
if channels == 2:
|
| 182 |
+
raw[:, 0] = nr.reduce_noise(
|
| 183 |
+
y=raw[:, 0],
|
| 184 |
+
sr=sample_rate,
|
| 185 |
+
prop_decrease=0.75
|
| 186 |
+
)
|
| 187 |
+
|
| 188 |
+
raw[:, 1] = nr.reduce_noise(
|
| 189 |
+
y=raw[:, 1],
|
| 190 |
+
sr=sample_rate,
|
| 191 |
+
prop_decrease=0.75
|
| 192 |
+
)
|
| 193 |
else:
|
| 194 |
+
raw = nr.reduce_noise(
|
| 195 |
+
y=raw,
|
| 196 |
+
sr=sample_rate,
|
| 197 |
+
prop_decrease=0.75
|
| 198 |
+
)
|
| 199 |
+
|
| 200 |
except Exception:
|
| 201 |
pass
|
| 202 |
|
| 203 |
+
# Step 2 β High-Pass Filter
|
| 204 |
try:
|
| 205 |
from scipy.signal import butter, sosfilt
|
| 206 |
+
|
| 207 |
+
sos = butter(
|
| 208 |
+
4,
|
| 209 |
+
80,
|
| 210 |
+
btype="hp",
|
| 211 |
+
fs=sample_rate,
|
| 212 |
+
output="sos"
|
| 213 |
+
)
|
| 214 |
+
|
| 215 |
if channels == 2:
|
| 216 |
raw[:, 0] = sosfilt(sos, raw[:, 0])
|
| 217 |
raw[:, 1] = sosfilt(sos, raw[:, 1])
|
| 218 |
else:
|
| 219 |
raw = sosfilt(sos, raw)
|
| 220 |
+
|
| 221 |
except Exception:
|
| 222 |
pass
|
| 223 |
|
| 224 |
if channels == 2:
|
| 225 |
raw = raw.flatten()
|
| 226 |
|
| 227 |
+
raw = np.clip(raw, -1.0, 1.0)
|
| 228 |
+
|
| 229 |
out_samples = (raw * 32768.0).astype(np.int16)
|
| 230 |
|
| 231 |
enhanced_segment = AudioSegment(
|
| 232 |
out_samples.tobytes(),
|
| 233 |
+
frame_rate=sample_rate,
|
| 234 |
+
sample_width=2,
|
| 235 |
+
channels=channels
|
| 236 |
)
|
| 237 |
|
| 238 |
# Step 3 β Normalize volume
|
| 239 |
enhanced_segment = effects.normalize(enhanced_segment)
|
| 240 |
|
| 241 |
+
base = os.path.splitext(
|
| 242 |
+
clean_file_name(file_path)
|
| 243 |
+
)[0]
|
| 244 |
+
|
| 245 |
output_path = base + "_enhanced.wav"
|
| 246 |
+
|
| 247 |
+
enhanced_segment.export(
|
| 248 |
+
output_path,
|
| 249 |
+
format="wav"
|
| 250 |
+
)
|
| 251 |
+
|
| 252 |
track_file(output_path)
|
| 253 |
|
| 254 |
duration = calculate_duration(output_path)
|
| 255 |
+
|
| 256 |
+
text = (
|
| 257 |
+
f"Enhanced Successfully!\n"
|
| 258 |
+
f"Duration: {duration:.3f} seconds"
|
| 259 |
+
)
|
| 260 |
+
|
| 261 |
return output_path, output_path, text
|
| 262 |
|
| 263 |
|
|
|
|
| 266 |
# βββββββββββββββββββββββββββββββββββββββββββββ
|
| 267 |
|
| 268 |
def ui():
|
| 269 |
+
|
| 270 |
theme = gr.themes.Soft(
|
| 271 |
+
font=[
|
| 272 |
+
gr.themes.GoogleFont("Source Sans Pro"),
|
| 273 |
+
"Arial",
|
| 274 |
+
"sans-serif"
|
| 275 |
+
]
|
| 276 |
)
|
| 277 |
|
| 278 |
css = """
|
| 279 |
+
.gradio-container {
|
| 280 |
+
max-width: none !important;
|
| 281 |
+
}
|
| 282 |
+
|
| 283 |
+
.tab-content {
|
| 284 |
+
padding: 20px;
|
| 285 |
+
}
|
| 286 |
|
| 287 |
@keyframes rgb-glow {
|
| 288 |
0% { color: #ff0080; text-shadow: 0 0 12px #ff0080, 0 0 24px #ff0080; }
|
|
|
|
| 293 |
83% { color: #a855f7; text-shadow: 0 0 12px #a855f7, 0 0 24px #a855f7; }
|
| 294 |
100% { color: #ff0080; text-shadow: 0 0 12px #ff0080, 0 0 24px #ff0080; }
|
| 295 |
}
|
| 296 |
+
|
| 297 |
@keyframes rgb-border {
|
| 298 |
0% { border-color: #ff0080; box-shadow: 0 0 10px #ff0080; }
|
| 299 |
16% { border-color: #ff8c00; box-shadow: 0 0 10px #ff8c00; }
|
|
|
|
| 303 |
83% { border-color: #a855f7; box-shadow: 0 0 10px #a855f7; }
|
| 304 |
100% { border-color: #ff0080; box-shadow: 0 0 10px #ff0080; }
|
| 305 |
}
|
| 306 |
+
|
| 307 |
@keyframes gradient-shift {
|
| 308 |
0% { background-position: 0% 50%; }
|
| 309 |
50% { background-position: 100% 50%; }
|
| 310 |
100% { background-position: 0% 50%; }
|
| 311 |
}
|
| 312 |
+
|
| 313 |
@keyframes pulse-glow {
|
| 314 |
+
0%, 100% {
|
| 315 |
+
box-shadow:
|
| 316 |
+
0 0 15px rgba(0,200,255,0.45),
|
| 317 |
+
0 4px 20px rgba(0,0,0,0.3);
|
| 318 |
+
}
|
| 319 |
+
|
| 320 |
+
50% {
|
| 321 |
+
box-shadow:
|
| 322 |
+
0 0 38px rgba(168,85,247,0.65),
|
| 323 |
+
0 4px 20px rgba(0,0,0,0.3);
|
| 324 |
+
}
|
| 325 |
}
|
| 326 |
|
| 327 |
.rgb-title {
|
|
|
|
| 339 |
font-weight: 800;
|
| 340 |
letter-spacing: 3px;
|
| 341 |
text-transform: uppercase;
|
| 342 |
+
animation:
|
| 343 |
+
rgb-glow 3s linear infinite,
|
| 344 |
+
rgb-border 3s linear infinite;
|
| 345 |
background: rgba(0,0,0,0.04);
|
| 346 |
margin-top: 10px;
|
| 347 |
}
|
| 348 |
|
| 349 |
/* Remove Silence primary button */
|
| 350 |
button.primary {
|
| 351 |
+
background: linear-gradient(
|
| 352 |
+
135deg,
|
| 353 |
+
#2563eb,
|
| 354 |
+
#1e40af
|
| 355 |
+
) !important;
|
| 356 |
+
|
| 357 |
color: white !important;
|
| 358 |
font-weight: 700 !important;
|
| 359 |
border: none !important;
|
| 360 |
border-radius: 12px !important;
|
| 361 |
padding: 13px 20px !important;
|
| 362 |
font-size: 1.05em !important;
|
| 363 |
+
|
| 364 |
+
box-shadow:
|
| 365 |
+
0 4px 15px rgba(37,99,235,0.4) !important;
|
| 366 |
+
|
| 367 |
transition: all 0.3s ease !important;
|
| 368 |
}
|
| 369 |
+
|
| 370 |
button.primary:hover {
|
| 371 |
+
background: linear-gradient(
|
| 372 |
+
135deg,
|
| 373 |
+
#1d4ed8,
|
| 374 |
+
#1e3a8a
|
| 375 |
+
) !important;
|
| 376 |
+
|
| 377 |
+
box-shadow:
|
| 378 |
+
0 6px 25px rgba(37,99,235,0.65) !important;
|
| 379 |
+
|
| 380 |
transform: translateY(-1px) !important;
|
| 381 |
}
|
| 382 |
|
| 383 |
+
/* Closed-site popup */
|
| 384 |
+
#closed-site-popup {
|
| 385 |
+
position: fixed;
|
| 386 |
+
inset: 0;
|
| 387 |
+
z-index: 999999;
|
| 388 |
+
display: flex;
|
| 389 |
+
align-items: center;
|
| 390 |
+
justify-content: center;
|
| 391 |
+
padding: 20px;
|
| 392 |
+
|
| 393 |
+
background: rgba(15, 23, 42, 0.78);
|
| 394 |
+
backdrop-filter: blur(7px);
|
| 395 |
+
}
|
| 396 |
+
|
| 397 |
+
.closed-popup-card {
|
| 398 |
+
width: min(440px, 100%);
|
| 399 |
+
background: #ffffff;
|
| 400 |
+
color: #0f172a;
|
| 401 |
+
border-radius: 24px;
|
| 402 |
+
padding: 30px 24px 24px;
|
| 403 |
+
text-align: center;
|
| 404 |
+
|
| 405 |
+
box-shadow:
|
| 406 |
+
0 30px 80px rgba(0,0,0,0.4);
|
| 407 |
+
|
| 408 |
+
animation: closedPopupIn 0.3s ease;
|
| 409 |
+
}
|
| 410 |
+
|
| 411 |
+
@keyframes closedPopupIn {
|
| 412 |
+
from {
|
| 413 |
+
opacity: 0;
|
| 414 |
+
transform: translateY(20px) scale(0.94);
|
| 415 |
+
}
|
| 416 |
+
|
| 417 |
+
to {
|
| 418 |
+
opacity: 1;
|
| 419 |
+
transform: translateY(0) scale(1);
|
| 420 |
+
}
|
| 421 |
+
}
|
| 422 |
+
|
| 423 |
+
.closed-popup-icon {
|
| 424 |
+
width: 72px;
|
| 425 |
+
height: 72px;
|
| 426 |
+
margin: 0 auto 16px;
|
| 427 |
+
|
| 428 |
+
display: grid;
|
| 429 |
+
place-items: center;
|
| 430 |
+
|
| 431 |
+
border-radius: 50%;
|
| 432 |
+
background: #fee2e2;
|
| 433 |
+
|
| 434 |
+
font-size: 34px;
|
| 435 |
+
}
|
| 436 |
+
|
| 437 |
+
.closed-popup-title {
|
| 438 |
+
margin: 0 0 10px;
|
| 439 |
+
font-size: 24px;
|
| 440 |
+
font-weight: 900;
|
| 441 |
+
}
|
| 442 |
+
|
| 443 |
+
.closed-popup-text {
|
| 444 |
+
margin: 0 auto;
|
| 445 |
+
max-width: 360px;
|
| 446 |
+
|
| 447 |
+
color: #64748b;
|
| 448 |
+
font-size: 14px;
|
| 449 |
+
line-height: 1.6;
|
| 450 |
+
}
|
| 451 |
+
|
| 452 |
+
.closed-popup-site {
|
| 453 |
+
margin-top: 18px;
|
| 454 |
+
padding: 12px 16px;
|
| 455 |
+
|
| 456 |
+
border-radius: 12px;
|
| 457 |
+
|
| 458 |
+
background: #eff6ff;
|
| 459 |
+
color: #1d4ed8;
|
| 460 |
+
|
| 461 |
+
font-size: 13px;
|
| 462 |
+
font-weight: 800;
|
| 463 |
+
|
| 464 |
+
word-break: break-word;
|
| 465 |
+
}
|
| 466 |
+
|
| 467 |
+
.closed-popup-countdown {
|
| 468 |
+
margin-top: 12px;
|
| 469 |
+
color: #94a3b8;
|
| 470 |
+
font-size: 12px;
|
| 471 |
+
}
|
| 472 |
+
|
| 473 |
+
.closed-popup-manual {
|
| 474 |
+
display: inline-block;
|
| 475 |
+
margin-top: 18px;
|
| 476 |
+
padding: 11px 18px;
|
| 477 |
+
|
| 478 |
+
border-radius: 12px;
|
| 479 |
+
background: linear-gradient(
|
| 480 |
+
135deg,
|
| 481 |
+
#2563eb,
|
| 482 |
+
#1e40af
|
| 483 |
+
);
|
| 484 |
+
|
| 485 |
+
color: #ffffff !important;
|
| 486 |
+
text-decoration: none !important;
|
| 487 |
+
font-size: 13px;
|
| 488 |
+
font-weight: 800;
|
| 489 |
+
}
|
| 490 |
+
|
| 491 |
/* Animated divider */
|
| 492 |
.enhance-divider {
|
| 493 |
margin: 36px auto 22px;
|
| 494 |
max-width: 95%;
|
| 495 |
height: 2px;
|
| 496 |
+
|
| 497 |
+
background: linear-gradient(
|
| 498 |
+
90deg,
|
| 499 |
+
transparent,
|
| 500 |
+
#00c8ff,
|
| 501 |
+
#a855f7,
|
| 502 |
+
#ff0080,
|
| 503 |
+
transparent
|
| 504 |
+
);
|
| 505 |
+
|
| 506 |
background-size: 200% 200%;
|
| 507 |
animation: gradient-shift 4s ease infinite;
|
| 508 |
border-radius: 2px;
|
| 509 |
}
|
| 510 |
|
| 511 |
/* Enhance header card */
|
| 512 |
+
.enhance-header {
|
| 513 |
+
text-align: center;
|
| 514 |
+
margin-bottom: 20px;
|
| 515 |
+
}
|
| 516 |
+
|
| 517 |
.enhance-label {
|
| 518 |
display: inline-flex;
|
| 519 |
flex-direction: column;
|
| 520 |
align-items: center;
|
| 521 |
gap: 4px;
|
| 522 |
+
|
| 523 |
+
background: linear-gradient(
|
| 524 |
+
135deg,
|
| 525 |
+
#0f172a,
|
| 526 |
+
#1e293b
|
| 527 |
+
);
|
| 528 |
+
|
| 529 |
border: 2px solid #00c8ff;
|
| 530 |
border-radius: 16px;
|
| 531 |
padding: 12px 32px;
|
| 532 |
+
|
| 533 |
animation: rgb-border 3s linear infinite;
|
| 534 |
}
|
| 535 |
+
|
| 536 |
.etitle {
|
| 537 |
font-size: 1.2em;
|
| 538 |
font-weight: 800;
|
| 539 |
letter-spacing: 2px;
|
| 540 |
text-transform: uppercase;
|
| 541 |
+
|
| 542 |
animation: rgb-glow 3s linear infinite;
|
| 543 |
}
|
| 544 |
+
|
| 545 |
.esub {
|
| 546 |
font-size: 0.75em;
|
| 547 |
color: #94a3b8;
|
|
|
|
| 550 |
|
| 551 |
/* Enhance button */
|
| 552 |
.enhance-btn button {
|
| 553 |
+
background: linear-gradient(
|
| 554 |
+
135deg,
|
| 555 |
+
#0f172a,
|
| 556 |
+
#1e293b,
|
| 557 |
+
#0f172a
|
| 558 |
+
) !important;
|
| 559 |
+
|
| 560 |
background-size: 200% 200% !important;
|
| 561 |
+
|
| 562 |
+
animation:
|
| 563 |
+
gradient-shift 4s ease infinite,
|
| 564 |
+
pulse-glow 2.5s ease-in-out infinite !important;
|
| 565 |
+
|
| 566 |
color: #00c8ff !important;
|
| 567 |
font-weight: 800 !important;
|
| 568 |
+
|
| 569 |
border: 2px solid #00c8ff !important;
|
| 570 |
border-radius: 12px !important;
|
| 571 |
+
|
| 572 |
padding: 13px 20px !important;
|
| 573 |
font-size: 1.05em !important;
|
| 574 |
+
|
| 575 |
letter-spacing: 1px !important;
|
| 576 |
text-transform: uppercase !important;
|
| 577 |
+
|
| 578 |
+
transition:
|
| 579 |
+
color 0.3s ease,
|
| 580 |
+
background 0.3s ease,
|
| 581 |
+
transform 0.2s ease !important;
|
| 582 |
}
|
| 583 |
+
|
| 584 |
.enhance-btn button:hover {
|
| 585 |
color: #ffffff !important;
|
| 586 |
+
|
| 587 |
+
background: linear-gradient(
|
| 588 |
+
135deg,
|
| 589 |
+
#00c8ff,
|
| 590 |
+
#a855f7
|
| 591 |
+
) !important;
|
| 592 |
+
|
| 593 |
border-color: transparent !important;
|
| 594 |
+
|
| 595 |
transform: translateY(-2px) !important;
|
| 596 |
+
|
| 597 |
+
box-shadow:
|
| 598 |
+
0 8px 30px rgba(0,200,255,0.55) !important;
|
| 599 |
+
|
| 600 |
animation: none !important;
|
| 601 |
}
|
| 602 |
"""
|
| 603 |
|
| 604 |
+
with gr.Blocks(
|
| 605 |
+
theme=theme,
|
| 606 |
+
css=css
|
| 607 |
+
) as demo:
|
| 608 |
|
| 609 |
processed_file_state = gr.State(value=None)
|
| 610 |
|
| 611 |
# ββ HEADER ββ
|
| 612 |
gr.HTML("""
|
| 613 |
<div style="text-align:center; margin:24px auto 20px; max-width:820px;">
|
| 614 |
+
<h1 class="rgb-title"
|
| 615 |
+
style="font-size:2.5em; margin-bottom:6px;">
|
| 616 |
π Remove Silence From Audio
|
| 617 |
</h1>
|
| 618 |
+
|
| 619 |
<p style="font-size:1.05em; color:#555; margin:0 0 8px;">
|
| 620 |
Upload an MP3 or WAV file, and it will remove silent parts from it.
|
| 621 |
</p>
|
| 622 |
+
|
| 623 |
<p style="font-size:0.8em; color:#999; margin-bottom:16px;">
|
| 624 |
β οΈ Please don't upload copyrighted content β it can take this Space offline.
|
| 625 |
</p>
|
| 626 |
+
|
| 627 |
+
<div class="made-by-badge">
|
| 628 |
+
β¦ Made by Deepu β¦
|
| 629 |
+
</div>
|
| 630 |
</div>
|
| 631 |
""")
|
| 632 |
|
| 633 |
# ββ REMOVE SILENCE ββ
|
| 634 |
with gr.Row():
|
| 635 |
+
|
| 636 |
with gr.Column(scale=1):
|
| 637 |
+
|
| 638 |
audio_input = gr.Audio(
|
| 639 |
label="π Upload Audio",
|
| 640 |
type="filepath",
|
| 641 |
sources=["upload", "microphone"]
|
| 642 |
)
|
| 643 |
+
|
| 644 |
silence_threshold = gr.Number(
|
| 645 |
label="Keep Silence Upto (In seconds)",
|
| 646 |
value=0.05
|
| 647 |
)
|
| 648 |
+
|
| 649 |
+
submit_btn = gr.Button(
|
| 650 |
+
"π Remove Silence",
|
| 651 |
+
variant="primary"
|
| 652 |
+
)
|
| 653 |
|
| 654 |
with gr.Column(scale=1):
|
| 655 |
+
|
| 656 |
+
audio_output = gr.Audio(
|
| 657 |
+
label="βΆ Play Audio"
|
| 658 |
+
)
|
| 659 |
+
|
| 660 |
+
file_output = gr.File(
|
| 661 |
+
label="β¬ Download Audio File"
|
| 662 |
+
)
|
| 663 |
+
|
| 664 |
+
duration_output = gr.Textbox(
|
| 665 |
+
label="π Duration Info"
|
| 666 |
+
)
|
| 667 |
+
|
| 668 |
+
# βββββββββββββββββββββββββββββββββββββββββ
|
| 669 |
+
# CLOSED SITE REDIRECT
|
| 670 |
+
# IMPORTANT:
|
| 671 |
+
# Remove Silence no longer calls process_audio.
|
| 672 |
+
# Clicking it only shows the notice and redirects.
|
| 673 |
+
# βββββββββββββββββββββββββββββββββββββββββ
|
| 674 |
|
| 675 |
submit_btn.click(
|
| 676 |
+
fn=None,
|
| 677 |
+
inputs=[],
|
| 678 |
+
outputs=[],
|
| 679 |
+
js="""
|
| 680 |
+
() => {
|
| 681 |
+
const oldPopup = document.getElementById("closed-site-popup");
|
| 682 |
+
|
| 683 |
+
if (oldPopup) {
|
| 684 |
+
oldPopup.remove();
|
| 685 |
+
}
|
| 686 |
+
|
| 687 |
+
const overlay = document.createElement("div");
|
| 688 |
+
overlay.id = "closed-site-popup";
|
| 689 |
+
|
| 690 |
+
overlay.innerHTML = `
|
| 691 |
+
<div class="closed-popup-card">
|
| 692 |
+
|
| 693 |
+
<div class="closed-popup-icon">
|
| 694 |
+
π
|
| 695 |
+
</div>
|
| 696 |
+
|
| 697 |
+
<h2 class="closed-popup-title">
|
| 698 |
+
This HF site has been closed
|
| 699 |
+
</h2>
|
| 700 |
+
|
| 701 |
+
<p class="closed-popup-text">
|
| 702 |
+
This Hugging Face site is no longer available.
|
| 703 |
+
Please continue using our new website.
|
| 704 |
+
</p>
|
| 705 |
+
|
| 706 |
+
<div class="closed-popup-site">
|
| 707 |
+
π audio.offexmail.online
|
| 708 |
+
</div>
|
| 709 |
+
|
| 710 |
+
<div class="closed-popup-countdown"
|
| 711 |
+
id="closed-popup-countdown">
|
| 712 |
+
Redirecting in 2 seconds...
|
| 713 |
+
</div>
|
| 714 |
+
|
| 715 |
+
<a
|
| 716 |
+
class="closed-popup-manual"
|
| 717 |
+
href="https://audio.offexmail.online"
|
| 718 |
+
>
|
| 719 |
+
Continue to Website β
|
| 720 |
+
</a>
|
| 721 |
+
|
| 722 |
+
</div>
|
| 723 |
+
`;
|
| 724 |
+
|
| 725 |
+
document.body.appendChild(overlay);
|
| 726 |
+
|
| 727 |
+
let seconds = 2;
|
| 728 |
+
|
| 729 |
+
const countdown =
|
| 730 |
+
document.getElementById(
|
| 731 |
+
"closed-popup-countdown"
|
| 732 |
+
);
|
| 733 |
+
|
| 734 |
+
const interval = setInterval(() => {
|
| 735 |
+
seconds--;
|
| 736 |
+
|
| 737 |
+
if (seconds > 0) {
|
| 738 |
+
countdown.textContent =
|
| 739 |
+
"Redirecting in " + seconds + " second...";
|
| 740 |
+
}
|
| 741 |
+
}, 1000);
|
| 742 |
+
|
| 743 |
+
setTimeout(() => {
|
| 744 |
+
clearInterval(interval);
|
| 745 |
+
|
| 746 |
+
window.location.replace(
|
| 747 |
+
"https://audio.offexmail.online"
|
| 748 |
+
);
|
| 749 |
+
}, 2000);
|
| 750 |
+
|
| 751 |
+
return [];
|
| 752 |
+
}
|
| 753 |
+
"""
|
| 754 |
)
|
| 755 |
|
| 756 |
# ββ DIVIDER ββ
|
| 757 |
+
gr.HTML(
|
| 758 |
+
'<div class="enhance-divider"></div>'
|
| 759 |
+
)
|
| 760 |
|
| 761 |
# ββ ENHANCE HEADER ββ
|
| 762 |
gr.HTML("""
|
| 763 |
<div class="enhance-header">
|
| 764 |
<div class="enhance-label">
|
| 765 |
+
<span class="etitle">
|
| 766 |
+
β¨ Audio Enhancer
|
| 767 |
+
</span>
|
| 768 |
+
|
| 769 |
+
<span class="esub">
|
| 770 |
+
Noise Reduction Β·
|
| 771 |
+
High-Pass Filter Β·
|
| 772 |
+
Volume Normalize
|
| 773 |
+
</span>
|
| 774 |
</div>
|
| 775 |
</div>
|
| 776 |
""")
|
| 777 |
|
| 778 |
# ββ ENHANCE SECTION ββ
|
| 779 |
with gr.Row():
|
| 780 |
+
|
| 781 |
with gr.Column(scale=1):
|
| 782 |
+
|
| 783 |
enhance_btn = gr.Button(
|
| 784 |
"β¨ Enhance Audio",
|
| 785 |
elem_classes=["enhance-btn"]
|
| 786 |
)
|
| 787 |
+
|
| 788 |
enhance_status = gr.Textbox(
|
| 789 |
label="β‘ Status",
|
| 790 |
interactive=False,
|
|
|
|
| 792 |
)
|
| 793 |
|
| 794 |
with gr.Column(scale=1):
|
| 795 |
+
|
| 796 |
+
enhanced_audio_output = gr.Audio(
|
| 797 |
+
label="βΆ Enhanced Audio"
|
| 798 |
+
)
|
| 799 |
+
|
| 800 |
+
enhanced_file_output = gr.File(
|
| 801 |
+
label="β¬ Download Enhanced Audio"
|
| 802 |
+
)
|
| 803 |
|
| 804 |
enhance_btn.click(
|
| 805 |
fn=enhance_audio,
|
| 806 |
inputs=[processed_file_state],
|
| 807 |
+
outputs=[
|
| 808 |
+
enhanced_audio_output,
|
| 809 |
+
enhanced_file_output,
|
| 810 |
+
enhance_status
|
| 811 |
+
]
|
| 812 |
)
|
| 813 |
|
| 814 |
return demo
|
|
|
|
| 820 |
|
| 821 |
import click
|
| 822 |
|
| 823 |
+
|
| 824 |
@click.command()
|
| 825 |
+
@click.option(
|
| 826 |
+
"--debug",
|
| 827 |
+
is_flag=True,
|
| 828 |
+
default=False,
|
| 829 |
+
help="Enable debug mode."
|
| 830 |
+
)
|
| 831 |
+
@click.option(
|
| 832 |
+
"--share",
|
| 833 |
+
is_flag=True,
|
| 834 |
+
default=False,
|
| 835 |
+
help="Enable sharing of the interface."
|
| 836 |
+
)
|
| 837 |
def main(debug, share):
|
| 838 |
+
|
| 839 |
start_cleanup_worker()
|
| 840 |
+
|
| 841 |
demo = ui()
|
| 842 |
+
|
| 843 |
+
demo.queue().launch(
|
| 844 |
+
debug=debug,
|
| 845 |
+
share=share
|
| 846 |
+
)
|
| 847 |
+
|
| 848 |
|
| 849 |
if __name__ == "__main__":
|
| 850 |
main()
|