Jacong commited on
Commit
c372f9b
ยท
verified ยท
1 Parent(s): 2a9cfa7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -10
app.py CHANGED
@@ -1,16 +1,55 @@
1
- import os
2
  import gradio as gr
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
 
4
- def info():
5
- return "Muse Space ๅทฒๅฏๅŠจใ€‚่ฏทๆŸฅ็œ‹ Logs ไฝฟ็”จๅ‘ฝไปค่กŒๆŽจ็†ใ€‚"
 
6
 
7
- demo = gr.Interface(
8
- fn=info,
9
- inputs=[],
10
- outputs="text",
11
- title="Muse (CLI-based)",
12
- description="Muse ๅฎ˜ๆ–นไป“ๅบ“ๆœชๆไพ› Web UIใ€‚ๆœฌ Space ไป…็”จไบŽๅฏๅŠจ็Žฏๅขƒใ€‚"
13
- )
14
 
15
  if __name__ == "__main__":
16
  demo.launch()
 
 
1
  import gradio as gr
2
+ import subprocess
3
+ import os
4
+ import uuid
5
+
6
+ OUTPUT_DIR = "outputs"
7
+ os.makedirs(OUTPUT_DIR, exist_ok=True)
8
+
9
+ def generate_music(prompt):
10
+ uid = str(uuid.uuid4())[:8]
11
+ out_wav = os.path.join(OUTPUT_DIR, f"{uid}.wav")
12
+
13
+ cmd = [
14
+ "python",
15
+ "infer/run_infer.py",
16
+ "--model", "bolshyC/Muse-0.6b",
17
+ "--prompt", prompt,
18
+ "--out", out_wav
19
+ ]
20
+
21
+ try:
22
+ subprocess.run(
23
+ cmd,
24
+ check=True,
25
+ timeout=600
26
+ )
27
+ except Exception as e:
28
+ return None, f"็”Ÿๆˆๅคฑ่ดฅ๏ผš{e}"
29
+
30
+ if not os.path.exists(out_wav):
31
+ return None, "็”Ÿๆˆๅคฑ่ดฅ๏ผšๆœชๆ‰พๅˆฐ้Ÿณ้ข‘ๆ–‡ไปถ"
32
+
33
+ return out_wav, "็”ŸๆˆๅฎŒๆˆ"
34
+
35
+ with gr.Blocks() as demo:
36
+ gr.Markdown("# ๐ŸŽต Muse Music Generator (HF Space)")
37
+ gr.Markdown("ไฝฟ็”จ Muse-0.6b ๅœจ HF Space ไธŠ็”Ÿๆˆ้Ÿณไน๏ผˆCLI ๆŽฅๅ…ฅ๏ผ‰")
38
+
39
+ prompt = gr.Textbox(
40
+ label="Prompt",
41
+ placeholder="A calm piano melody, slow tempo"
42
+ )
43
 
44
+ btn = gr.Button("Generate")
45
+ audio = gr.Audio(label="Output", type="filepath")
46
+ status = gr.Textbox(label="Status")
47
 
48
+ btn.click(
49
+ fn=generate_music,
50
+ inputs=prompt,
51
+ outputs=[audio, status]
52
+ )
 
 
53
 
54
  if __name__ == "__main__":
55
  demo.launch()