tee342 commited on
Commit
5f09bf5
·
verified ·
1 Parent(s): 7b50d42

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -0
app.py CHANGED
@@ -850,6 +850,38 @@ with gr.Blocks(css="""
850
  title="Export Stems + Final Mix Together",
851
  description="Perfect for sharing with producers or archiving"
852
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
853
 
854
  # Launch Gradio App
855
  demo.launch()
 
850
  title="Export Stems + Final Mix Together",
851
  description="Perfect for sharing with producers or archiving"
852
  )
853
+ # Add this at the bottom of your app.py (or in a dedicated section)
854
+
855
+ def huggingface_predict_interface(audio_url, effects, isolate, preset, fmt):
856
+ # Save base64 audio to file
857
+ import base64, tempfile
858
+ header, encoded = audio_url.split(",", 1)
859
+ audio_binary = base64.b64decode(encoded)
860
+ with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as f:
861
+ f.write(audio_binary)
862
+ audio_path = f.name
863
+
864
+ # Run your existing process_audio function
865
+ output_path, _, _, _, _, _ = process_audio(audio_path, effects, isolate, preset, fmt)
866
+
867
+ # Return base64 string back
868
+ with open(output_path, "rb") as f:
869
+ encoded_out = base64.b64encode(f.read()).decode("utf-8")
870
+ return f"data:audio/{fmt.lower()};base64,{encoded_out}"
871
+
872
+ # Define Gradio interface for API
873
+ gr.Interface(
874
+ fn=huggingface_predict_interface,
875
+ inputs=[
876
+ gr.Text(label="Audio Data URL"), # base64 string
877
+ gr.Textbox(label="Effects JSON List"), # or gr.List if calling internally
878
+ gr.Checkbox(label="Isolate Vocals"),
879
+ gr.Textbox(label="Preset Name"),
880
+ gr.Textbox(label="Export Format")
881
+ ],
882
+ outputs=gr.Text(label="Processed Audio URL"),
883
+ allow_flagging="never"
884
+ ).launch()
885
 
886
  # Launch Gradio App
887
  demo.launch()