CleanSong commited on
Commit
8fa6ed1
·
verified ·
1 Parent(s): eabef44

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -0
app.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import requests
3
+ import os
4
+
5
+ # Hugging Face API token stored as a secret in the frontend Space
6
+ HF_TOKEN = os.environ.get("HF_TOKEN") # Set in your HF Space secrets
7
+ BACKEND_SPACE_API = "https://hf.space/embed/CleanSong-AI/Main-tool-backend-main/api/predict/"
8
+
9
+ def clean_song(file):
10
+ """
11
+ Sends the uploaded audio file to the private orchestrator
12
+ and returns the cleaned audio file.
13
+ """
14
+ if file is None:
15
+ return None
16
+
17
+ files = {"data": (file.name, open(file.name, "rb"), "audio/mpeg")}
18
+ headers = {"Authorization": f"Bearer {HF_TOKEN}"}
19
+
20
+ try:
21
+ response = requests.post(BACKEND_SPACE_API, files=files, headers=headers)
22
+ response.raise_for_status()
23
+ except Exception as e:
24
+ return f"Error: {e}"
25
+
26
+ # HF backend should return processed audio as bytes
27
+ cleaned_file_bytes = response.content
28
+
29
+ # Save locally to return to user
30
+ output_path = "cleaned_output.mp3"
31
+ with open(output_path, "wb") as f:
32
+ f.write(cleaned_file_bytes)
33
+
34
+ return output_path
35
+
36
+ # Gradio interface
37
+ iface = gr.Interface(
38
+ fn=clean_song,
39
+ inputs=gr.Audio(type="file", label="Upload Song"),
40
+ outputs=gr.Audio(type="file", label="Cleaned Song"),
41
+ title="CleanSong AI - Prototype Frontend",
42
+ description="Upload a song and get a cleaned version. Early prototype!"
43
+ )
44
+
45
+ if __name__ == "__main__":
46
+ iface.launch()