Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -79,11 +79,10 @@ import json
|
|
79 |
# Function to recognize audio from URL or uploaded file
|
80 |
def recognize_audio(choice, url, file):
|
81 |
api_url = os.getenv("API_URL", "https://api.audd.io/")
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
)['api_token'] = os.getenv("API_TOKEN", "your_api_token_here")
|
87 |
|
88 |
if choice == "URL":
|
89 |
if not url:
|
@@ -92,8 +91,8 @@ def recognize_audio(choice, url, file):
|
|
92 |
response = requests.post(api_url, data=params)
|
93 |
|
94 |
elif choice == "Upload File":
|
95 |
-
if file:
|
96 |
-
return "Please upload a valid
|
97 |
with open(file, "rb") as f:
|
98 |
response = requests.post(api_url, data=params, files={'file': f})
|
99 |
|
@@ -112,7 +111,7 @@ interface = gr.Interface(
|
|
112 |
],
|
113 |
outputs=gr.Textbox(label="Recognition Result"),
|
114 |
title="Audio Recognition",
|
115 |
-
description="Choose a method: Upload an audio file or enter a URL to identify the song.
|
116 |
)
|
117 |
|
118 |
# Run Gradio App
|
|
|
79 |
# Function to recognize audio from URL or uploaded file
|
80 |
def recognize_audio(choice, url, file):
|
81 |
api_url = os.getenv("API_URL", "https://api.audd.io/")
|
82 |
+
|
83 |
+
# Memuat PARAMS sebagai dictionary (bukan string JSON)
|
84 |
+
params = json.loads(os.getenv("PARAMS", "{}"))
|
85 |
+
params['api_token'] = os.getenv("API_TOKEN", "your_api_token_here")
|
|
|
86 |
|
87 |
if choice == "URL":
|
88 |
if not url:
|
|
|
91 |
response = requests.post(api_url, data=params)
|
92 |
|
93 |
elif choice == "Upload File":
|
94 |
+
if not file:
|
95 |
+
return "Please upload a valid audio file."
|
96 |
with open(file, "rb") as f:
|
97 |
response = requests.post(api_url, data=params, files={'file': f})
|
98 |
|
|
|
111 |
],
|
112 |
outputs=gr.Textbox(label="Recognition Result"),
|
113 |
title="Audio Recognition",
|
114 |
+
description="Choose a method: Upload an audio file or enter a URL to identify the song."
|
115 |
)
|
116 |
|
117 |
# Run Gradio App
|