Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -42,17 +42,29 @@ def identify_audio(file):
|
|
42 |
buf = f.read()
|
43 |
buffer_result = acr.recognize_by_filebuffer(buf, 0)
|
44 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
return {
|
46 |
-
"Partial Results":
|
47 |
-
"Full Result":
|
48 |
-
"Buffer Result":
|
49 |
}
|
50 |
|
51 |
# Create Gradio interface
|
52 |
iface = gr.Interface(
|
53 |
fn=identify_audio,
|
54 |
inputs=gr.File(label="Upload Audio File"),
|
55 |
-
outputs=gr.
|
56 |
title="Audio Search by File",
|
57 |
description="Upload an audio file to identify it using ACRCloud."
|
58 |
)
|
|
|
42 |
buf = f.read()
|
43 |
buffer_result = acr.recognize_by_filebuffer(buf, 0)
|
44 |
|
45 |
+
# Parse and structure the results in a more readable format
|
46 |
+
partial_results = "\n".join(results)
|
47 |
+
full_result_parsed = f"Title: {full_result['metadata']['music'][0]['title']}\n" \
|
48 |
+
f"Artist: {full_result['metadata']['music'][0]['artists'][0]['name']}\n" \
|
49 |
+
f"Album: {full_result['metadata']['music'][0]['album']['name']}\n" \
|
50 |
+
f"Release Date: {full_result['metadata']['music'][0]['release_date']}\n" \
|
51 |
+
f"Duration: {full_result['metadata']['music'][0]['duration_ms'] // 1000}s"
|
52 |
+
|
53 |
+
buffer_result_parsed = f"Track ID: {buffer_result['metadata']['music'][0]['external_metadata']['spotify']['track']['id']}\n" \
|
54 |
+
f"Track Name: {buffer_result['metadata']['music'][0]['external_metadata']['spotify']['track']['name']}\n" \
|
55 |
+
f"Artist: {buffer_result['metadata']['music'][0]['external_metadata']['spotify']['track']['artists'][0]['name']}\n"
|
56 |
+
|
57 |
return {
|
58 |
+
"Partial Results": partial_results,
|
59 |
+
"Full Result": full_result_parsed,
|
60 |
+
"Buffer Result": buffer_result_parsed
|
61 |
}
|
62 |
|
63 |
# Create Gradio interface
|
64 |
iface = gr.Interface(
|
65 |
fn=identify_audio,
|
66 |
inputs=gr.File(label="Upload Audio File"),
|
67 |
+
outputs=[gr.Textbox(label="Partial Results"), gr.Textbox(label="Full Result"), gr.Textbox(label="Buffer Result")],
|
68 |
title="Audio Search by File",
|
69 |
description="Upload an audio file to identify it using ACRCloud."
|
70 |
)
|