slslslrhfem commited on
Commit
afd98c4
·
1 Parent(s): f3cb625

change download mechanism

Browse files
Files changed (1) hide show
  1. app.py +82 -152
app.py CHANGED
@@ -207,11 +207,20 @@ def find_song_file_by_title(song_title):
207
 
208
  return None
209
 
 
 
 
 
 
 
 
 
 
210
  @spaces.GPU(duration=300)
211
  def process_audio_for_matching(audio_file):
212
  if audio_file is None:
213
  return None, None, None, """
214
- <div style='text-align: center; color: #dc2626; padding: 30px; background: #fef2f2; border-radius: 12px; border: 2px dashed #fecaca;'>
215
  <h3>No Audio File</h3>
216
  <p>Please upload an audio file to get started!</p>
217
  </div>
@@ -221,18 +230,18 @@ def process_audio_for_matching(audio_file):
221
 
222
  if result.get('message') != 'success':
223
  return None, None, None, f"""
224
- <div style="text-align: center; padding: 25px; background: #fefce8; border-radius: 12px; border: 1px solid #fde047; margin: 10px 0;">
225
- <h3 style="color: #a16207; margin-bottom: 15px;">No Matches Found</h3>
226
- <p style="color: #a16207; font-size: 1.1em;">{result.get('message', 'Unknown error occurred')}</p>
227
  </div>
228
  """
229
 
230
  matches = result.get('matches', [])
231
  if not matches:
232
  return None, None, None, """
233
- <div style="text-align: center; padding: 25px; background: #fefce8; border-radius: 12px; border: 1px solid #fde047; margin: 10px 0;">
234
- <h3 style="color: #a16207; margin-bottom: 15px;">No Matches Found</h3>
235
- <p style="color: #a16207; font-size: 1.1em;">No matching vocals found in the dataset.</p>
236
  </div>
237
  """
238
 
@@ -250,7 +259,7 @@ def process_audio_for_matching(audio_file):
250
  else:
251
  audio_files[i] = None
252
 
253
- # Generate match results HTML
254
  matches_html = ""
255
  for match in matches:
256
  rank = match.get('rank', 0)
@@ -264,29 +273,28 @@ def process_audio_for_matching(audio_file):
264
  rank_color = rank_colors.get(rank, '#6b7280')
265
 
266
  matches_html += f"""
267
- <div style="background: #ffffff; border-radius: 12px; padding: 20px; margin: 15px 0;
268
- border-left: 5px solid {rank_color}; box-shadow: 0 3px 10px rgba(0,0,0,0.1);">
269
- <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px;">
270
- <h3 style="color: #111827; margin: 0; font-size: 1.2em;">
271
- <span style="background: {rank_color}; color: white; padding: 4px 8px; border-radius: 15px; font-size: 0.8em; margin-right: 10px;">
272
- #{rank}
273
- </span>
274
- {song_title}
275
- </h3>
276
- <span style="background: #f3f4f6; color: #111827; padding: 6px 12px; border-radius: 20px; font-weight: 600;">
277
- {confidence}
278
- </span>
279
- </div>
280
-
281
- <div style="background: #f9fafb; border-radius: 8px; padding: 12px; margin: 10px 0;">
282
- <div style="display: grid; grid-template-columns: 1fr 1fr; gap: 10px; text-align: center;">
283
- <div>
284
- <strong style="color: #1f2937;">Your Audio</strong>
285
- <br><span style="color: #dc2626; font-size: 1.1em;">{test_time:.1f}s</span>
286
  </div>
287
- <div>
288
- <strong style="color: #1f2937;">Matched At</strong>
289
- <br><span style="color: #16a34a; font-size: 1.1em;">{library_time:.1f}s</span>
290
  </div>
291
  </div>
292
  </div>
@@ -294,20 +302,13 @@ def process_audio_for_matching(audio_file):
294
  """
295
 
296
  results_html = f"""
