judith.ibanez commited on
Commit
d47c6b8
·
1 Parent(s): 99fa302
Files changed (1) hide show
  1. app.py +33 -5
app.py CHANGED
@@ -419,27 +419,55 @@ async def get_info():
419
  def recognize_music_gradio(pdf_file):
420
  """Gradio wrapper for music recognition"""
421
  try:
 
422
  result = mcp_server.recognize_music_tool(f"file://{pdf_file.name}")
 
423
  if result.get("isError"):
424
- # Return error message as text instead of file path
425
  error_msg = result["content"][0]["text"]
426
  print(f"Error in music recognition: {error_msg}")
427
- return None # Return None instead of error text for file output
428
 
429
  # Extract file ID from the response
430
  response_text = result["content"][0]["text"]
 
 
431
  if "musicxml://" in response_text:
432
  file_id = response_text.split("musicxml://")[1].split("`")[0]
 
 
433
  if file_id in mcp_server.processed_files:
434
  file_info = mcp_server.processed_files[file_id]
435
- if os.path.exists(file_info["output_path"]):
436
- return file_info["output_path"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
437
 
438
- print("Processing completed but output file not found")
 
439
  return None
440
 
441
  except Exception as e:
442
  print(f"Exception in Gradio wrapper: {str(e)}")
 
 
443
  return None
444
 
445
  # Create Gradio interface
 
419
  def recognize_music_gradio(pdf_file):
420
  """Gradio wrapper for music recognition"""
421
  try:
422
+ print(f"Processing file: {pdf_file.name}")
423
  result = mcp_server.recognize_music_tool(f"file://{pdf_file.name}")
424
+
425
  if result.get("isError"):
 
426
  error_msg = result["content"][0]["text"]
427
  print(f"Error in music recognition: {error_msg}")
428
+ return None
429
 
430
  # Extract file ID from the response
431
  response_text = result["content"][0]["text"]
432
+ print(f"Response text: {response_text}")
433
+
434
  if "musicxml://" in response_text:
435
  file_id = response_text.split("musicxml://")[1].split("`")[0]
436
+ print(f"Extracted file ID: {file_id}")
437
+
438
  if file_id in mcp_server.processed_files:
439
  file_info = mcp_server.processed_files[file_id]
440
+ output_path = file_info["output_path"]
441
+ print(f"Output path from cache: {output_path}")
442
+
443
+ if os.path.exists(output_path):
444
+ print(f"✅ File exists: {output_path}")
445
+ return output_path
446
+ else:
447
+ print(f"❌ File not found: {output_path}")
448
+
449
+ # If the above doesn't work, try to find the file directly
450
+ pdf_basename = os.path.splitext(os.path.basename(pdf_file.name))[0]
451
+ possible_files = [
452
+ f"/tmp/output/{pdf_basename}.mxl",
453
+ f"/tmp/output/{pdf_basename}.xml",
454
+ f"/tmp/output/{pdf_basename}.musicxml"
455
+ ]
456
+
457
+ for file_path in possible_files:
458
+ print(f"Checking: {file_path}")
459
+ if os.path.exists(file_path):
460
+ print(f"✅ Found file: {file_path}")
461
+ return file_path
462
 
463
+ print(" No output file found in any expected location")
464
+ print(f"Files in /tmp/output: {os.listdir('/tmp/output') if os.path.exists('/tmp/output') else 'Directory not found'}")
465
  return None
466
 
467
  except Exception as e:
468
  print(f"Exception in Gradio wrapper: {str(e)}")
469
+ import traceback
470
+ traceback.print_exc()
471
  return None
472
 
473
  # Create Gradio interface