ui updated
Browse files
app.py
CHANGED
|
@@ -59,132 +59,175 @@ def process_audio(audio_path, model_name):
|
|
| 59 |
real_prob = 1 - prob
|
| 60 |
fake_prob = prob
|
| 61 |
|
| 62 |
-
# Return formatted results
|
| 63 |
return {
|
| 64 |
-
"
|
| 65 |
-
"
|
| 66 |
}
|
| 67 |
|
| 68 |
except Exception as e:
|
| 69 |
-
return {"
|
| 70 |
|
| 71 |
|
| 72 |
def predict(audio_file, model_name):
|
| 73 |
"""Gradio interface function"""
|
| 74 |
if audio_file is None:
|
| 75 |
-
return {"
|
| 76 |
return process_audio(audio_file, model_name)
|
| 77 |
|
| 78 |
|
| 79 |
-
# Custom CSS for styling
|
| 80 |
css = """
|
| 81 |
:root {
|
| 82 |
-
--primary-
|
| 83 |
-
--secondary-
|
| 84 |
-
--
|
| 85 |
-
--
|
| 86 |
-
--text-
|
| 87 |
-
--border-
|
|
|
|
|
|
|
|
|
|
| 88 |
}
|
| 89 |
|
| 90 |
-
.gradio-container {
|
| 91 |
-
background-color: var(--
|
|
|
|
| 92 |
}
|
| 93 |
|
| 94 |
-
.
|
| 95 |
-
background
|
| 96 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
color: white !important;
|
| 98 |
-
border
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
}
|
| 100 |
|
| 101 |
-
|
| 102 |
-
background:
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
transition: all 0.
|
| 106 |
}
|
| 107 |
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
|
|
|
|
|
|
| 112 |
}
|
| 113 |
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
|
|
|
|
|
|
| 119 |
}
|
| 120 |
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
}
|
| 128 |
|
| 129 |
-
.
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
|
|
|
| 133 |
}
|
| 134 |
|
| 135 |
.header-container {
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
border
|
| 141 |
-
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
|
| 142 |
}
|
| 143 |
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
}
|
| 151 |
|
| 152 |
-
.
|
| 153 |
-
|
| 154 |
-
padding:
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
color: var(--primary-color);
|
| 158 |
-
text-decoration: none;
|
| 159 |
-
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
|
| 160 |
-
transition: all 0.2s ease;
|
| 161 |
}
|
| 162 |
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 166 |
}
|
| 167 |
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 172 |
}
|
| 173 |
"""
|
| 174 |
|
| 175 |
# Create Gradio interface
|
| 176 |
-
with gr.Blocks(css=css) as demo:
|
| 177 |
-
# Title
|
| 178 |
gr.HTML(
|
| 179 |
"""
|
| 180 |
<div class="header-container">
|
| 181 |
-
<div
|
| 182 |
<img src="https://i.postimg.cc/3Jx3yZ5b/real-vs-fake-sonics-w-logo.jpg"
|
| 183 |
-
style="max-width:
|
| 184 |
</div>
|
| 185 |
-
<h1
|
| 186 |
-
<h3>ICLR 2025 [Poster]</h3>
|
| 187 |
-
<p style="
|
| 188 |
Detect if a song is real or AI-generated with our state-of-the-art models.
|
| 189 |
Simply upload an audio file to verify its authenticity!
|
| 190 |
</p>
|
|
@@ -192,10 +235,10 @@ with gr.Blocks(css=css) as demo:
|
|
| 192 |
"""
|
| 193 |
)
|
| 194 |
|
| 195 |
-
# Resource Links
|
| 196 |
gr.HTML(
|
| 197 |
"""
|
| 198 |
-
<div
|
| 199 |
<a href="https://openreview.net/forum?id=PY7KSh29Z8" target="_blank" class="resource-link">
|
| 200 |
📄 Paper
|
| 201 |
</a>
|
|
@@ -219,15 +262,16 @@ with gr.Blocks(css=css) as demo:
|
|
| 219 |
with gr.Row(equal_height=True):
|
| 220 |
with gr.Column():
|
| 221 |
audio_input = gr.Audio(
|
| 222 |
-
label="
|
| 223 |
type="filepath",
|
| 224 |
-
elem_id="audio_input"
|
|
|
|
| 225 |
)
|
| 226 |
|
| 227 |
model_dropdown = gr.Dropdown(
|
| 228 |
choices=list(MODEL_IDS.keys()),
|
| 229 |
value="SpecTTTra-γ (5s)",
|
| 230 |
-
label="
|
| 231 |
elem_id="model_dropdown"
|
| 232 |
)
|
| 233 |
|
|
@@ -239,33 +283,33 @@ with gr.Blocks(css=css) as demo:
|
|
| 239 |
with gr.Column():
|
| 240 |
# Define output before using it in Examples
|
| 241 |
output = gr.Label(
|
| 242 |
-
label="
|
| 243 |
num_top_classes=2,
|
| 244 |
-
elem_id="output"
|
| 245 |
-
elem_classes="label-container"
|
| 246 |
)
|
| 247 |
|
| 248 |
-
with gr.Accordion("
|
| 249 |
gr.Markdown("""
|
| 250 |
-
The SONICS classifier
|
| 251 |
-
|
|
|
|
| 252 |
|
| 253 |
-
|
| 254 |
-
- **SpecTTTra
|
| 255 |
-
- **SpecTTTra-β**: Balanced performance
|
| 256 |
-
- **SpecTTTra
|
| 257 |
|
| 258 |
-
|
| 259 |
- **5s**: Analyzes a 5-second clip (faster)
|
| 260 |
- **120s**: Analyzes up to 2 minutes (more accurate)
|
| 261 |
""")
|
| 262 |
|
| 263 |
# Add Examples section after output is defined
|
| 264 |
-
with gr.Accordion("
|
| 265 |
gr.Examples(
|
| 266 |
examples=[
|
| 267 |
-
["
|
| 268 |
-
["
|
| 269 |
],
|
| 270 |
inputs=[audio_input, model_dropdown],
|
| 271 |
outputs=[output],
|
|
@@ -276,9 +320,9 @@ with gr.Blocks(css=css) as demo:
|
|
| 276 |
# Footer
|
| 277 |
gr.HTML(
|
| 278 |
"""
|
| 279 |
-
<div class="footer">
|
| 280 |
-
<p>SONICS: Synthetic Or Not - Identifying Counterfeit Songs |
|
| 281 |
-
<p
|
| 282 |
</div>
|
| 283 |
"""
|
| 284 |
)
|
|
@@ -287,4 +331,5 @@ with gr.Blocks(css=css) as demo:
|
|
| 287 |
submit_btn.click(fn=predict, inputs=[audio_input, model_dropdown], outputs=[output])
|
| 288 |
|
| 289 |
if __name__ == "__main__":
|
|
|
|
| 290 |
demo.launch()
|
|
|
|
| 59 |
real_prob = 1 - prob
|
| 60 |
fake_prob = prob
|
| 61 |
|
| 62 |
+
# Return formatted results
|
| 63 |
return {
|
| 64 |
+
"Real": float(real_prob),
|
| 65 |
+
"Fake": float(fake_prob)
|
| 66 |
}
|
| 67 |
|
| 68 |
except Exception as e:
|
| 69 |
+
return {"Error": str(e)}
|
| 70 |
|
| 71 |
|
| 72 |
def predict(audio_file, model_name):
|
| 73 |
"""Gradio interface function"""
|
| 74 |
if audio_file is None:
|
| 75 |
+
return {"Message": "Please upload an audio file"}
|
| 76 |
return process_audio(audio_file, model_name)
|
| 77 |
|
| 78 |
|
| 79 |
+
# Custom CSS for styling - Dark theme with black background
|
| 80 |
css = """
|
| 81 |
:root {
|
| 82 |
+
--primary-bg: #000000;
|
| 83 |
+
--secondary-bg: #111111;
|
| 84 |
+
--panel-bg: #1e1e1e;
|
| 85 |
+
--text-color: #ffffff;
|
| 86 |
+
--text-secondary: #bbbbbb;
|
| 87 |
+
--border-color: #333333;
|
| 88 |
+
--analyze-button-color: #ffa500;
|
| 89 |
+
--analyze-button-hover: #ff8c00;
|
| 90 |
+
--accent-color: #4a78e5;
|
| 91 |
}
|
| 92 |
|
| 93 |
+
body, .gradio-container {
|
| 94 |
+
background-color: var(--primary-bg) !important;
|
| 95 |
+
color: var(--text-color) !important;
|
| 96 |
}
|
| 97 |
|
| 98 |
+
.footer, .header-container, .accordion-content {
|
| 99 |
+
background-color: var(--secondary-bg) !important;
|
| 100 |
+
color: var(--text-color) !important;
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
/* Headers and text */
|
| 104 |
+
h1, h2, h3 {
|
| 105 |
+
color: var(--text-color) !important;
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
p {
|
| 109 |
+
color: var(--text-secondary) !important;
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
/* Button styling */
|
| 113 |
+
button#submit_btn {
|
| 114 |
+
background-color: var(--analyze-button-color) !important;
|
| 115 |
color: white !important;
|
| 116 |
+
border: none !important;
|
| 117 |
+
font-weight: bold !important;
|
| 118 |
+
padding: 10px 20px !important;
|
| 119 |
+
font-size: 16px !important;
|
| 120 |
+
border-radius: 8px !important;
|
| 121 |
}
|
| 122 |
|
| 123 |
+
button#submit_btn:hover {
|
| 124 |
+
background-color: var(--analyze-button-hover) !important;
|
| 125 |
+
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.5) !important;
|
| 126 |
+
transform: translateY(-2px) !important;
|
| 127 |
+
transition: all 0.2s ease !important;
|
| 128 |
}
|
| 129 |
|
| 130 |
+
/* Panel backgrounds */
|
| 131 |
+
.gr-panel, .gr-box, .gr-form, .gr-input-label, .gr-input {
|
| 132 |
+
background-color: var(--panel-bg) !important;
|
| 133 |
+
border: 1px solid var(--border-color) !important;
|
| 134 |
+
border-radius: 8px !important;
|
| 135 |
+
color: var(--text-color) !important;
|
| 136 |
}
|
| 137 |
|
| 138 |
+
/* Results panel */
|
| 139 |
+
#output {
|
| 140 |
+
background-color: var(--panel-bg) !important;
|
| 141 |
+
border-radius: 8px !important;
|
| 142 |
+
padding: 10px !important;
|
| 143 |
+
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3) !important;
|
| 144 |
+
border: 1px solid var(--border-color) !important;
|
| 145 |
}
|
| 146 |
|
| 147 |
+
/* Resource links */
|
| 148 |
+
.resource-link {
|
| 149 |
+
background-color: var(--secondary-bg) !important;
|
| 150 |
+
color: var(--accent-color) !important;
|
| 151 |
+
border: 1px solid var(--border-color) !important;
|
| 152 |
+
padding: 8px 16px !important;
|
| 153 |
+
border-radius: 20px !important;
|
| 154 |
+
margin: 5px !important;
|
| 155 |
+
text-decoration: none !important;
|
| 156 |
+
display: inline-block !important;
|
| 157 |
+
font-weight: 500 !important;
|
| 158 |
+
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3) !important;
|
| 159 |
}
|
| 160 |
|
| 161 |
+
.resource-link:hover {
|
| 162 |
+
transform: translateY(-2px) !important;
|
| 163 |
+
box-shadow: 0 3px 6px rgba(0, 0, 0, 0.4) !important;
|
| 164 |
+
transition: all 0.2s ease !important;
|
| 165 |
+
background-color: #222222 !important;
|
| 166 |
}
|
| 167 |
|
| 168 |
.header-container {
|
| 169 |
+
padding: 20px !important;
|
| 170 |
+
border-radius: 10px !important;
|
| 171 |
+
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3) !important;
|
| 172 |
+
margin-bottom: 20px !important;
|
| 173 |
+
border: 1px solid var(--border-color) !important;
|
|
|
|
| 174 |
}
|
| 175 |
|
| 176 |
+
/* Accordion styling */
|
| 177 |
+
.gr-accordion {
|
| 178 |
+
border: 1px solid var(--border-color) !important;
|
| 179 |
+
border-radius: 8px !important;
|
| 180 |
+
overflow: hidden !important;
|
| 181 |
+
background-color: var(--panel-bg) !important;
|
| 182 |
}
|
| 183 |
|
| 184 |
+
.gr-accordion-header {
|
| 185 |
+
background-color: var(--secondary-bg) !important;
|
| 186 |
+
padding: 10px 15px !important;
|
| 187 |
+
font-weight: 600 !important;
|
| 188 |
+
color: var(--text-color) !important;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 189 |
}
|
| 190 |
|
| 191 |
+
/* Audio player */
|
| 192 |
+
.audio-player {
|
| 193 |
+
background-color: var(--panel-bg) !important;
|
| 194 |
+
border-radius: 8px !important;
|
| 195 |
+
overflow: hidden !important;
|
| 196 |
+
}
|
| 197 |
+
|
| 198 |
+
/* Dropdown & Input fields */
|
| 199 |
+
select, input, .gr-dropdown {
|
| 200 |
+
background-color: var(--panel-bg) !important;
|
| 201 |
+
color: var(--text-color) !important;
|
| 202 |
+
border: 1px solid var(--border-color) !important;
|
| 203 |
}
|
| 204 |
|
| 205 |
+
/* Labels */
|
| 206 |
+
label, .gr-label {
|
| 207 |
+
color: var(--text-secondary) !important;
|
| 208 |
+
}
|
| 209 |
+
|
| 210 |
+
/* Footer styling */
|
| 211 |
+
.footer {
|
| 212 |
+
border-top: 1px solid var(--border-color) !important;
|
| 213 |
+
margin-top: 30px !important;
|
| 214 |
+
padding: 15px !important;
|
| 215 |
}
|
| 216 |
"""
|
| 217 |
|
| 218 |
# Create Gradio interface
|
| 219 |
+
with gr.Blocks(css=css, theme=gr.themes.Default()) as demo:
|
| 220 |
+
# Title and Logo
|
| 221 |
gr.HTML(
|
| 222 |
"""
|
| 223 |
<div class="header-container">
|
| 224 |
+
<div style="display: flex; justify-content: center; margin-bottom: 20px;">
|
| 225 |
<img src="https://i.postimg.cc/3Jx3yZ5b/real-vs-fake-sonics-w-logo.jpg"
|
| 226 |
+
style="max-width: 150px; border-radius: 10px; box-shadow: 0 4px 8px rgba(0,0,0,0.3);">
|
| 227 |
</div>
|
| 228 |
+
<h1 style="text-align: center; font-size: 28px; margin-bottom: 10px; color: #ffffff;">SONICS: Synthetic Or Not - Identifying Counterfeit Songs</h1>
|
| 229 |
+
<h3 style="text-align: center; color: #bbbbbb; margin-bottom: 15px;">ICLR 2025 [Poster]</h3>
|
| 230 |
+
<p style="text-align: center; font-size: 16px; margin: 0; color: #aaaaaa;">
|
| 231 |
Detect if a song is real or AI-generated with our state-of-the-art models.
|
| 232 |
Simply upload an audio file to verify its authenticity!
|
| 233 |
</p>
|
|
|
|
| 235 |
"""
|
| 236 |
)
|
| 237 |
|
| 238 |
+
# Resource Links - Simplified
|
| 239 |
gr.HTML(
|
| 240 |
"""
|
| 241 |
+
<div style="display: flex; justify-content: center; flex-wrap: wrap; gap: 8px; margin-bottom: 25px;">
|
| 242 |
<a href="https://openreview.net/forum?id=PY7KSh29Z8" target="_blank" class="resource-link">
|
| 243 |
📄 Paper
|
| 244 |
</a>
|
|
|
|
| 262 |
with gr.Row(equal_height=True):
|
| 263 |
with gr.Column():
|
| 264 |
audio_input = gr.Audio(
|
| 265 |
+
label="Upload Audio File",
|
| 266 |
type="filepath",
|
| 267 |
+
elem_id="audio_input",
|
| 268 |
+
elem_classes="audio-player"
|
| 269 |
)
|
| 270 |
|
| 271 |
model_dropdown = gr.Dropdown(
|
| 272 |
choices=list(MODEL_IDS.keys()),
|
| 273 |
value="SpecTTTra-γ (5s)",
|
| 274 |
+
label="Select Model",
|
| 275 |
elem_id="model_dropdown"
|
| 276 |
)
|
| 277 |
|
|
|
|
| 283 |
with gr.Column():
|
| 284 |
# Define output before using it in Examples
|
| 285 |
output = gr.Label(
|
| 286 |
+
label="Analysis Result",
|
| 287 |
num_top_classes=2,
|
| 288 |
+
elem_id="output"
|
|
|
|
| 289 |
)
|
| 290 |
|
| 291 |
+
with gr.Accordion("How It Works", open=True):
|
| 292 |
gr.Markdown("""
|
| 293 |
+
## The SONICS classifier
|
| 294 |
+
|
| 295 |
+
The SONICS classifier analyzes your audio to determine if it's an authentic song (human created) or generated by AI. Our models are trained on a diverse dataset of real and AI-generated songs from Suno and Udio.
|
| 296 |
|
| 297 |
+
### Models available:
|
| 298 |
+
- **SpecTTTra-α**: Optimized for speed
|
| 299 |
+
- **SpecTTTra-β**: Balanced performance
|
| 300 |
+
- **SpecTTTra-γ**: Highest accuracy
|
| 301 |
|
| 302 |
+
### Duration variants:
|
| 303 |
- **5s**: Analyzes a 5-second clip (faster)
|
| 304 |
- **120s**: Analyzes up to 2 minutes (more accurate)
|
| 305 |
""")
|
| 306 |
|
| 307 |
# Add Examples section after output is defined
|
| 308 |
+
with gr.Accordion("Example Audio Files", open=True):
|
| 309 |
gr.Examples(
|
| 310 |
examples=[
|
| 311 |
+
["demo/real_song.mp3", "SpecTTTra-γ (5s)"],
|
| 312 |
+
["demo/fake_song.mp3", "SpecTTTra-γ (5s)"],
|
| 313 |
],
|
| 314 |
inputs=[audio_input, model_dropdown],
|
| 315 |
outputs=[output],
|
|
|
|
| 320 |
# Footer
|
| 321 |
gr.HTML(
|
| 322 |
"""
|
| 323 |
+
<div class="footer" style="text-align: center;">
|
| 324 |
+
<p style="color: #bbbbbb; font-size: 14px;">SONICS: Synthetic Or Not - Identifying Counterfeit Songs | ICLR 2025</p>
|
| 325 |
+
<p style="color: #777777; font-size: 12px;">For research purposes only</p>
|
| 326 |
</div>
|
| 327 |
"""
|
| 328 |
)
|
|
|
|
| 331 |
submit_btn.click(fn=predict, inputs=[audio_input, model_dropdown], outputs=[output])
|
| 332 |
|
| 333 |
if __name__ == "__main__":
|
| 334 |
+
# Use dark theme as base and then apply custom CSS on top
|
| 335 |
demo.launch()
|