bharatverse11 commited on
Commit
cab9b9b
Β·
verified Β·
1 Parent(s): 28a7261

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +78 -22
app.py CHANGED
@@ -1,42 +1,98 @@
1
  import gradio as gr
2
  import requests
3
  import base64
4
- import numpy as np
5
  import io
6
  import soundfile as sf
7
 
 
8
  API_URL = "https://bustled-hertha-unprojective.ngrok-free.dev/generate"
9
 
 
10
  def generate(prompt, duration, steps, cfg):
11
- res = requests.post(API_URL, json={
12
- "prompt": prompt,
13
- "duration": duration,
14
- "steps": steps,
15
- "cfg_scale": cfg
16
- }, timeout=120)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
 
18
- data = res.json()
19
 
20
- # βœ… decode base64 properly
21
- audio_bytes = base64.b64decode(data["audio"])
 
 
22
 
23
- # convert to numpy using soundfile
24
- audio, sr = sf.read(io.BytesIO(audio_bytes))
 
 
 
 
25
 
26
- return sr, audio
 
 
 
27
 
 
 
 
 
28
 
29
- with gr.Blocks() as demo:
30
- gr.Markdown("## 🎡 AutoMix AI Beat Generator")
 
 
31
 
32
- prompt = gr.Textbox(label="Prompt", placeholder="Dark trap beat, 140 BPM...")
33
- duration = gr.Slider(1, 10, value=5, label="Duration (seconds)")
34
- steps = gr.Slider(20, 80, value=40, label="Steps")
35
- cfg = gr.Slider(1, 10, value=7, label="CFG Scale")
36
 
37
- btn = gr.Button("Generate Beat πŸš€")
38
- out = gr.Audio(label="Output")
39
 
40
- btn.click(generate, [prompt, duration, steps, cfg], out)
 
 
 
 
41
 
42
  demo.launch()
 
1
  import gradio as gr
2
  import requests
3
  import base64
 
4
  import io
5
  import soundfile as sf
6
 
7
+ # πŸ”₯ IMPORTANT: your ngrok API endpoint
8
  API_URL = "https://bustled-hertha-unprojective.ngrok-free.dev/generate"
9
 
10
+
11
  def generate(prompt, duration, steps, cfg):
12
+ try:
13
+ # πŸš€ send request to backend
14
+ res = requests.post(
15
+ API_URL,
16
+ json={
17
+ "prompt": prompt,
18
+ "duration": duration,
19
+ "steps": steps,
20
+ "cfg_scale": cfg
21
+ },
22
+ timeout=180 # longer timeout for generation
23
+ )
24
+
25
+ print("STATUS:", res.status_code)
26
+
27
+ # ❌ backend error
28
+ if res.status_code != 200:
29
+ print("❌ Backend error:", res.text[:300])
30
+ return None
31
+
32
+ # ❌ empty response
33
+ if not res.text:
34
+ print("❌ Empty response")
35
+ return None
36
+
37
+ # ❌ invalid JSON
38
+ try:
39
+ data = res.json()
40
+ except Exception:
41
+ print("❌ Invalid JSON:", res.text[:300])
42
+ return None
43
+
44
+ # ❌ missing audio
45
+ if "audio" not in data:
46
+ print("❌ No audio key:", data)
47
+ return None
48
+
49
+ # βœ… decode base64 β†’ audio
50
+ audio_bytes = base64.b64decode(data["audio"])
51
+ audio, sr = sf.read(io.BytesIO(audio_bytes))
52
+
53
+ return sr, audio
54
+
55
+ except Exception as e:
56
+ print("❌ Request failed:", str(e))
57
+ return None
58
 
 
59
 
60
+ # 🎨 UI
61
+ with gr.Blocks(title="AutoMix AI 🎡") as demo:
62
+ gr.Markdown("# 🎡 AutoMix AI Beat Generator")
63
+ gr.Markdown("Generate AI beats using diffusion model πŸš€")
64
 
65
+ with gr.Row():
66
+ with gr.Column():
67
+ prompt = gr.Textbox(
68
+ label="🎧 Prompt",
69
+ placeholder="Dark trap beat, 140 BPM, heavy 808..."
70
+ )
71
 
72
+ duration = gr.Slider(
73
+ 1, 10, value=5, step=1,
74
+ label="⏱ Duration (seconds)"
75
+ )
76
 
77
+ steps = gr.Slider(
78
+ 20, 80, value=40, step=5,
79
+ label="βš™οΈ Diffusion Steps"
80
+ )
81
 
82
+ cfg = gr.Slider(
83
+ 1, 10, value=7, step=0.5,
84
+ label="πŸŽ› CFG Scale"
85
+ )
86
 
87
+ btn = gr.Button("πŸš€ Generate Beat", variant="primary")
 
 
 
88
 
89
+ with gr.Column():
90
+ output = gr.Audio(label="🎡 Generated Beat")
91
 
92
+ btn.click(
93
+ fn=generate,
94
+ inputs=[prompt, duration, steps, cfg],
95
+ outputs=output
96
+ )
97
 
98
  demo.launch()