297
- <div style="background: #ffffff; border-radius: 16px; padding: 30px;
298
- box-shadow: 0 4px 20px rgba(0,0,0,0.08); border: 1px solid #e5e7eb; margin: 10px 0;">
299
- <div style="text-align: center; margin-bottom: 25px;">
300
- <h2 style="color: #111827; margin-bottom: 10px; font-size: 1.8em;">Vocal Matching Results</h2>
301
- <p style="color: #374151; font-size: 1.1em;">Found {len(matches)} similar vocals in Covers80 dataset</p>
302
  </div>
303
-
304
  {matches_html}
305
-
306
- <div style="text-align: center; margin-top: 25px; padding: 15px; background: #f3f4f6; border-radius: 8px;">
307
- <p style="color: #374151; margin: 0; font-size: 0.95em;">
308
- <strong>Audio Players:</strong> Top 3 matched songs are available above. Timestamps show where similar vocals were found.
309
- </p>
310
- </div>
311
  </div>
312
  """
313
 
@@ -325,124 +326,53 @@ custom_css = """
325
  border-radius: 16px !important;
326
  box-shadow: 0 4px 20px rgba(0,0,0,0.08) !important;
327
  margin: 0 auto !important;
328
- padding: 40px !important;
329
- max-width: 900px;
330
  border: 1px solid #e5e7eb !important;
331
  }
332
- h1 {
333
- text-align: center !important;
334
- font-size: 2.5em !important;
335
- font-weight: 700 !important;
336
- margin-bottom: 15px !important;
337
- color: #111827 !important;
338
- }
339
- .gradio-markdown p {
340
- text-align: center !important;
341
- font-size: 1.1em !important;
342
- color: #374151 !important;
343
- margin-bottom: 25px !important;
344
- line-height: 1.6;
345
- }
346
- .upload-container {
347
- background: #ffffff !important;
348
- border-radius: 12px !important;
349
- padding: 25px !important;
350
- border: 2px dashed #d1d5db !important;
351
- margin-bottom: 25px !important;
352
- transition: all 0.3s ease !important;
353
- }
354
- .upload-container:hover {
355
- border-color: #2563eb !important;
356
- background: #f9fafb !important;
357
- }
358
- .output-container {
359
- background: #ffffff !important;
360
- border-radius: 12px !important;
361
- padding: 20px !important;
362
- border: 1px solid #e5e7eb !important;
363
- min-height: 200px !important;
364
- }
365
- .gr-button {
366
- background: #2563eb !important;
367
- color: #ffffff !important;
368
- border: none !important;
369
- border-radius: 8px !important;
370
- padding: 12px 24px !important;
371
- font-weight: 500 !important;
372
- font-size: 1em !important;
373
- transition: all 0.2s ease !important;
374
- }
375
- .gr-button:hover {
376
- background: #1d4ed8 !important;
377
- transform: translateY(-1px) !important;
378
- box-shadow: 0 4px 12px rgba(37, 99, 235, 0.25) !important;
379
- }
380
- @media (max-width: 768px) {
381
- h1 { font-size: 2em !important; }
382
- .main-container { margin: 10px !important; padding: 25px !important; }
383
- .upload-container { padding: 20px !important; }
384
- }
385
  """
386
 
387
- # Gradio interface with 3 audio outputs
388
- demo = gr.Interface(
389
- fn=process_audio_for_matching,
390
- inputs=gr.Audio(
391
- type="filepath",
392
- label="Upload Your Audio File",
393
- elem_classes=["upload-container"]
394
- ),
395
- outputs=[
396
- gr.Audio(
397
- label="Match #1 Audio",
398
- elem_classes=["output-container"]
399
- ),
400
- gr.Audio(
401
- label="Match #2 Audio",
402
- elem_classes=["output-container"]
403
- ),
404
- gr.Audio(
405
- label="Match #3 Audio",
406
- elem_classes=["output-container"]
407
- ),
408
- gr.HTML(
409
- label="Analysis Results",
410
- elem_classes=["output-container"]
411
- )
412
- ],
413
- title="Music Plagiarism Detection",
414
- description="""
415
- <div style="text-align: center; font-size: 1.1em; color: #374151; margin: 25px 0; line-height: 1.6;">
416
  <p><strong>Music Plagiarism Detection: Problem Formulation and a Segment-based Solution</strong></p>
