Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -74,35 +74,41 @@
|
|
74 |
import requests
|
75 |
import gradio as gr
|
76 |
import os
|
77 |
-
|
78 |
-
|
79 |
-
def recognize_audio(url, file):
|
80 |
-
api_url = os.
|
81 |
-
api_token = os.
|
82 |
-
|
83 |
-
|
84 |
-
if
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
|
|
93 |
else:
|
94 |
-
return "Please
|
|
|
|
|
95 |
|
|
|
96 |
interface = gr.Interface(
|
97 |
fn=recognize_audio,
|
98 |
inputs=[
|
|
|
99 |
gr.Textbox(label="Enter Audio URL", placeholder="https://example.com/audio.mp3"),
|
100 |
-
gr.File(label="Upload Audio File")
|
101 |
],
|
102 |
outputs=gr.Textbox(label="Recognition Result"),
|
103 |
title="Audio Recognition",
|
104 |
-
description="Upload an audio
|
105 |
)
|
106 |
|
|
|
107 |
if __name__ == "__main__":
|
108 |
interface.launch()
|
|
|
74 |
import requests
|
75 |
import gradio as gr
|
76 |
import os
|
77 |
+
|
78 |
+
# Function to recognize audio from URL or uploaded file
|
79 |
+
def recognize_audio(choice, url, file):
|
80 |
+
api_url = os.getenv("API_URL")
|
81 |
+
api_token = os.getenv("API_TOKEN")
|
82 |
+
params = os.getenv("PARAMS")
|
83 |
+
|
84 |
+
if choice == "URL":
|
85 |
+
if not url:
|
86 |
+
return "Please enter a valid URL."
|
87 |
+
params['url'] = url
|
88 |
+
response = requests.post(api_url, data=params)
|
89 |
+
elif choice == "Upload File":
|
90 |
+
if not file:
|
91 |
+
return "Please upload an audio file."
|
92 |
+
with open(file.name, "rb") as f:
|
93 |
+
response = requests.post(api_url, data=params, files={'file': f})
|
94 |
else:
|
95 |
+
return "Please select a method (URL or Upload File)."
|
96 |
+
|
97 |
+
return response.text
|
98 |
|
99 |
+
# Gradio Interface
|
100 |
interface = gr.Interface(
|
101 |
fn=recognize_audio,
|
102 |
inputs=[
|
103 |
+
gr.Radio(["URL", "Upload File"], label="Select Input Method"),
|
104 |
gr.Textbox(label="Enter Audio URL", placeholder="https://example.com/audio.mp3"),
|
105 |
+
gr.File(label="Upload Audio File", type="file")
|
106 |
],
|
107 |
outputs=gr.Textbox(label="Recognition Result"),
|
108 |
title="Audio Recognition",
|
109 |
+
description="Choose a method: Upload an audio file or enter a URL to identify the song."
|
110 |
)
|
111 |
|
112 |
+
# Run Gradio App
|
113 |
if __name__ == "__main__":
|
114 |
interface.launch()
|