Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,7 +6,7 @@ from pydub.silence import split_on_silence
|
|
| 6 |
import re
|
| 7 |
import click
|
| 8 |
|
| 9 |
-
# --- LOGIC SECTION (SAME
|
| 10 |
|
| 11 |
def clean_file_name(file_path):
|
| 12 |
file_name = os.path.basename(file_path)
|
|
@@ -39,178 +39,172 @@ def process_audio(audio_file, seconds=0.05):
|
|
| 39 |
output_audio_file = remove_silence(audio_file, minimum_silence=keep_silence)
|
| 40 |
before = calculate_duration(audio_file)
|
| 41 |
after = calculate_duration(output_audio_file)
|
| 42 |
-
text = f"⏱️ Old
|
| 43 |
return output_audio_file, output_audio_file, text
|
| 44 |
|
| 45 |
def reset_interface():
|
| 46 |
return None, 0.05, None, None, ""
|
| 47 |
|
| 48 |
-
# --- NEW
|
| 49 |
|
| 50 |
def ui():
|
| 51 |
-
#
|
| 52 |
theme = gr.themes.Soft(
|
| 53 |
primary_hue="cyan",
|
| 54 |
secondary_hue="slate",
|
| 55 |
-
font=[gr.themes.GoogleFont("
|
| 56 |
).set(
|
| 57 |
-
body_background_fill="#
|
| 58 |
-
block_background_fill="#
|
| 59 |
block_border_width="0px",
|
| 60 |
input_background_fill="#1a1a1a"
|
| 61 |
)
|
| 62 |
|
| 63 |
-
# RGB & Mobile Responsive CSS
|
| 64 |
css = """
|
| 65 |
-
/*
|
| 66 |
.gradio-container {
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
padding: 10px;
|
|
|
|
|
|
|
| 70 |
}
|
| 71 |
|
| 72 |
-
/*
|
|
|
|
|
|
|
|
|
|
| 73 |
@keyframes rgb-flow {
|
| 74 |
0% { background-position: 0% 50%; }
|
| 75 |
50% { background-position: 100% 50%; }
|
| 76 |
100% { background-position: 0% 50%; }
|
| 77 |
}
|
| 78 |
|
| 79 |
-
/*
|
| 80 |
.rgb-text {
|
| 81 |
-
background: linear-gradient(45deg, #ff0000, #
|
| 82 |
background-size: 300%;
|
| 83 |
-webkit-background-clip: text;
|
| 84 |
-webkit-text-fill-color: transparent;
|
| 85 |
-
font-weight:
|
| 86 |
-
font-size:
|
| 87 |
text-align: center;
|
| 88 |
-
animation: rgb-flow
|
| 89 |
-
text-shadow: 0 0 10px rgba(255,255,255,0.1);
|
| 90 |
margin-bottom: 5px;
|
|
|
|
| 91 |
}
|
| 92 |
|
| 93 |
-
.subtitle {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
|
| 95 |
-
/*
|
| 96 |
.rgb-card {
|
| 97 |
-
position: relative;
|
| 98 |
background: #111;
|
| 99 |
-
border-radius:
|
| 100 |
-
padding:
|
| 101 |
-
|
| 102 |
-
|
| 103 |
}
|
| 104 |
|
| 105 |
-
/* The Glowing Border */
|
| 106 |
.rgb-card::before {
|
| 107 |
content: "";
|
| 108 |
position: absolute;
|
| 109 |
-
inset:
|
| 110 |
z-index: -1;
|
| 111 |
-
background: linear-gradient(45deg, #ff0000, #00ffd5, #002bff, #ff00c8
|
| 112 |
background-size: 400%;
|
| 113 |
-
border-radius:
|
| 114 |
-
animation: rgb-flow
|
| 115 |
-
|
| 116 |
-
opacity: 0.8;
|
| 117 |
}
|
| 118 |
|
| 119 |
-
/* Inner Content of Card */
|
| 120 |
.inner-card {
|
| 121 |
-
background: #
|
| 122 |
-
border-radius:
|
| 123 |
-
padding:
|
| 124 |
-
height: 100%;
|
| 125 |
}
|
| 126 |
|
| 127 |
-
/*
|
| 128 |
.process-btn {
|
| 129 |
background: linear-gradient(90deg, #00c6ff 0%, #0072ff 100%) !important;
|
| 130 |
-
border: none !important;
|
| 131 |
color: white !important;
|
| 132 |
-
font-weight:
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
transition: 0.3s;
|
| 136 |
-
box-shadow: 0 0 15px rgba(0, 114, 255, 0.4);
|
| 137 |
}
|
| 138 |
-
.process-btn:hover { box-shadow: 0 0 25px rgba(0, 114, 255, 0.8); transform: scale(1.02); }
|
| 139 |
-
|
| 140 |
.reset-btn {
|
| 141 |
background: #ff0055 !important;
|
| 142 |
color: white !important;
|
| 143 |
border: none !important;
|
| 144 |
-
box-shadow: 0 0 10px rgba(255, 0, 85, 0.4);
|
| 145 |
}
|
| 146 |
-
|
| 147 |
-
/*
|
| 148 |
.stat-box textarea {
|
| 149 |
background-color: #000 !important;
|
| 150 |
color: #00ff88 !important;
|
| 151 |
-
|
| 152 |
-
font-
|
| 153 |
}
|
| 154 |
|
| 155 |
-
/* Mobile
|
| 156 |
@media (max-width: 768px) {
|
| 157 |
-
.
|
| 158 |
-
.inner-card { padding:
|
|
|
|
| 159 |
}
|
| 160 |
"""
|
| 161 |
|
| 162 |
-
with gr.Blocks(theme=theme, css=css, title="
|
| 163 |
|
| 164 |
-
# Header
|
| 165 |
gr.HTML("""
|
| 166 |
-
<div class="rgb-text">
|
| 167 |
-
<div class="subtitle">
|
| 168 |
""")
|
| 169 |
|
| 170 |
-
# Main RGB Wrapper
|
| 171 |
with gr.Group(elem_classes="rgb-card"):
|
| 172 |
with gr.Column(elem_classes="inner-card"):
|
| 173 |
|
| 174 |
-
#
|
| 175 |
with gr.Row():
|
| 176 |
|
| 177 |
-
# ---
|
| 178 |
with gr.Column(scale=1):
|
| 179 |
-
gr.Markdown("###
|
| 180 |
audio_input = gr.Audio(
|
| 181 |
-
label="
|
| 182 |
sources=["upload", "microphone"], show_label=False
|
| 183 |
)
|
| 184 |
|
| 185 |
-
gr.Markdown("### 🎚️
|
| 186 |
silence_threshold = gr.Slider(
|
| 187 |
minimum=0, maximum=1, step=0.01, value=0.05,
|
| 188 |
-
label="Keep Silence (
|
| 189 |
)
|
| 190 |
|
| 191 |
-
|
| 192 |
-
submit_btn = gr.Button("🚀 PROCESS", elem_classes="process-btn")
|
| 193 |
-
clear_btn = gr.Button("❌ RESET", elem_classes="reset-btn")
|
| 194 |
|
| 195 |
-
# ---
|
| 196 |
with gr.Column(scale=1):
|
| 197 |
-
gr.Markdown("###
|
| 198 |
audio_output = gr.Audio(
|
| 199 |
label="Clean Audio", show_label=False, interactive=False
|
| 200 |
)
|
| 201 |
|
| 202 |
-
gr.
|
| 203 |
-
|
|
|
|
| 204 |
|
| 205 |
duration_output = gr.Textbox(
|
| 206 |
-
label="STATS", lines=
|
| 207 |
elem_classes="stat-box", show_label=True
|
| 208 |
)
|
| 209 |
|
| 210 |
-
#
|
| 211 |
-
gr.Markdown("""<div style="text-align: center; color: #444; margin-top: 10px;">CYBERPUNK AUDIO TOOLS © 2026</div>""")
|
| 212 |
|
| 213 |
-
# Functionality
|
| 214 |
submit_btn.click(
|
| 215 |
fn=process_audio,
|
| 216 |
inputs=[audio_input, silence_threshold],
|
|
|
|
| 6 |
import re
|
| 7 |
import click
|
| 8 |
|
| 9 |
+
# --- LOGIC SECTION (SAME) ---
|
| 10 |
|
| 11 |
def clean_file_name(file_path):
|
| 12 |
file_name = os.path.basename(file_path)
|
|
|
|
| 39 |
output_audio_file = remove_silence(audio_file, minimum_silence=keep_silence)
|
| 40 |
before = calculate_duration(audio_file)
|
| 41 |
after = calculate_duration(output_audio_file)
|
| 42 |
+
text = f"⏱️ Old: {before:.2f}s | ✅ New: {after:.2f}s | 🚀 Saved: {before-after:.2f}s"
|
| 43 |
return output_audio_file, output_audio_file, text
|
| 44 |
|
| 45 |
def reset_interface():
|
| 46 |
return None, 0.05, None, None, ""
|
| 47 |
|
| 48 |
+
# --- NEW MOBILE-OPTIMIZED UI ---
|
| 49 |
|
| 50 |
def ui():
|
| 51 |
+
# Clean Modern Font Theme
|
| 52 |
theme = gr.themes.Soft(
|
| 53 |
primary_hue="cyan",
|
| 54 |
secondary_hue="slate",
|
| 55 |
+
font=[gr.themes.GoogleFont("Poppins"), "sans-serif"], # Changed to Poppins (Cleaner)
|
| 56 |
).set(
|
| 57 |
+
body_background_fill="#050505",
|
| 58 |
+
block_background_fill="#121212",
|
| 59 |
block_border_width="0px",
|
| 60 |
input_background_fill="#1a1a1a"
|
| 61 |
)
|
| 62 |
|
|
|
|
| 63 |
css = """
|
| 64 |
+
/* MOBILE FIX: Container width 100% karega */
|
| 65 |
.gradio-container {
|
| 66 |
+
width: 100% !important;
|
| 67 |
+
max-width: 100% !important;
|
| 68 |
+
padding: 10px !important;
|
| 69 |
+
margin: 0 !important;
|
| 70 |
+
overflow-x: hidden;
|
| 71 |
}
|
| 72 |
|
| 73 |
+
/* Font Change */
|
| 74 |
+
* { font-family: 'Poppins', sans-serif !important; }
|
| 75 |
+
|
| 76 |
+
/* RGB Animation */
|
| 77 |
@keyframes rgb-flow {
|
| 78 |
0% { background-position: 0% 50%; }
|
| 79 |
50% { background-position: 100% 50%; }
|
| 80 |
100% { background-position: 0% 50%; }
|
| 81 |
}
|
| 82 |
|
| 83 |
+
/* Title Styling - Mobile Friendly */
|
| 84 |
.rgb-text {
|
| 85 |
+
background: linear-gradient(45deg, #ff0000, #00ffd5, #002bff, #ff00c8);
|
| 86 |
background-size: 300%;
|
| 87 |
-webkit-background-clip: text;
|
| 88 |
-webkit-text-fill-color: transparent;
|
| 89 |
+
font-weight: 800;
|
| 90 |
+
font-size: 2rem; /* Thoda chota kiya mobile ke liye */
|
| 91 |
text-align: center;
|
| 92 |
+
animation: rgb-flow 8s linear infinite;
|
|
|
|
| 93 |
margin-bottom: 5px;
|
| 94 |
+
line-height: 1.2;
|
| 95 |
}
|
| 96 |
|
| 97 |
+
.subtitle {
|
| 98 |
+
text-align: center;
|
| 99 |
+
color: #888;
|
| 100 |
+
font-size: 0.9rem;
|
| 101 |
+
margin-bottom: 15px;
|
| 102 |
+
}
|
| 103 |
|
| 104 |
+
/* Card Styling */
|
| 105 |
.rgb-card {
|
|
|
|
| 106 |
background: #111;
|
| 107 |
+
border-radius: 15px;
|
| 108 |
+
padding: 2px; /* Border patla kiya */
|
| 109 |
+
margin-bottom: 10px;
|
| 110 |
+
position: relative;
|
| 111 |
}
|
| 112 |
|
|
|
|
| 113 |
.rgb-card::before {
|
| 114 |
content: "";
|
| 115 |
position: absolute;
|
| 116 |
+
inset: 0;
|
| 117 |
z-index: -1;
|
| 118 |
+
background: linear-gradient(45deg, #ff0000, #00ffd5, #002bff, #ff00c8);
|
| 119 |
background-size: 400%;
|
| 120 |
+
border-radius: 15px;
|
| 121 |
+
animation: rgb-flow 15s linear infinite;
|
| 122 |
+
opacity: 0.6;
|
|
|
|
| 123 |
}
|
| 124 |
|
|
|
|
| 125 |
.inner-card {
|
| 126 |
+
background: #0a0a0a;
|
| 127 |
+
border-radius: 13px;
|
| 128 |
+
padding: 15px;
|
|
|
|
| 129 |
}
|
| 130 |
|
| 131 |
+
/* Button Styling */
|
| 132 |
.process-btn {
|
| 133 |
background: linear-gradient(90deg, #00c6ff 0%, #0072ff 100%) !important;
|
|
|
|
| 134 |
color: white !important;
|
| 135 |
+
font-weight: 600 !important;
|
| 136 |
+
border: none !important;
|
| 137 |
+
box-shadow: 0 4px 15px rgba(0, 114, 255, 0.3);
|
|
|
|
|
|
|
| 138 |
}
|
|
|
|
|
|
|
| 139 |
.reset-btn {
|
| 140 |
background: #ff0055 !important;
|
| 141 |
color: white !important;
|
| 142 |
border: none !important;
|
|
|
|
| 143 |
}
|
| 144 |
+
|
| 145 |
+
/* Stats Box Text Fix */
|
| 146 |
.stat-box textarea {
|
| 147 |
background-color: #000 !important;
|
| 148 |
color: #00ff88 !important;
|
| 149 |
+
font-family: monospace;
|
| 150 |
+
font-size: 14px !important;
|
| 151 |
}
|
| 152 |
|
| 153 |
+
/* Mobile Specific Tweaks */
|
| 154 |
@media (max-width: 768px) {
|
| 155 |
+
.rgb-text { font-size: 1.5rem !important; } /* Mobile pe title chota */
|
| 156 |
+
.inner-card { padding: 10px !important; }
|
| 157 |
+
.process-btn, .reset-btn { width: 100%; margin-top: 5px; } /* Buttons full width */
|
| 158 |
}
|
| 159 |
"""
|
| 160 |
|
| 161 |
+
with gr.Blocks(theme=theme, css=css, title="Silence Remover Pro") as demo:
|
| 162 |
|
|
|
|
| 163 |
gr.HTML("""
|
| 164 |
+
<div class="rgb-text">SILENCE REMOVER</div>
|
| 165 |
+
<div class="subtitle">Clean Audio • Fast • AI Powered</div>
|
| 166 |
""")
|
| 167 |
|
|
|
|
| 168 |
with gr.Group(elem_classes="rgb-card"):
|
| 169 |
with gr.Column(elem_classes="inner-card"):
|
| 170 |
|
| 171 |
+
# Mobile par ye stack ho jayega (upar-niche)
|
| 172 |
with gr.Row():
|
| 173 |
|
| 174 |
+
# --- INPUT SECTION ---
|
| 175 |
with gr.Column(scale=1):
|
| 176 |
+
gr.Markdown("### 📤 UPLOAD")
|
| 177 |
audio_input = gr.Audio(
|
| 178 |
+
label="Source", type="filepath",
|
| 179 |
sources=["upload", "microphone"], show_label=False
|
| 180 |
)
|
| 181 |
|
| 182 |
+
gr.Markdown("### 🎚️ SETTING")
|
| 183 |
silence_threshold = gr.Slider(
|
| 184 |
minimum=0, maximum=1, step=0.01, value=0.05,
|
| 185 |
+
label="Keep Silence (Sec)"
|
| 186 |
)
|
| 187 |
|
| 188 |
+
submit_btn = gr.Button("🚀 PROCESS AUDIO", elem_classes="process-btn")
|
|
|
|
|
|
|
| 189 |
|
| 190 |
+
# --- OUTPUT SECTION ---
|
| 191 |
with gr.Column(scale=1):
|
| 192 |
+
gr.Markdown("### 🎧 RESULT")
|
| 193 |
audio_output = gr.Audio(
|
| 194 |
label="Clean Audio", show_label=False, interactive=False
|
| 195 |
)
|
| 196 |
|
| 197 |
+
with gr.Row():
|
| 198 |
+
file_output = gr.File(label="Download", file_count="single", scale=2)
|
| 199 |
+
clear_btn = gr.Button("❌ RESET", elem_classes="reset-btn", scale=1)
|
| 200 |
|
| 201 |
duration_output = gr.Textbox(
|
| 202 |
+
label="STATS", lines=2,
|
| 203 |
elem_classes="stat-box", show_label=True
|
| 204 |
)
|
| 205 |
|
| 206 |
+
gr.Markdown("""<div style="text-align: center; color: #555; font-size: 0.8rem; margin-top: 5px;">Made with ❤️</div>""")
|
|
|
|
| 207 |
|
|
|
|
| 208 |
submit_btn.click(
|
| 209 |
fn=process_audio,
|
| 210 |
inputs=[audio_input, silence_threshold],
|