417
- <p style="font-size: 0.9em; color: #6b7280; margin: 10px 0;">
418
- Authors: Seonghyeon Go, Yumin Kim<br>
419
- MIPPIA Inc.<br>
420
- Submitted to ICASSP 2026
421
  </p>
422
- <hr style="border: none; border-top: 1px solid #e5e7eb; margin: 20px 0;">
423
- <p><strong>Demo Version Notice:</strong><br>
424
- This demo differs from the paper version and focuses exclusively on vocal segment transcription.</p>
425
- <p>Upload any music file to detect vocal similarities in the Covers80 dataset.<br>
426
- The system analyzes only vocal characteristics, ignoring instrumental parts.</p>
427
- <p style="font-size: 0.95em; color: #dc2626; font-weight: 600; margin-top: 15px;">
428
- Processing can take up to 2 minutes per file
429
- </p>
430
- <p style="font-size: 0.95em; color: #6b7280; margin-top: 10px;">
431
- Supported formats: MP3, WAV, M4A, FLAC
432
  </p>
 
433
  </div>
434
- """,
435
- examples=[],
436
- css=custom_css,
437
- theme=gr.themes.Soft(
438
- primary_hue="blue",
439
- secondary_hue="gray",
440
- neutral_hue="gray",
441
- font=[gr.themes.GoogleFont("Inter"), "Arial", "sans-serif"]
442
- ),
443
- elem_classes=["main-container"],
444
- allow_flagging="never"
445
- )
 
 
 
 
 
 
 
 
 
 
 
 
446
 
447
  if __name__ == "__main__":
448
  demo.launch(
 
207
 
208
  return None
209
 
210
+ def format_time(seconds):
211
+ """Convert seconds to MM:SS format"""
212
+ if seconds is None or seconds < 0:
213
+ return "0:00"
214
+
215
+ minutes = int(seconds // 60)
216
+ seconds = int(seconds % 60)
217
+ return f"{minutes}:{seconds:02d}"
218
+
219
  @spaces.GPU(duration=300)
220
  def process_audio_for_matching(audio_file):
221
  if audio_file is None:
222
  return None, None, None, """
223
+ <div style='text-align: center; color: #dc2626; padding: 20px; background: #fef2f2; border-radius: 8px;'>
224
  <h3>No Audio File</h3>
225
  <p>Please upload an audio file to get started!</p>
226
  </div>
 
230
 
231
  if result.get('message') != 'success':
232
  return None, None, None, f"""
233
+ <div style="text-align: center; padding: 20px; background: #fefce8; border-radius: 8px;">
234
+ <h3 style="color: #a16207;">No Matches Found</h3>
235
+ <p style="color: #a16207;">{result.get('message', 'Unknown error occurred')}</p>
236
  </div>
237
  """
238
 
239
  matches = result.get('matches', [])
240
  if not matches:
241
  return None, None, None, """
242
+ <div style="text-align: center; padding: 20px; background: #fefce8; border-radius: 8px;">
243
+ <h3 style="color: #a16207;">No Matches Found</h3>
244
+ <p style="color: #a16207;">No matching vocals found in the dataset.</p>
245
  </div>
246
  """
247
 
 
259
  else:
260
  audio_files[i] = None
261
 
262
+ # Generate match results HTML - compact horizontal layout
263
  matches_html = ""
264
  for match in matches:
265
  rank = match.get('rank', 0)
 
273
  rank_color = rank_colors.get(rank, '#6b7280')
274
 
275
  matches_html += f"""
276
+ <div style="background: #ffffff; border-radius: 8px; padding: 15px; margin: 10px 0;
277
+ border-left: 4px solid {rank_color}; box-shadow: 0 2px 8px rgba(0,0,0,0.1);">
278
+ <div style="display: flex; justify-content: space-between; align-items: center;">
279
+ <div style="flex: 1;">
280
+ <h4 style="color: #111827; margin: 0; font-size: 1.1em;">
281
+ <span style="background: {rank_color}; color: white; padding: 2px 6px; border-radius: 10px; font-size: 0.8em; margin-right: 8px;">
282
+ #{rank}
283
+ </span>
284
+ {song_title}
285
+ </h4>
286
+ </div>
287
+ <div style="display: flex; gap: 15px; align-items: center;">
288
+ <div style="text-align: center;">
289
+ <small style="color: #6b7280;">Your Audio</small>
290
+ <div style="color: #dc2626; font-weight: 600;">{format_time(test_time)}</div>
291
+ </div>
292
+ <div style="text-align: center;">
293
+ <small style="color: #6b7280;">Matched At</small>
294
+ <div style="color: #16a34a; font-weight: 600;">{format_time(library_time)}</div>
295
  </div>
296
+ <div style="background: #f3f4f6; color: #111827; padding: 4px 10px; border-radius: 12px; font-weight: 600; font-size: 0.9em;">
297
+ {confidence}
 
298
  </div>
299
  </div>
300
  </div>
 
302
  """
