-
Notifications
You must be signed in to change notification settings - Fork 1
feat: 기상음악 AI 분석 기능 추가 #197
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
95558ab
chore: 자막 추출용 youtubei.js 의존성 추가
Dino0204 a2e2977
feat: 자막 데이터 검증용 web-llm 의존성 추가
Dino0204 7052355
feat: AI 분석 권한 설정 및 쿼리 추가
Dino0204 61f839b
feat: 유튜브 자막 가져오기
Dino0204 38ddc15
feat: 메인 스레드 중단 방지용 llm worker
Dino0204 4c059e9
change: 한국어를 우선순위로 변경
Dino0204 633d655
feat: 기상음악 훅에 권한 설정
Dino0204 a83edd9
refactor: 기상음악 추천 기능을 wake-up-music-recommend로 분리
Dino0204 41a6163
refactor: 기상음악 AI 분석 모듈을 wake-up-music-analysis로 구성
Dino0204 3c1e5c9
refactor: 기상음악 AI 분석 표시 컴포넌트 분리
Dino0204 af2da85
refactor: 음악 리스트 아이템에 선택·AI 상태 슬롯 추가
Dino0204 d77dfca
feat: 기상음악 크게 보기에 AI 분석·인앱 플레이어 추가
Dino0204 ee884a7
change: 기상음악 권한·훅 정리 (사감 AI 분석 제한, 미사용 날짜 헬퍼 제거)
Dino0204 a09f3de
fix: 기상음악 자막·캐시·선택표시 리뷰 반영
Dino0204 ea58171
fix: 플레이어 너비 제한
Dino0204 f76ed7f
fear: AI 면책 문구 추가
Dino0204 822e22c
feat: 자동 생성 자막 감지 및 배지 표시
Dino0204 cb2fa23
change: NoteText 다중 줄 옵션 추가
Dino0204 e02fdcd
refactor: AI 분석 결과 패널을 상태별 컴포넌트로 분리
Dino0204 38f8ed0
refactor: AI 모델 로드 상태를 단일 출처로 분리
Dino0204 55b379e
change: 크게 보기 플레이어 UI 개선
Dino0204 7dc1f7f
chore: 포맷
Dino0204 3a27c74
feat: yt-dlp docker image
Dino0204 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| import { HttpStatusCode } from "axios"; | ||
| import { NextRequest, NextResponse } from "next/server"; | ||
| import { extractYoutubeVideoId } from "@/entities/music/lib/youtube"; | ||
| import { getYoutubeTranscript } from "@/entities/music/lib/transcript"; | ||
|
|
||
| export const runtime = "nodejs"; | ||
|
|
||
| export async function GET(request: NextRequest) { | ||
| const authorization = request.headers.get("authorization"); | ||
| const accessToken = authorization?.startsWith("Bearer ") | ||
| ? authorization.slice("Bearer ".length) | ||
| : null; | ||
|
|
||
| if (!accessToken) { | ||
| return NextResponse.json( | ||
| { error: "access token 없음" }, | ||
| { status: HttpStatusCode.Unauthorized }, | ||
| ); | ||
| } | ||
|
|
||
| const params = request.nextUrl.searchParams; | ||
| const urlParam = params.get("url"); | ||
| const idParam = params.get("id"); | ||
| const videoId = | ||
| idParam ?? (urlParam ? extractYoutubeVideoId(urlParam) : null); | ||
|
|
||
| const youtubeIdRegex = /^[a-zA-Z0-9_-]{11}$/; | ||
| if (!videoId || !youtubeIdRegex.test(videoId)) { | ||
| return NextResponse.json( | ||
| { error: "올바른 형식의 videoId(id) 또는 url이 필요합니다." }, | ||
| { status: HttpStatusCode.BadRequest }, | ||
| ); | ||
| } | ||
|
Dino0204 marked this conversation as resolved.
|
||
|
|
||
| const result = await getYoutubeTranscript(videoId); | ||
|
|
||
| if ("error" in result) { | ||
| return NextResponse.json(result, { status: HttpStatusCode.NotFound }); | ||
| } | ||
|
|
||
| return NextResponse.json(result); | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| import { WebWorkerMLCEngineHandler } from "@mlc-ai/web-llm"; | ||
|
|
||
| const handler = new WebWorkerMLCEngineHandler(); | ||
|
|
||
| self.onmessage = (event: MessageEvent) => { | ||
| handler.onmessage(event); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| import type { WebWorkerMLCEngine } from "@mlc-ai/web-llm"; | ||
|
|
||
| export const MUSIC_LLM_MODEL_ID = "gemma-2-2b-it-q4f16_1-MLC"; | ||
|
|
||
| export type ModelState = | ||
| | { status: "idle" } | ||
| | { status: "loading"; progress: number } | ||
| | { status: "ready" } | ||
| | { status: "error"; message: string }; | ||
|
|
||
| const WEBGPU_UNSUPPORTED_MESSAGE = | ||
| "이 브라우저/기기에서 WebGPU를 사용할 수 없습니다."; | ||
|
|
||
| let enginePromise: Promise<WebWorkerMLCEngine> | null = null; | ||
| let modelState: ModelState = { status: "idle" }; | ||
| const listeners = new Set<() => void>(); | ||
|
|
||
| function setModelState(next: ModelState) { | ||
| modelState = next; | ||
| listeners.forEach((listener) => listener()); | ||
| } | ||
|
|
||
| export function subscribeModelState(listener: () => void): () => void { | ||
| listeners.add(listener); | ||
| return () => { | ||
| listeners.delete(listener); | ||
| }; | ||
| } | ||
|
|
||
| export function getModelStateSnapshot(): ModelState { | ||
| return modelState; | ||
| } | ||
|
|
||
| export async function ensureWebGpuSupport(): Promise<void> { | ||
| if (modelState.status !== "idle") return; | ||
|
|
||
| const gpu = ( | ||
| navigator as Navigator & { | ||
| gpu?: { requestAdapter: () => Promise<unknown> }; | ||
| } | ||
| ).gpu; | ||
|
|
||
| if (!gpu) { | ||
| setModelState({ status: "error", message: WEBGPU_UNSUPPORTED_MESSAGE }); | ||
| return; | ||
| } | ||
|
|
||
| try { | ||
| const adapter = await gpu.requestAdapter(); | ||
| if (!adapter) { | ||
| setModelState({ status: "error", message: WEBGPU_UNSUPPORTED_MESSAGE }); | ||
| } | ||
| } catch { | ||
| setModelState({ status: "error", message: WEBGPU_UNSUPPORTED_MESSAGE }); | ||
| } | ||
| } | ||
|
|
||
| export function getMusicLlmEngine(): Promise<WebWorkerMLCEngine> { | ||
| if (!enginePromise) { | ||
| setModelState({ status: "loading", progress: 0 }); | ||
| enginePromise = (async () => { | ||
| const { CreateWebWorkerMLCEngine } = await import("@mlc-ai/web-llm"); | ||
| const worker = new Worker( | ||
| new URL("./webllm.worker.ts", import.meta.url), | ||
| { | ||
| type: "module", | ||
| }, | ||
| ); | ||
|
|
||
| const engine = await CreateWebWorkerMLCEngine( | ||
| worker, | ||
| MUSIC_LLM_MODEL_ID, | ||
| { | ||
| initProgressCallback: (report) => | ||
| setModelState({ status: "loading", progress: report.progress }), | ||
| }, | ||
| ); | ||
| setModelState({ status: "ready" }); | ||
| return engine; | ||
| })().catch((error) => { | ||
| enginePromise = null; | ||
| const reason = error instanceof Error ? error.message : String(error); | ||
| setModelState({ | ||
| status: "error", | ||
| message: reason.includes("WebGPU") | ||
| ? WEBGPU_UNSUPPORTED_MESSAGE | ||
| : "AI 모델을 불러오지 못했습니다.", | ||
| }); | ||
| throw error; | ||
| }); | ||
| } | ||
|
|
||
| return enginePromise; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| "use client"; | ||
|
|
||
| import { useSyncExternalStore } from "react"; | ||
| import { | ||
| getModelStateSnapshot, | ||
| subscribeModelState, | ||
| type ModelState, | ||
| } from "@/entities/ai/lib/webllmEngine"; | ||
|
|
||
| export function useModelState(): ModelState { | ||
| return useSyncExternalStore( | ||
| subscribeModelState, | ||
| getModelStateSnapshot, | ||
| getModelStateSnapshot, | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,23 @@ | ||
| import type { UserRole } from "@/entities/user/model/user"; | ||
|
|
||
| // 기자위(DORMITORY_MANAGER) 중 AI 분석을 쓸 수 있는 사감 계정 이름 | ||
| const DORM_SUPERVISOR_NAME = "사감선생님"; | ||
|
|
||
| interface CreateMusicPermissionParams { | ||
| role?: UserRole; | ||
| name?: string; | ||
| } | ||
|
|
||
| export function createMusicPermission({ role }: CreateMusicPermissionParams) { | ||
| export function createMusicPermission({ | ||
| role, | ||
| name, | ||
| }: CreateMusicPermissionParams) { | ||
| const isDormManager = role === "DORMITORY_MANAGER"; | ||
|
|
||
| return { | ||
| canDeleteAnyMusic: role === "ADMIN" || role === "DORMITORY_MANAGER", | ||
| canDeleteAnyMusic: role === "ADMIN" || isDormManager, | ||
| // 어드민은 모두 가능, 기자위는 사감선생님만 가능 | ||
| canUseAiAnalysis: | ||
| role === "ADMIN" || (isDormManager && name === DORM_SUPERVISOR_NAME), | ||
|
Dino0204 marked this conversation as resolved.
|
||
| }; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.