Update app.py
Browse files
app.py
CHANGED
|
@@ -1,21 +1,18 @@
|
|
|
|
|
| 1 |
from gradio_client import Client
|
| 2 |
import os
|
| 3 |
-
import gradio as gr
|
| 4 |
|
| 5 |
-
|
|
|
|
|
|
|
| 6 |
BACKEND_SPACE = "CleanSong-AI/Main-tool-backend-main"
|
| 7 |
|
| 8 |
def clean_song(file_path):
|
| 9 |
if file_path is None:
|
| 10 |
return None
|
| 11 |
|
| 12 |
-
client = Client(
|
| 13 |
-
BACKEND_SPACE,
|
| 14 |
-
hf_token=HF_TOKEN
|
| 15 |
-
)
|
| 16 |
-
|
| 17 |
try:
|
| 18 |
-
|
| 19 |
result = client.predict(
|
| 20 |
file_path,
|
| 21 |
api_name="/predict"
|
|
@@ -23,17 +20,7 @@ def clean_song(file_path):
|
|
| 23 |
except Exception as e:
|
| 24 |
return f"Error calling backend: {e}"
|
| 25 |
|
| 26 |
-
|
| 27 |
-
if isinstance(result, str) and os.path.exists(result):
|
| 28 |
-
return result
|
| 29 |
-
|
| 30 |
-
# fallback: save bytes
|
| 31 |
-
output_path = "cleaned_output.wav"
|
| 32 |
-
with open(output_path, "wb") as f:
|
| 33 |
-
f.write(result)
|
| 34 |
-
|
| 35 |
-
return output_path
|
| 36 |
-
|
| 37 |
|
| 38 |
# ------------------------------------------------------------
|
| 39 |
# UI
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
from gradio_client import Client
|
| 3 |
import os
|
|
|
|
| 4 |
|
| 5 |
+
# IMPORTANT: token must be set as env var
|
| 6 |
+
# os.environ["HF_TOKEN"] = "hf_xxx" # only if not already set
|
| 7 |
+
|
| 8 |
BACKEND_SPACE = "CleanSong-AI/Main-tool-backend-main"
|
| 9 |
|
| 10 |
def clean_song(file_path):
|
| 11 |
if file_path is None:
|
| 12 |
return None
|
| 13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
try:
|
| 15 |
+
client = Client(BACKEND_SPACE)
|
| 16 |
result = client.predict(
|
| 17 |
file_path,
|
| 18 |
api_name="/predict"
|
|
|
|
| 20 |
except Exception as e:
|
| 21 |
return f"Error calling backend: {e}"
|
| 22 |
|
| 23 |
+
return result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
# ------------------------------------------------------------
|
| 26 |
# UI
|