RayPac006 commited on
Commit
7c15a26
·
verified ·
1 Parent(s): dc3c3dc

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +55 -0
app.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from chord_extractor.extractors import Chordino
3
+ import pandas as pd
4
+
5
+ # Initialize the extractor
6
+ # We do this outside the function so it only loads once when the app starts
7
+ chordino = Chordino()
8
+
9
+ def process_audio(audio_path):
10
+ if audio_path is None:
11
+ return None, "Please upload an audio file."
12
+
13
+ try:
14
+ # Extract chords from the file
15
+ # chord-extractor handles the conversion internally
16
+ extracted_chords = chordino.extract(audio_path)
17
+
18
+ # Format the data for the Gradio Dataframe
19
+ data = []
20
+ for c in extracted_chords:
21
+ # Rounding timestamp for better readability
22
+ data.append([round(c.timestamp, 2), c.chord])
23
+
24
+ return data, f"Successfully extracted {len(data)} chord changes."
25
+
26
+ except Exception as e:
27
+ return None, f"Error: {str(e)}"
28
+
29
+ # Define the Gradio Interface
30
+ with gr.Blocks(title="Guitar Chord Extractor") as demo:
31
+ gr.Markdown("# 🎸 Guitar Chord Extractor")
32
+ gr.Markdown("Upload an audio file (mp3, wav, flac) to extract the chord progression using Chordino.")
33
+
34
+ with gr.Row():
35
+ with gr.Column():
36
+ audio_input = gr.Audio(label="Upload Audio", type="filepath")
37
+ submit_btn = gr.Button("Extract Chords", variant="primary")
38
+
39
+ with gr.Column():
40
+ status_output = gr.Textbox(label="Status")
41
+ chord_output = gr.Dataframe(
42
+ headers=["Timestamp (s)", "Chord"],
43
+ datatype=["number", "string"],
44
+ label="Extracted Progression"
45
+ )
46
+
47
+ submit_btn.click(
48
+ fn=process_audio,
49
+ inputs=[audio_input],
50
+ outputs=[chord_output, status_output]
51
+ )
52
+
53
+ # Launch the app
54
+ if __name__ == "__main__":
55
+ demo.launch()