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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import numpy as np
|
| 3 |
+
import time
|
| 4 |
+
from typing import Generator, Tuple
|
| 5 |
+
|
| 6 |
+
def process_audio(audio: Tuple[int, np.ndarray]) -> Generator[np.ndarray, None, None]:
|
| 7 |
+
"""Process audio in real-time with shadow effects"""
|
| 8 |
+
if audio is None:
|
| 9 |
+
return
|
| 10 |
+
|
| 11 |
+
sample_rate, audio_data = audio
|
| 12 |
+
|
| 13 |
+
# Simulate real-time processing with shadow effect
|
| 14 |
+
for i in range(0, len(audio_data), 1024):
|
| 15 |
+
chunk = audio_data[i:i+1024]
|
| 16 |
+
|
| 17 |
+
# Apply shadow effect (attenuate and delay simulation)
|
| 18 |
+
shadow_effect = chunk * 0.7
|
| 19 |
+
if i > 512:
|
| 20 |
+
shadow_effect += audio_data[i-512:i-512+len(chunk)] * 0.3
|
| 21 |
+
|
| 22 |
+
yield shadow_effect
|
| 23 |
+
|
| 24 |
+
def get_audio_info(audio: Tuple[int, np.ndarray]) -> str:
|
| 25 |
+
"""Get audio information"""
|
| 26 |
+
if audio is None:
|
| 27 |
+
return "No audio detected"
|
| 28 |
+
|
| 29 |
+
sample_rate, audio_data = audio
|
| 30 |
+
duration = len(audio_data) / sample_rate
|
| 31 |
+
return f"Sample Rate: {sample_rate} Hz\nDuration: {duration:.2f} seconds\nChannels: Mono"
|
| 32 |
+
|
| 33 |
+
# Custom dark theme with shadow effects
|
| 34 |
+
custom_dark_theme = gr.themes.Soft(
|
| 35 |
+
primary_hue="purple",
|
| 36 |
+
secondary_hue="indigo",
|
| 37 |
+
neutral_hue="gray",
|
| 38 |
+
font=gr.themes.GoogleFont("Inter"),
|
| 39 |
+
text_size="lg",
|
| 40 |
+
spacing_size="lg",
|
| 41 |
+
radius_size="md"
|
| 42 |
+
).set(
|
| 43 |
+
body_background_fill="*neutral_950",
|
| 44 |
+
block_background_fill="*neutral_900",
|
| 45 |
+
block_border_width="1px",
|
| 46 |
+
block_border_color="*neutral_800",
|
| 47 |
+
block_shadow="0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -1px rgba(0, 0, 0, 0.2)",
|
| 48 |
+
block_title_text_weight="600",
|
| 49 |
+
block_title_text_color="*neutral_50",
|
| 50 |
+
block_label_text_color="*neutral_300",
|
| 51 |
+
input_background_fill="*neutral_800",
|
| 52 |
+
input_border_color="*neutral_700",
|
| 53 |
+
input_text_color="*neutral_100",
|
| 54 |
+
button_primary_background_fill="*primary_600",
|
| 55 |
+
button_primary_background_fill_hover="*primary_700",
|
| 56 |
+
button_primary_text_color="white",
|
| 57 |
+
button_secondary_background_fill="*neutral_800",
|
| 58 |
+
button_secondary_background_fill_hover="*neutral_700",
|
| 59 |
+
button_secondary_text_color="*neutral_100",
|
| 60 |
+
prose_text_color="*neutral_200",
|
| 61 |
+
prose_header_text_color="*neutral_50"
|
| 62 |
+
)
|
| 63 |
+
|
| 64 |
+
# Custom CSS for additional shadow effects
|
| 65 |
+
custom_css = """
|
| 66 |
+
/* Enhanced shadow effects */
|
| 67 |
+
.gradio-container {
|
| 68 |
+
background: linear-gradient(135deg, #0f0f0f 0%, #1a1a1a 100%);
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
/* Card shadow effects */
|
| 72 |
+
.shadow-card {
|
| 73 |
+
box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5), 0 6px 10px rgba(0, 0, 0, 0.3);
|
| 74 |
+
border: 1px solid #333;
|
| 75 |
+
background: rgba(30, 30, 30, 0.8);
|
| 76 |
+
backdrop-filter: blur(10px);
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
/* Button shadow effects */
|
| 80 |
+
.btn-shadow {
|
| 81 |
+
box-shadow: 0 4px 15px rgba(139, 92, 246, 0.3), 0 2px 4px rgba(0, 0, 0, 0.2);
|
| 82 |
+
transition: all 0.3s ease;
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
.btn-shadow:hover {
|
| 86 |
+
box-shadow: 0 6px 20px rgba(139, 92, 246, 0.4), 0 3px 6px rgba(0, 0, 0, 0.3);
|
| 87 |
+
transform: translateY(-2px);
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
/* Audio component shadow */
|
| 91 |
+
audio {
|
| 92 |
+
box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);
|
| 93 |
+
border-radius: 8px;
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
/* Text shadow for headings */
|
| 97 |
+
h1, h2, h3 {
|
| 98 |
+
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
/* Glow effect for active elements */
|
| 102 |
+
.glow {
|
| 103 |
+
box-shadow: 0 0 20px rgba(139, 92, 246, 0.5), 0 0 40px rgba(139, 92, 246, 0.3);
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
/* Animation for recording */
|
| 107 |
+
@keyframes pulse {
|
| 108 |
+
0% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7); }
|
| 109 |
+
70% { box-shadow: 0 0 0 10px rgba(239, 68, 68, 0); }
|
| 110 |
+
100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
.recording {
|
| 114 |
+
animation: pulse 2s infinite;
|
| 115 |
+
}
|
| 116 |
+
"""
|
| 117 |
+
|
| 118 |
+
with gr.Blocks() as demo:
|
| 119 |
+
# Header with shadow effect
|
| 120 |
+
gr.HTML("""
|
| 121 |
+
<div style="text-align: center; margin-bottom: 30px; padding: 20px; background: rgba(30, 30, 30, 0.6); border-radius: 12px; box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);">
|
| 122 |
+
<h1 style="color: #e5e7eb; font-size: 2.5em; margin-bottom: 10px; text-shadow: 2px 2px 8px rgba(0, 0, 0, 0.7);">
|
| 123 |
+
ποΈ Real-Time Voice Shadow Processor
|
| 124 |
+
</h1>
|
| 125 |
+
<p style="color: #9ca3af; font-size: 1.1em; text-shadow: 1px 1px 4px rgba(0, 0, 0, 0.5);">
|
| 126 |
+
Experience audio with dynamic shadow effects in real-time
|
| 127 |
+
</p>
|
| 128 |
+
<a href="https://huggingface.co/spaces/akhaliq/anycoder" style="color: #8b5cf6; text-decoration: none; font-weight: 600;">
|
| 129 |
+
Built with anycoder
|
| 130 |
+
</a>
|
| 131 |
+
</div>
|
| 132 |
+
""")
|
| 133 |
+
|
| 134 |
+
with gr.Row(equal_height=True):
|
| 135 |
+
with gr.Column(scale=1, elem_classes=["shadow-card"]):
|
| 136 |
+
gr.Markdown("""
|
| 137 |
+
### ποΈ Input Controls
|
| 138 |
+
Speak into your microphone to apply real-time shadow effects
|
| 139 |
+
""", elem_id="input-header")
|
| 140 |
+
|
| 141 |
+
# Input audio with shadow effect
|
| 142 |
+
input_audio = gr.Audio(
|
| 143 |
+
sources=["microphone"],
|
| 144 |
+
type="numpy",
|
| 145 |
+
label="π€ Input Audio",
|
| 146 |
+
streaming=True,
|
| 147 |
+
elem_classes=["shadow-card"]
|
| 148 |
+
)
|
| 149 |
+
|
| 150 |
+
with gr.Row():
|
| 151 |
+
start_btn = gr.Button(
|
| 152 |
+
"βΆοΈ Start Processing",
|
| 153 |
+
variant="primary",
|
| 154 |
+
elem_classes=["btn-shadow"],
|
| 155 |
+
size="lg"
|
| 156 |
+
)
|
| 157 |
+
stop_btn = gr.Button(
|
| 158 |
+
"βΉοΈ Stop",
|
| 159 |
+
variant="secondary",
|
| 160 |
+
elem_classes=["btn-shadow"],
|
| 161 |
+
size="lg"
|
| 162 |
+
)
|
| 163 |
+
|
| 164 |
+
with gr.Column(scale=1, elem_classes=["shadow-card"]):
|
| 165 |
+
gr.Markdown("""
|
| 166 |
+
### π Audio Information
|
| 167 |
+
Real-time audio analysis and processing status
|
| 168 |
+
""", elem_id="info-header")
|
| 169 |
+
|
| 170 |
+
# Audio info display
|
| 171 |
+
audio_info = gr.Textbox(
|
| 172 |
+
label="π Audio Details",
|
| 173 |
+
value="Waiting for audio input...",
|
| 174 |
+
interactive=False,
|
| 175 |
+
elem_classes=["shadow-card"]
|
| 176 |
+
)
|
| 177 |
+
|
| 178 |
+
# Status indicator
|
| 179 |
+
status_display = gr.HTML("""
|
| 180 |
+
<div style="padding: 15px; background: rgba(55, 65, 81, 0.5); border-radius: 8px; margin: 10px 0;">
|
| 181 |
+
<p style="color: #9ca3af; margin: 0;">π΄ Status: Ready</p>
|
| 182 |
+
</div>
|
| 183 |
+
""")
|
| 184 |
+
|
| 185 |
+
# Volume visualization
|
| 186 |
+
volume_meter = gr.Slider(
|
| 187 |
+
minimum=0,
|
| 188 |
+
maximum=100,
|
| 189 |
+
value=0,
|
| 190 |
+
label="π Volume Level",
|
| 191 |
+
interactive=False,
|
| 192 |
+
elem_classes=["shadow-card"]
|
| 193 |
+
)
|
| 194 |
+
|
| 195 |
+
with gr.Row():
|
| 196 |
+
with gr.Column(elem_classes=["shadow-card"]):
|
| 197 |
+
gr.Markdown("""
|
| 198 |
+
### π― Processed Output
|
| 199 |
+
Audio with shadow effects applied in real-time
|
| 200 |
+
""", elem_id="output-header")
|
| 201 |
+
|
| 202 |
+
# Output audio with shadow effect
|
| 203 |
+
output_audio = gr.Audio(
|
| 204 |
+
label="π Processed Audio",
|
| 205 |
+
streaming=True,
|
| 206 |
+
autoplay=True,
|
| 207 |
+
elem_classes=["shadow-card"]
|
| 208 |
+
)
|
| 209 |
+
|
| 210 |
+
# Effect controls
|
| 211 |
+
with gr.Accordion("βοΈ Shadow Effect Settings", open=True):
|
| 212 |
+
shadow_intensity = gr.Slider(
|
| 213 |
+
minimum=0,
|
| 214 |
+
maximum=100,
|
| 215 |
+
value=30,
|
| 216 |
+
label="Shadow Intensity (%)",
|
| 217 |
+
elem_classes=["shadow-card"]
|
| 218 |
+
)
|
| 219 |
+
|
| 220 |
+
delay_amount = gr.Slider(
|
| 221 |
+
minimum=0,
|
| 222 |
+
maximum=100,
|
| 223 |
+
value=50,
|
| 224 |
+
label="Delay Amount (%)",
|
| 225 |
+
elem_classes=["shadow-card"]
|
| 226 |
+
)
|
| 227 |
+
|
| 228 |
+
# Real-time processing function
|
| 229 |
+
def process_realtime(audio, intensity, delay):
|
| 230 |
+
if audio is None:
|
| 231 |
+
return None, "No audio input", 0, '<div style="padding: 15px; background: rgba(55, 65, 81, 0.5); border-radius: 8px; margin: 10px 0;"><p style="color: #9ca3af; margin: 0;">π΄ Status: Ready</p></div>'
|
| 232 |
+
|
| 233 |
+
sample_rate, audio_data = audio
|
| 234 |
+
|
| 235 |
+
# Calculate volume
|
| 236 |
+
volume = np.sqrt(np.mean(audio_data**2)) * 100
|
| 237 |
+
volume = min(volume, 100)
|
| 238 |
+
|
| 239 |
+
# Apply shadow effect
|
| 240 |
+
shadow_factor = intensity / 100
|
| 241 |
+
delay_samples = int((delay / 100) * sample_rate * 0.1) # Max 100ms delay
|
| 242 |
+
|
| 243 |
+
processed_audio = audio_data * (1 - shadow_factor)
|
| 244 |
+
if delay_samples > 0 and len(audio_data) > delay_samples:
|
| 245 |
+
processed_audio[delay_samples:] += audio_data[:-delay_samples] * shadow_factor
|
| 246 |
+
|
| 247 |
+
info = get_audio_info(audio)
|
| 248 |
+
status_color = "#10b981" if volume > 10 else "#f59e0b"
|
| 249 |
+
status_html = f'<div style="padding: 15px; background: rgba(55, 65, 81, 0.5); border-radius: 8px; margin: 10px 0;"><p style="color: #9ca3af; margin: 0;">π’ Status: Processing | Volume: {volume:.1f}%</p></div>'
|
| 250 |
+
|
| 251 |
+
return (sample_rate, processed_audio), info, volume, status_html
|
| 252 |
+
|
| 253 |
+
# Event handlers
|
| 254 |
+
input_audio.stream(
|
| 255 |
+
process_realtime,
|
| 256 |
+
inputs=[input_audio, shadow_intensity, delay_amount],
|
| 257 |
+
outputs=[output_audio, audio_info, volume_meter, status_display],
|
| 258 |
+
time_limit=30,
|
| 259 |
+
stream_every=0.1,
|
| 260 |
+
api_visibility="public"
|
| 261 |
+
)
|
| 262 |
+
|
| 263 |
+
start_btn.click(
|
| 264 |
+
lambda: gr.Audio(streaming=True),
|
| 265 |
+
outputs=[input_audio],
|
| 266 |
+
api_visibility="public"
|
| 267 |
+
)
|
| 268 |
+
|
| 269 |
+
stop_btn.click(
|
| 270 |
+
lambda: None,
|
| 271 |
+
outputs=[input_audio],
|
| 272 |
+
api_visibility="public"
|
| 273 |
+
)
|
| 274 |
+
|
| 275 |
+
# Footer with shadow effect
|
| 276 |
+
gr.HTML("""
|
| 277 |
+
<div style="text-align: center; margin-top: 30px; padding: 20px; background: rgba(30, 30, 30, 0.6); border-radius: 12px; box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.3);">
|
| 278 |
+
<p style="color: #6b7280; font-size: 0.9em;">
|
| 279 |
+
ποΈ Real-time voice processing with shadow effects | Dark mode interface
|
| 280 |
+
</p>
|
| 281 |
+
</div>
|
| 282 |
+
""")
|
| 283 |
+
|
| 284 |
+
# Launch with custom dark theme and settings
|
| 285 |
+
demo.launch(
|
| 286 |
+
theme=custom_dark_theme,
|
| 287 |
+
css=custom_css,
|
| 288 |
+
footer_links=[{"label": "Built with anycoder", "url": "https://huggingface.co/spaces/akhaliq/anycoder"}]
|
| 289 |
+
)
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio>=6.0
|
| 2 |
+
numpy
|
| 3 |
+
requests
|
| 4 |
+
Pillow
|