Spaces:
Sleeping
Sleeping
Yongkang ZOU
commited on
Commit
·
f8a57e8
1
Parent(s):
7e16d1f
update gradio ui
Browse files
app.py
CHANGED
|
@@ -14,14 +14,17 @@ def generate_music(melody_file, prompt):
|
|
| 14 |
if not MUSICGEN_API_URL:
|
| 15 |
return "❌ 未配置 MUSICGEN_API_URL,请检查 .env 文件"
|
| 16 |
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
if response.status_code == 200:
|
| 27 |
output_path = "generated_music.wav"
|
|
|
|
| 14 |
if not MUSICGEN_API_URL:
|
| 15 |
return "❌ 未配置 MUSICGEN_API_URL,请检查 .env 文件"
|
| 16 |
|
| 17 |
+
try:
|
| 18 |
+
with open(melody_file, "rb") as f: # melody_file 是字符串路径
|
| 19 |
+
files = {
|
| 20 |
+
"melody": ("hum.wav", f, "audio/wav") # 用一个合理的名字传给接口
|
| 21 |
+
}
|
| 22 |
+
data = {
|
| 23 |
+
"text": prompt
|
| 24 |
+
}
|
| 25 |
+
response = requests.post(MUSICGEN_API_URL, files=files, data=data)
|
| 26 |
+
except Exception as e:
|
| 27 |
+
return f"❌ 文件读取失败: {e}"
|
| 28 |
|
| 29 |
if response.status_code == 200:
|
| 30 |
output_path = "generated_music.wav"
|