'commit'
This commit is contained in:
@@ -9,7 +9,7 @@ import fastapi
|
||||
from fastapi import APIRouter, HTTPException, Query
|
||||
from pydantic import BaseModel
|
||||
|
||||
from Routes.suno_music_generator import SunoMusicGenerator
|
||||
from Suno.sunoUtil import SunoMusicGenerator
|
||||
from Config import Config
|
||||
|
||||
# 创建路由路由器
|
||||
|
Binary file not shown.
0
dsLightRag/Suno/__init__.py
Normal file
0
dsLightRag/Suno/__init__.py
Normal file
BIN
dsLightRag/Suno/__pycache__/__init__.cpython-310.pyc
Normal file
BIN
dsLightRag/Suno/__pycache__/__init__.cpython-310.pyc
Normal file
Binary file not shown.
Binary file not shown.
@@ -129,14 +129,14 @@
|
||||
<option value="">请选择情绪与场景</option>
|
||||
<option value="夏日海边">夏日海边</option>
|
||||
<option value="深夜治愈">深夜治愈</option>
|
||||
<option value="热血励志">热血励志</option>
|
||||
<option value="热血沥水">热血沥水</option>
|
||||
<option value="国风江湖">国风江湖</option>
|
||||
<option value="安静学习">安静学习</option>
|
||||
<option value="欢快活泼">欢快活泼</option>
|
||||
<option value="庄重严肃">庄重严肃</option>
|
||||
<option value="温馨感动">温馨感动</option>
|
||||
</select>
|
||||
<div class="form-helper">示例:「夏日海边」「深夜治愈」「热血励志」</div>
|
||||
<div class="form-helper">示例:「夏日海边」「深夜治愈」「热血沥水」</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
@@ -197,6 +197,13 @@
|
||||
<div class="form-helper">添加教学科目可以让音乐更贴合特定学科的学习氛围</div>
|
||||
</div>
|
||||
|
||||
<!-- 添加音乐时长输入字段 -->
|
||||
<div class="form-group">
|
||||
<label for="duration" class="form-label">8. 音乐时长(分钟)</label>
|
||||
<input type="number" id="duration" class="form-input" min="0.5" max="10" step="0.5" value="2" required>
|
||||
<div class="form-helper">请输入0.5-10分钟之间的时长,步长0.5分钟</div>
|
||||
</div>
|
||||
|
||||
<div class="form-actions">
|
||||
<button type="submit" class="btn btn-primary"><i class="fas fa-magic"></i> 生成音乐提示词</button>
|
||||
<button type="button" id="randomSampleBtn" class="btn btn-info"><i class="fas fa-random"></i> 随机示例</button>
|
||||
@@ -231,7 +238,8 @@
|
||||
tempo: "4/4 拍 120 BPM",
|
||||
instruments: "吉他+贝斯+鼓",
|
||||
theme: "快乐学习",
|
||||
teachingSubject: "英语"
|
||||
teachingSubject: "英语",
|
||||
duration: 2 // 添加时长字段
|
||||
},
|
||||
{
|
||||
style: "古风",
|
||||
@@ -240,7 +248,8 @@
|
||||
tempo: "4/4 拍 80 BPM",
|
||||
instruments: "笛子+古筝",
|
||||
theme: "诗词歌赋",
|
||||
teachingSubject: "语文"
|
||||
teachingSubject: "语文",
|
||||
duration: 3 // 添加时长字段
|
||||
},
|
||||
{
|
||||
style: "Classical",
|
||||
@@ -249,7 +258,8 @@
|
||||
tempo: "3/4 拍 90 BPM",
|
||||
instruments: "钢琴弦乐",
|
||||
theme: "数学的旋律",
|
||||
teachingSubject: "数学"
|
||||
teachingSubject: "数学",
|
||||
duration: 4 // 添加时长字段
|
||||
},
|
||||
{
|
||||
style: "民谣",
|
||||
@@ -280,7 +290,7 @@
|
||||
},
|
||||
{
|
||||
style: "摇滚",
|
||||
mood: "热血励志",
|
||||
mood: "热血沥水",
|
||||
vocal: "高亢女声",
|
||||
tempo: "4/4 拍 140 BPM",
|
||||
instruments: "吉他+贝斯+鼓",
|
||||
@@ -321,6 +331,7 @@
|
||||
document.getElementById('instruments').value = sample.instruments;
|
||||
document.getElementById('theme').value = sample.theme;
|
||||
document.getElementById('teachingSubject').value = sample.teachingSubject;
|
||||
document.getElementById('duration').value = sample.duration; // 填充时长
|
||||
|
||||
// 隐藏结果区域
|
||||
resultContainer.style.display = 'none';
|
||||
@@ -338,13 +349,14 @@
|
||||
const instruments = document.getElementById('instruments').value;
|
||||
const theme = document.getElementById('theme').value;
|
||||
const teachingSubject = document.getElementById('teachingSubject').value;
|
||||
const duration = document.getElementById('duration').value; // 获取时长
|
||||
|
||||
// 生成提示词
|
||||
let prompt = `${style} ${mood},${vocal},${tempo},配${instruments},主题围绕'${theme}'`;
|
||||
if (teachingSubject) {
|
||||
prompt += `,适合${teachingSubject}教学使用`;
|
||||
}
|
||||
prompt += `,时长 2 分钟。`;
|
||||
prompt += `,时长${duration}分钟。`; // 添加时长到提示词
|
||||
|
||||
// 显示结果
|
||||
resultContent.textContent = prompt;
|
||||
|
135
dsLightRag/static/Suno/music_progress.html
Normal file
135
dsLightRag/static/Suno/music_progress.html
Normal file
@@ -0,0 +1,135 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>音乐生成进度</title>
|
||||
<style>
|
||||
* {
|
||||
margin: 0; padding: 0; box-sizing: border-box;
|
||||
font-family: 'PingFang SC', 'Microsoft YaHei', sans-serif;
|
||||
}
|
||||
body { background-color: #f5f7fa; color: #333; line-height: 1.6; }
|
||||
.container { max-width: 800px; margin: 50px auto; padding: 20px; background-color: white; border-radius: 10px; box-shadow: 0 2px 15px rgba(0,0,0,0.05); }
|
||||
h1 { font-size: 2rem; margin-bottom: 30px; color: #3498db; text-align: center; }
|
||||
.progress-container { margin: 40px 0; }
|
||||
.progress-title { margin-bottom: 15px; font-weight: 500; font-size: 1.1rem; }
|
||||
.progress-bar { height: 20px; background-color: #f1f1f1; border-radius: 10px; overflow: hidden; position: relative; }
|
||||
.progress-fill { height: 100%; background: linear-gradient(90deg, #3498db, #8e44ad); border-radius: 10px; transition: width 0.3s; width: 0%; }
|
||||
.progress-text { position: absolute; top: 0; right: 10px; line-height: 20px; color: white; font-weight: bold; }
|
||||
.status-message { margin-top: 20px; padding: 15px; border-radius: 6px; background-color: #f8f9fa; border: 1px solid #eee; text-align: center; }
|
||||
.player-container { margin-top: 40px; display: none; }
|
||||
.audio-player { width: 100%; margin-top: 20px; }
|
||||
.back-button { display: block; margin: 30px auto 0; padding: 12px 30px; background-color: #3498db; color: white; border: none; border-radius: 6px; cursor: pointer; font-size: 16px; transition: background 0.3s; text-align: center; text-decoration: none; max-width: 200px; }
|
||||
.back-button:hover { background-color: #2980b9; }
|
||||
</style>
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<h1><i class="fas fa-music"></i> 音乐生成进度</h1>
|
||||
|
||||
<div class="progress-container">
|
||||
<div class="progress-title">生成进度</div>
|
||||
<div class="progress-bar">
|
||||
<div class="progress-fill" id="progressFill"><span class="progress-text" id="progressText">0%</span></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="status-message" id="statusMessage">
|
||||
<i class="fas fa-spinner fa-spin"></i> 正在准备生成音乐...
|
||||
</div>
|
||||
|
||||
<div class="player-container" id="playerContainer">
|
||||
<h2 style="text-align: center; margin-bottom: 20px;">音乐已生成完成</h2>
|
||||
<div id="musicTitle" style="text-align: center; font-size: 1.2rem; margin-bottom: 10px;"></div>
|
||||
<audio id="audioPlayer" class="audio-player" controls>
|
||||
<source id="audioSource" type="audio/mpeg">
|
||||
您的浏览器不支持音频元素。
|
||||
</audio>
|
||||
</div>
|
||||
|
||||
<a href="index.html" class="back-button"><i class="fas fa-arrow-left"></i> 返回创作页</a>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
// 获取URL中的任务ID
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
const taskId = urlParams.get('task_id');
|
||||
|
||||
if (!taskId) {
|
||||
document.getElementById('statusMessage').innerHTML = '<i class="fas fa-exclamation-circle"></i> 无效的任务ID';
|
||||
return;
|
||||
}
|
||||
|
||||
// 轮询任务状态
|
||||
let progressInterval;
|
||||
let progress = 0;
|
||||
|
||||
function checkTaskStatus() {
|
||||
fetch(`/api/suno/check_task_status?task_id=${taskId}`)
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
// 更新状态信息
|
||||
const statusMessage = document.getElementById('statusMessage');
|
||||
const progressFill = document.getElementById('progressFill');
|
||||
const progressText = document.getElementById('progressText');
|
||||
|
||||
if (data.status === 'error') {
|
||||
clearInterval(progressInterval);
|
||||
statusMessage.innerHTML = `<i class="fas fa-exclamation-circle"></i> 生成失败: ${data.error || '未知错误'}`;
|
||||
statusMessage.style.backgroundColor = '#ffebee';
|
||||
statusMessage.style.borderColor = '#ef9a9a';
|
||||
return;
|
||||
}
|
||||
|
||||
statusMessage.innerHTML = `<i class="fas fa-spinner fa-spin"></i> ${data.message || '正在生成音乐...'}`;
|
||||
|
||||
// 更新进度条
|
||||
if (data.progress) {
|
||||
progress = Math.min(data.progress, 100);
|
||||
} else if (data.status === 'completed') {
|
||||
progress = 100;
|
||||
} else if (data.status === 'processing') {
|
||||
// 如果没有具体进度,模拟进度增加
|
||||
if (progress < 90) {
|
||||
progress += 1;
|
||||
}
|
||||
}
|
||||
|
||||
progressFill.style.width = `${progress}%`;
|
||||
progressText.textContent = `${progress}%`;
|
||||
|
||||
// 任务完成
|
||||
if (data.status === 'completed') {
|
||||
clearInterval(progressInterval);
|
||||
statusMessage.innerHTML = '<i class="fas fa-check-circle"></i> 音乐生成完成!';
|
||||
statusMessage.style.backgroundColor = '#e8f5e9';
|
||||
statusMessage.style.borderColor = '#a5d6a7';
|
||||
|
||||
// 显示播放器
|
||||
const playerContainer = document.getElementById('playerContainer');
|
||||
playerContainer.style.display = 'block';
|
||||
|
||||
// 设置音乐标题和源
|
||||
document.getElementById('musicTitle').textContent = data.title || '生成的音乐';
|
||||
const audioSource = document.getElementById('audioSource');
|
||||
audioSource.src = data.audio_url || '';
|
||||
document.getElementById('audioPlayer').load();
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('检查任务状态失败:', error);
|
||||
});
|
||||
}
|
||||
|
||||
// 立即检查一次
|
||||
checkTaskStatus();
|
||||
|
||||
// 然后每3秒检查一次
|
||||
progressInterval = setInterval(checkTaskStatus, 3000);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Reference in New Issue
Block a user