데모버전 안정화
This commit is contained in:
1 parent
7038faaf74
commit
1e16e0e3eb
26 files changed
+1226
-109
No files matched your search
+105
-38
@@ -128,7 +128,9 @@ async def generate_song(
|
||||
project = project_result.scalar_one_or_none()
|
||||
|
||||
if not project:
|
||||
logger.warning(f"[generate_song] Project NOT FOUND - task_id: {task_id}")
|
||||
logger.warning(
|
||||
f"[generate_song] Project NOT FOUND - task_id: {task_id}"
|
||||
)
|
||||
raise HTTPException(
|
||||
status_code=404,
|
||||
detail=f"task_id '{task_id}'에 해당하는 Project를 찾을 수 없습니다.",
|
||||
@@ -143,6 +145,13 @@ async def generate_song(
|
||||
.limit(1)
|
||||
)
|
||||
lyric = lyric_result.scalar_one_or_none()
|
||||
logger.debug(
|
||||
f"[generate_song] Lyric query result - "
|
||||
f"id: {lyric.id if lyric else None}, "
|
||||
f"project_id: {lyric.project_id if lyric else None}, "
|
||||
f"task_id: {lyric.task_id if lyric else None}, "
|
||||
f"lyric_result: {lyric.lyric_result if lyric else None}"
|
||||
)
|
||||
|
||||
if not lyric:
|
||||
logger.warning(f"[generate_song] Lyric NOT FOUND - task_id: {task_id}")
|
||||
@@ -156,13 +165,25 @@ async def generate_song(
|
||||
logger.info(
|
||||
f"[generate_song] Queries completed - task_id: {task_id}, "
|
||||
f"project_id: {project_id}, lyric_id: {lyric_id}, "
|
||||
f"elapsed: {(query_time - request_start)*1000:.1f}ms"
|
||||
f"elapsed: {(query_time - request_start) * 1000:.1f}ms"
|
||||
)
|
||||
|
||||
# Song 테이블에 초기 데이터 저장
|
||||
song_prompt = (
|
||||
f"[Lyrics]\n{request_body.lyrics}\n\n[Genre]\n{request_body.genre}"
|
||||
)
|
||||
logger.debug(
|
||||
f"[generate_song] Lyrics comparison - task_id: {task_id}\n"
|
||||
f"{'=' * 60}\n"
|
||||
f"[lyric.lyric_result]\n"
|
||||
f"{'-' * 60}\n"
|
||||
f"{lyric.lyric_result}\n"
|
||||
f"{'=' * 60}\n"
|
||||
f"[song_prompt]\n"
|
||||
f"{'-' * 60}\n"
|
||||
f"{song_prompt}\n"
|
||||
f"{'=' * 60}"
|
||||
)
|
||||
|
||||
song = Song(
|
||||
project_id=project_id,
|
||||
@@ -181,7 +202,7 @@ async def generate_song(
|
||||
logger.info(
|
||||
f"[generate_song] Stage 1 DONE - Song saved - "
|
||||
f"task_id: {task_id}, song_id: {song_id}, "
|
||||
f"elapsed: {(stage1_time - request_start)*1000:.1f}ms"
|
||||
f"elapsed: {(stage1_time - request_start) * 1000:.1f}ms"
|
||||
)
|
||||
# 세션이 여기서 자동으로 닫힘
|
||||
|
||||
@@ -218,7 +239,7 @@ async def generate_song(
|
||||
logger.info(
|
||||
f"[generate_song] Stage 2 DONE - task_id: {task_id}, "
|
||||
f"suno_task_id: {suno_task_id}, "
|
||||
f"elapsed: {(stage2_time - stage2_start)*1000:.1f}ms"
|
||||
f"elapsed: {(stage2_time - stage2_start) * 1000:.1f}ms"
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
@@ -264,12 +285,12 @@ async def generate_song(
|
||||
total_time = stage3_time - request_start
|
||||
logger.info(
|
||||
f"[generate_song] Stage 3 DONE - task_id: {task_id}, "
|
||||
f"elapsed: {(stage3_time - stage3_start)*1000:.1f}ms"
|
||||
f"elapsed: {(stage3_time - stage3_start) * 1000:.1f}ms"
|
||||
)
|
||||
logger.info(
|
||||
f"[generate_song] SUCCESS - task_id: {task_id}, "
|
||||
f"suno_task_id: {suno_task_id}, "
|
||||
f"total_time: {total_time*1000:.1f}ms"
|
||||
f"total_time: {total_time * 1000:.1f}ms"
|
||||
)
|
||||
|
||||
return GenerateSongResponse(
|
||||
@@ -344,14 +365,22 @@ async def get_song_status(
|
||||
Azure Blob Storage에 업로드한 뒤 Song 테이블의 status를 completed로,
|
||||
song_result_url을 Blob URL로 업데이트합니다.
|
||||
"""
|
||||
suno_task_id = song_id # 임시방편 / 외부 suno 노출 방지
|
||||
suno_task_id = song_id # 임시방편 / 외부 suno 노출 방지
|
||||
logger.info(f"[get_song_status] START - song_id: {suno_task_id}")
|
||||
try:
|
||||
suno_service = SunoService()
|
||||
result = await suno_service.get_task_status(suno_task_id)
|
||||
logger.debug(f"[get_song_status] Suno API raw response - song_id: {suno_task_id}, result: {result}")
|
||||
logger.debug(
|
||||
f"[get_song_status] Suno API raw response - song_id: {suno_task_id}, result: {result}"
|
||||
)
|
||||
parsed_response = suno_service.parse_status_response(result)
|
||||
logger.info(f"[get_song_status] Suno API response - song_id: {suno_task_id}, status: {parsed_response.status}")
|
||||
logger.info(
|
||||
f"[get_song_status] Suno API response - song_id: {suno_task_id}, status: {parsed_response.status}"
|
||||
)
|
||||
|
||||
if parsed_response.status == "TEXT_SUCCESS" and result:
|
||||
parsed_response.status = "processing"
|
||||
return parsed_response
|
||||
|
||||
# SUCCESS 상태인 경우 백그라운드에서 MP3 다운로드 및 Blob 업로드 진행
|
||||
if parsed_response.status == "SUCCESS" and result:
|
||||
@@ -365,7 +394,9 @@ async def get_song_status(
|
||||
first_clip = clips_data[0]
|
||||
audio_url = first_clip.get("audioUrl")
|
||||
clip_duration = first_clip.get("duration")
|
||||
logger.debug(f"[get_song_status] Using first clip - id: {first_clip.get('id')}, audio_url: {audio_url}, duration: {clip_duration}")
|
||||
logger.debug(
|
||||
f"[get_song_status] Using first clip - id: {first_clip.get('id')}, audio_url: {audio_url}, duration: {clip_duration}"
|
||||
)
|
||||
|
||||
if audio_url:
|
||||
# song_id로 Song 조회
|
||||
@@ -376,7 +407,7 @@ async def get_song_status(
|
||||
.limit(1)
|
||||
)
|
||||
song = song_result.scalar_one_or_none()
|
||||
|
||||
|
||||
# processing 상태인 경우에만 백그라운드 태스크 실행 (중복 방지)
|
||||
if song and song.status == "processing":
|
||||
# store_name 조회
|
||||
@@ -388,9 +419,11 @@ async def get_song_status(
|
||||
|
||||
# 상태를 uploading으로 변경 (중복 호출 방지)
|
||||
song.status = "uploading"
|
||||
song.suno_audio_id = first_clip.get('id')
|
||||
song.suno_audio_id = first_clip.get("id")
|
||||
await session.commit()
|
||||
logger.info(f"[get_song_status] Song status changed to uploading - song_id: {suno_task_id}")
|
||||
logger.info(
|
||||
f"[get_song_status] Song status changed to uploading - song_id: {suno_task_id}"
|
||||
)
|
||||
|
||||
# 백그라운드 태스크로 MP3 다운로드 및 Blob 업로드 실행
|
||||
background_tasks.add_task(
|
||||
@@ -400,10 +433,19 @@ async def get_song_status(
|
||||
store_name=store_name,
|
||||
duration=clip_duration,
|
||||
)
|
||||
logger.info(f"[get_song_status] Background task scheduled - song_id: {suno_task_id}, store_name: {store_name}")
|
||||
logger.info(
|
||||
f"[get_song_status] Background task scheduled - song_id: {suno_task_id}, store_name: {store_name}"
|
||||
)
|
||||
|
||||
suno_audio_id = first_clip.get('id')
|
||||
word_data = await suno_service.get_lyric_timestamp(suno_task_id, suno_audio_id)
|
||||
suno_audio_id = first_clip.get("id")
|
||||
word_data = await suno_service.get_lyric_timestamp(
|
||||
suno_task_id, suno_audio_id
|
||||
)
|
||||
logger.debug(
|
||||
f"[get_song_status] word_data from get_lyric_timestamp - "
|
||||
f"suno_task_id: {suno_task_id}, suno_audio_id: {suno_audio_id}, "
|
||||
f"word_data: {word_data}"
|
||||
)
|
||||
lyric_result = await session.execute(
|
||||
select(Lyric)
|
||||
.where(Lyric.task_id == song.task_id)
|
||||
@@ -411,30 +453,52 @@ async def get_song_status(
|
||||
.limit(1)
|
||||
)
|
||||
lyric = lyric_result.scalar_one_or_none()
|
||||
gt_lyric = lyric.lyric_result
|
||||
gt_lyric = lyric.lyric_result
|
||||
lyric_line_list = gt_lyric.split("\n")
|
||||
sentences = [lyric_line.strip(',. ') for lyric_line in lyric_line_list if lyric_line and lyric_line != "---"]
|
||||
sentences = [
|
||||
lyric_line.strip(",. ")
|
||||
for lyric_line in lyric_line_list
|
||||
if lyric_line and lyric_line != "---"
|
||||
]
|
||||
logger.debug(
|
||||
f"[get_song_status] sentences from lyric - "
|
||||
f"sentences: {sentences}"
|
||||
)
|
||||
|
||||
timestamped_lyrics = suno_service.align_lyrics(
|
||||
word_data, sentences
|
||||
)
|
||||
logger.debug(
|
||||
f"[get_song_status] sentences from lyric - "
|
||||
f"sentences: {sentences}"
|
||||
)
|
||||
|
||||
timestamped_lyrics = suno_service.align_lyrics(word_data, sentences)
|
||||
# TODO : DB upload timestamped_lyrics
|
||||
for order_idx, timestamped_lyric in enumerate(timestamped_lyrics):
|
||||
for order_idx, timestamped_lyric in enumerate(
|
||||
timestamped_lyrics
|
||||
):
|
||||
song_timestamp = SongTimestamp(
|
||||
suno_audio_id = suno_audio_id,
|
||||
order_idx = order_idx,
|
||||
lyric_line = timestamped_lyric["text"],
|
||||
start_time = timestamped_lyric["start_sec"],
|
||||
end_time = timestamped_lyric["end_sec"]
|
||||
suno_audio_id=suno_audio_id,
|
||||
order_idx=order_idx,
|
||||
lyric_line=timestamped_lyric["text"],
|
||||
start_time=timestamped_lyric["start_sec"],
|
||||
end_time=timestamped_lyric["end_sec"],
|
||||
)
|
||||
session.add(song_timestamp)
|
||||
|
||||
|
||||
await session.commit()
|
||||
|
||||
elif song and song.status == "uploading":
|
||||
logger.info(f"[get_song_status] SKIPPED - Song is already uploading, song_id: {suno_task_id}")
|
||||
logger.info(
|
||||
f"[get_song_status] SKIPPED - Song is already uploading, song_id: {suno_task_id}"
|
||||
)
|
||||
parsed_response.status = "uploading"
|
||||
elif song and song.status == "completed":
|
||||
logger.info(f"[get_song_status] SKIPPED - Song already completed, song_id: {suno_task_id}")
|
||||
logger.info(
|
||||
f"[get_song_status] SKIPPED - Song already completed, song_id: {suno_task_id}"
|
||||
)
|
||||
|
||||
logger.info(f"[get_song_status] SUCCESS - song_id: {suno_task_id}")
|
||||
logger.info(f"[get_song_status] END - song_id: {suno_task_id}")
|
||||
return parsed_response
|
||||
|
||||
except Exception as e:
|
||||
@@ -520,7 +584,9 @@ async def download_song(
|
||||
error_message="Song not found",
|
||||
)
|
||||
|
||||
logger.info(f"[download_song] Song found - task_id: {task_id}, status: {song.status}")
|
||||
logger.info(
|
||||
f"[download_song] Song found - task_id: {task_id}, status: {song.status}"
|
||||
)
|
||||
|
||||
# processing 상태인 경우
|
||||
if song.status == "processing":
|
||||
@@ -559,7 +625,9 @@ async def download_song(
|
||||
)
|
||||
project = project_result.scalar_one_or_none()
|
||||
|
||||
logger.info(f"[download_song] COMPLETED - task_id: {task_id}, song_result_url: {song.song_result_url}")
|
||||
logger.info(
|
||||
f"[download_song] COMPLETED - task_id: {task_id}, song_result_url: {song.song_result_url}"
|
||||
)
|
||||
return DownloadSongResponse(
|
||||
success=True,
|
||||
status="completed",
|
||||
@@ -621,7 +689,9 @@ async def get_songs(
|
||||
pagination: PaginationParams = Depends(get_pagination_params),
|
||||
) -> PaginatedResponse[SongListItem]:
|
||||
"""완료된 노래 목록을 페이지네이션하여 반환합니다."""
|
||||
logger.info(f"[get_songs] START - page: {pagination.page}, page_size: {pagination.page_size}")
|
||||
logger.info(
|
||||
f"[get_songs] START - page: {pagination.page}, page_size: {pagination.page_size}"
|
||||
)
|
||||
try:
|
||||
offset = (pagination.page - 1) * pagination.page_size
|
||||
|
||||
@@ -630,10 +700,7 @@ async def get_songs(
|
||||
|
||||
# task_id별 최신 created_at 조회
|
||||
latest_subquery = (
|
||||
select(
|
||||
Song.task_id,
|
||||
func.max(Song.created_at).label("max_created_at")
|
||||
)
|
||||
select(Song.task_id, func.max(Song.created_at).label("max_created_at"))
|
||||
.where(Song.status == "completed")
|
||||
.group_by(Song.task_id)
|
||||
.subquery()
|
||||
@@ -651,8 +718,8 @@ async def get_songs(
|
||||
latest_subquery,
|
||||
and_(
|
||||
Song.task_id == latest_subquery.c.task_id,
|
||||
Song.created_at == latest_subquery.c.max_created_at
|
||||
)
|
||||
Song.created_at == latest_subquery.c.max_created_at,
|
||||
),
|
||||
)
|
||||
.where(Song.status == "completed")
|
||||
.order_by(Song.created_at.desc())
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from sqladmin import ModelView
|
||||
|
||||
from app.song.models import Song
|
||||
from app.song.models import Song, SongTimestamp
|
||||
|
||||
|
||||
class SongAdmin(ModelView, model=Song):
|
||||
@@ -67,3 +67,59 @@ class SongAdmin(ModelView, model=Song):
|
||||
"song_result_url": "결과 URL",
|
||||
"created_at": "생성일시",
|
||||
}
|
||||
|
||||
|
||||
class SongTimestampAdmin(ModelView, model=SongTimestamp):
|
||||
name = "노래 타임스탬프"
|
||||
name_plural = "노래 타임스탬프 목록"
|
||||
icon = "fa-solid fa-clock"
|
||||
category = "노래 관리"
|
||||
page_size = 20
|
||||
|
||||
column_list = [
|
||||
"id",
|
||||
"suno_audio_id",
|
||||
"order_idx",
|
||||
"lyric_line",
|
||||
"start_time",
|
||||
"end_time",
|
||||
"created_at",
|
||||
]
|
||||
|
||||
column_details_list = [
|
||||
"id",
|
||||
"suno_audio_id",
|
||||
"order_idx",
|
||||
"lyric_line",
|
||||
"start_time",
|
||||
"end_time",
|
||||
"created_at",
|
||||
]
|
||||
|
||||
form_excluded_columns = ["created_at"]
|
||||
|
||||
column_searchable_list = [
|
||||
SongTimestamp.suno_audio_id,
|
||||
SongTimestamp.lyric_line,
|
||||
]
|
||||
|
||||
column_default_sort = (SongTimestamp.created_at, True)
|
||||
|
||||
column_sortable_list = [
|
||||
SongTimestamp.id,
|
||||
SongTimestamp.suno_audio_id,
|
||||
SongTimestamp.order_idx,
|
||||
SongTimestamp.start_time,
|
||||
SongTimestamp.end_time,
|
||||
SongTimestamp.created_at,
|
||||
]
|
||||
|
||||
column_labels = {
|
||||
"id": "ID",
|
||||
"suno_audio_id": "Suno 오디오 ID",
|
||||
"order_idx": "순서",
|
||||
"lyric_line": "가사",
|
||||
"start_time": "시작 시간",
|
||||
"end_time": "종료 시간",
|
||||
"created_at": "생성일시",
|
||||
}
|
||||
Reference in new issue
Block a user