303
 
304
  results_html = f"""
305
+ <div style="background: #ffffff; border-radius: 12px; padding: 20px;
306
+ box-shadow: 0 4px 15px rgba(0,0,0,0.08); border: 1px solid #e5e7eb;">
307
+ <div style="text-align: center; margin-bottom: 20px;">
308
+ <h3 style="color: #111827; margin: 0;">Vocal Matching Results</h3>
309
+ <p style="color: #6b7280; margin: 5px 0;">Found {len(matches)} similar vocals in Covers80 dataset</p>
310
  </div>
 
311
  {matches_html}
 
 
 
 
 
 
312
  </div>
313
  """
314
 
 
326
  border-radius: 16px !important;
327
  box-shadow: 0 4px 20px rgba(0,0,0,0.08) !important;
328
  margin: 0 auto !important;
329
+ padding: 30px !important;
330
+ max-width: 1200px;
331
  border: 1px solid #e5e7eb !important;
332
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
333
  """
334
 
335
+ # Gradio interface with horizontal layout
336
+ with gr.Blocks(css=custom_css, theme=gr.themes.Soft(), title="Music Plagiarism Detection") as demo:
337
+ gr.Markdown("""
338
+ <div style="text-align: center; margin-bottom: 20px;">
339
+ <h1 style="color: #111827; font-size: 2.2em; margin-bottom: 10px;">Music Plagiarism Detection</h1>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
340
  <p><strong>Music Plagiarism Detection: Problem Formulation and a Segment-based Solution</strong></p>
341
+ <p style="font-size: 0.9em; color: #6b7280; margin: 8px 0;">
342
+ Authors: Seonghyeon Go, Yumin Kim | MIPPIA Inc. | Submitted to ICASSP 2026
 
 
343
  </p>
344
+ <hr style="border: none; border-top: 1px solid #e5e7eb; margin: 15px 0;">
345
+ <p><strong>Demo Version Notice:</strong> This demo differs from the paper version and focuses exclusively on vocal segment transcription.</p>
346
+ <p style="font-size: 0.9em; color: #6b7280; margin: 8px 0;">
347
+ Structure analysis has been excluded for optimization. Results are derived from all downbeats,
348
+ which may cause some timestamps to appear less precise than expected.
 
 
 
 
 
349
  </p>
350
+ <p style="color: #dc2626; font-weight: 600;">Processing can take up to 2 minutes per file</p>
351
  </div>
352
+ """, elem_classes=["main-container"])
353
+
354
+ # Input section
355
+ with gr.Row():
356
+ audio_input = gr.Audio(type="filepath", label="Upload Your Audio File")
357
+
358
+ with gr.Row():
359
+ submit_btn = gr.Button("Analyze Audio", variant="primary", size="lg")
360
+
361
+ # Output section - horizontal layout
362
+ with gr.Row():
363
+ with gr.Column(scale=1):
364
+ audio1 = gr.Audio(label="Match #1", show_label=True)
365
+ audio2 = gr.Audio(label="Match #2", show_label=True)
366
+ audio3 = gr.Audio(label="Match #3", show_label=True)
367
+
368
+ with gr.Column(scale=1):
369
+ results = gr.HTML(label="Analysis Results")
370
+
371
+ submit_btn.click(
372
+ fn=process_audio_for_matching,
373
+ inputs=[audio_input],
374
+ outputs=[audio1, audio2, audio3, results]
375
+ )
376
 
377
  if __name__ == "__main__":
378
  demo.launch(