Compare commits
6 Commits
prochains-
...
6ae861ff54
| Author | SHA1 | Date | |
|---|---|---|---|
| 6ae861ff54 | |||
| b74c6b0b40 | |||
| 4d8fa57ab2 | |||
| 36652ea2cc | |||
| 3b236d6af4 | |||
| 64ba7f9006 |
@@ -13,6 +13,95 @@ env:
|
||||
IMAGE_FRONTEND: audio-classifier-frontend
|
||||
|
||||
jobs:
|
||||
build-backend:
|
||||
name: Build Backend Image
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Download Essentia models
|
||||
run: |
|
||||
mkdir -p backend/models
|
||||
cd backend/models
|
||||
|
||||
# Download models from Essentia
|
||||
echo "Downloading Essentia models..."
|
||||
|
||||
# Embedding model (18 MB)
|
||||
curl -L -o discogs-effnet-bs64-1.pb \
|
||||
https://essentia.upf.edu/models/feature-extractors/discogs-effnet/discogs-effnet-bs64-1.pb
|
||||
|
||||
# Genre classifier (2 MB)
|
||||
curl -L -o genre_discogs400-discogs-effnet-1.pb \
|
||||
https://essentia.upf.edu/models/classification-heads/genre_discogs400/genre_discogs400-discogs-effnet-1.pb
|
||||
|
||||
# Genre metadata
|
||||
curl -L -o genre_discogs400-discogs-effnet-1.json \
|
||||
https://essentia.upf.edu/models/classification-heads/genre_discogs400/genre_discogs400-discogs-effnet-1.json
|
||||
|
||||
# Mood classifier (2.7 MB)
|
||||
curl -L -o mtg_jamendo_moodtheme-discogs-effnet-1.pb \
|
||||
https://essentia.upf.edu/models/classification-heads/mtg_jamendo_moodtheme/mtg_jamendo_moodtheme-discogs-effnet-1.pb
|
||||
|
||||
# Instrument classifier (2.6 MB)
|
||||
curl -L -o mtg_jamendo_instrument-discogs-effnet-1.pb \
|
||||
https://essentia.upf.edu/models/classification-heads/mtg_jamendo_instrument/mtg_jamendo_instrument-discogs-effnet-1.pb
|
||||
|
||||
# Genre classifier alternative (2.7 MB)
|
||||
curl -L -o mtg_jamendo_genre-discogs-effnet-1.pb \
|
||||
https://essentia.upf.edu/models/classification-heads/mtg_jamendo_genre/mtg_jamendo_genre-discogs-effnet-1.pb
|
||||
|
||||
ls -lh
|
||||
echo "Models downloaded successfully!"
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Login to Gitea Container Registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ${{ env.REGISTRY }}
|
||||
username: ${{ gitea.actor }}
|
||||
password: ${{ secrets.REGISTRY_TOKEN }}
|
||||
|
||||
- name: Determine version
|
||||
id: version
|
||||
run: |
|
||||
if [[ "${{ gitea.ref }}" == refs/tags/v* ]]; then
|
||||
echo "VERSION=${GITEA_REF#refs/tags/}" >> $GITHUB_OUTPUT
|
||||
else
|
||||
echo "VERSION=dev-$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
|
||||
- name: Extract metadata
|
||||
id: meta
|
||||
uses: docker/metadata-action@v5
|
||||
with:
|
||||
images: ${{ env.REGISTRY }}/${{ gitea.repository_owner }}/${{ env.IMAGE_BACKEND }}
|
||||
tags: |
|
||||
type=semver,pattern={{version}}
|
||||
type=semver,pattern={{major}}.{{minor}}
|
||||
type=raw,value=latest,enable=${{ startsWith(gitea.ref, 'refs/tags/v') }}
|
||||
type=raw,value=dev,enable=${{ gitea.ref == 'refs/heads/main' }}
|
||||
type=sha,prefix=dev-,format=short,enable=${{ gitea.ref == 'refs/heads/main' }}
|
||||
|
||||
- name: Build and push backend
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
context: .
|
||||
file: ./backend/Dockerfile
|
||||
push: true
|
||||
build-args: |
|
||||
VERSION=${{ steps.version.outputs.VERSION }}
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ gitea.repository_owner }}/${{ env.IMAGE_BACKEND }}:buildcache
|
||||
cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ gitea.repository_owner }}/${{ env.IMAGE_BACKEND }}:buildcache,mode=max
|
||||
|
||||
build-frontend:
|
||||
name: Build Frontend Image
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
@@ -41,6 +41,9 @@ def find_audio_files(directory: str) -> list[Path]:
|
||||
return []
|
||||
|
||||
for root, dirs, files in os.walk(directory_path):
|
||||
# Skip transcoded and waveforms directories
|
||||
dirs[:] = [d for d in dirs if d not in ['transcoded', 'waveforms', '.transcoded', '.waveforms']]
|
||||
|
||||
for file in files:
|
||||
file_path = Path(root) / file
|
||||
if file_path.suffix.lower() in AUDIO_EXTENSIONS:
|
||||
|
||||
@@ -46,6 +46,9 @@ def find_audio_files(directory: str) -> List[Path]:
|
||||
logger.info(f"Scanning directory: {directory}")
|
||||
|
||||
for root, dirs, files in os.walk(directory_path):
|
||||
# Skip transcoded and waveforms directories
|
||||
dirs[:] = [d for d in dirs if d not in ['transcoded', 'waveforms', '.transcoded', '.waveforms']]
|
||||
|
||||
for file in files:
|
||||
file_path = Path(root) / file
|
||||
if file_path.suffix.lower() in AUDIO_EXTENSIONS:
|
||||
|
||||
@@ -41,9 +41,7 @@ services:
|
||||
image: git.benoitsz.com/benoit/audio-classifier-frontend:dev
|
||||
container_name: audio_classifier_ui
|
||||
environment:
|
||||
# In production, set NEXT_PUBLIC_API_URL to your server's public URL
|
||||
# Example: NEXT_PUBLIC_API_URL=https://yourserver.com:8001
|
||||
NEXT_PUBLIC_API_URL: ${NEXT_PUBLIC_API_URL:-http://localhost:8001}
|
||||
NEXT_PUBLIC_API_URL: https://api.audioclassifier.benoitsz.com
|
||||
ports:
|
||||
- "3000:3000"
|
||||
depends_on:
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
import { useState, useMemo } from "react"
|
||||
import { useQuery } from "@tanstack/react-query"
|
||||
import { getTracks } from "@/lib/api"
|
||||
import { getTracks, getApiUrl } from "@/lib/api"
|
||||
import type { FilterParams, Track } from "@/lib/types"
|
||||
import FilterPanel from "@/components/FilterPanel"
|
||||
import AudioPlayer from "@/components/AudioPlayer"
|
||||
@@ -90,7 +90,7 @@ export default function Home() {
|
||||
setIsScanning(true)
|
||||
setScanStatus("Démarrage du scan...")
|
||||
|
||||
const response = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/library/scan`, {
|
||||
const response = await fetch(`${getApiUrl()}/api/library/scan`, {
|
||||
method: 'POST',
|
||||
})
|
||||
|
||||
@@ -103,7 +103,7 @@ export default function Home() {
|
||||
// Poll scan status
|
||||
const pollInterval = setInterval(async () => {
|
||||
try {
|
||||
const statusResponse = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/library/scan/status`)
|
||||
const statusResponse = await fetch(`${getApiUrl()}/api/library/scan/status`)
|
||||
const status = await statusResponse.json()
|
||||
|
||||
if (!status.is_scanning) {
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
import { useState, useRef, useEffect } from "react"
|
||||
import type { Track } from "@/lib/types"
|
||||
import { getApiUrl } from "@/lib/api"
|
||||
|
||||
interface AudioPlayerProps {
|
||||
track: Track | null
|
||||
@@ -79,7 +80,7 @@ export default function AudioPlayer({ track, isPlaying, onPlayingChange }: Audio
|
||||
setIsLoadingWaveform(true)
|
||||
try {
|
||||
const response = await fetch(
|
||||
`${process.env.NEXT_PUBLIC_API_URL}/api/audio/waveform/${trackId}`
|
||||
`${getApiUrl()}/api/audio/waveform/${trackId}`
|
||||
)
|
||||
if (response.ok) {
|
||||
const data = await response.json()
|
||||
@@ -161,7 +162,7 @@ export default function AudioPlayer({ track, isPlaying, onPlayingChange }: Audio
|
||||
return (
|
||||
<div className="bg-gray-50 border-t border-gray-300 shadow-lg" style={{ height: '80px' }}>
|
||||
{/* Hidden audio element */}
|
||||
{track && <audio ref={audioRef} src={`${process.env.NEXT_PUBLIC_API_URL}/api/audio/stream/${track.id}`} />}
|
||||
{track && <audio ref={audioRef} src={`${getApiUrl()}/api/audio/stream/${track.id}`} />}
|
||||
|
||||
<div className="h-full flex items-center gap-3 px-4">
|
||||
{/* Play/Pause button */}
|
||||
@@ -300,7 +301,7 @@ export default function AudioPlayer({ track, isPlaying, onPlayingChange }: Audio
|
||||
{/* Download button */}
|
||||
{track && (
|
||||
<a
|
||||
href={`${process.env.NEXT_PUBLIC_API_URL}/api/audio/download/${track.id}`}
|
||||
href={`${getApiUrl()}/api/audio/download/${track.id}`}
|
||||
download
|
||||
className="w-8 h-8 flex items-center justify-center text-gray-600 hover:text-gray-900 transition-colors rounded hover:bg-gray-200 flex-shrink-0"
|
||||
aria-label="Download"
|
||||
|
||||
@@ -15,35 +15,36 @@ import type {
|
||||
} from './types'
|
||||
|
||||
// Get API URL from runtime config (injected at container startup) or fallback to env var
|
||||
function getApiUrl(): string {
|
||||
export function getApiUrl(): string {
|
||||
if (typeof window !== 'undefined' && (window as any).__RUNTIME_CONFIG__) {
|
||||
return (window as any).__RUNTIME_CONFIG__.API_URL
|
||||
}
|
||||
return process.env.NEXT_PUBLIC_API_URL || 'http://localhost:8000'
|
||||
}
|
||||
|
||||
const API_BASE_URL = getApiUrl()
|
||||
|
||||
const apiClient = axios.create({
|
||||
baseURL: API_BASE_URL,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
})
|
||||
// Create axios instance dynamically to use runtime config
|
||||
function getApiClient() {
|
||||
return axios.create({
|
||||
baseURL: getApiUrl(),
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// Tracks
|
||||
export async function getTracks(params: FilterParams & { skip?: number; limit?: number }): Promise<TracksResponse> {
|
||||
const response = await apiClient.get('/api/tracks', { params })
|
||||
const response = await getApiClient().get('/api/tracks', { params })
|
||||
return response.data
|
||||
}
|
||||
|
||||
export async function getTrack(id: string): Promise<Track> {
|
||||
const response = await apiClient.get(`/api/tracks/${id}`)
|
||||
const response = await getApiClient().get(`/api/tracks/${id}`)
|
||||
return response.data
|
||||
}
|
||||
|
||||
export async function deleteTrack(id: string): Promise<void> {
|
||||
await apiClient.delete(`/api/tracks/${id}`)
|
||||
await getApiClient().delete(`/api/tracks/${id}`)
|
||||
}
|
||||
|
||||
// Search
|
||||
@@ -51,7 +52,7 @@ export async function searchTracks(
|
||||
query: string,
|
||||
filters?: { genre?: string; mood?: string; limit?: number }
|
||||
): Promise<SearchResponse> {
|
||||
const response = await apiClient.get('/api/search', {
|
||||
const response = await getApiClient().get('/api/search', {
|
||||
params: { q: query, ...filters },
|
||||
})
|
||||
return response.data
|
||||
@@ -59,7 +60,7 @@ export async function searchTracks(
|
||||
|
||||
// Similar
|
||||
export async function getSimilarTracks(id: string, limit: number = 10): Promise<SimilarTracksResponse> {
|
||||
const response = await apiClient.get(`/api/tracks/${id}/similar`, {
|
||||
const response = await getApiClient().get(`/api/tracks/${id}/similar`, {
|
||||
params: { limit },
|
||||
})
|
||||
return response.data
|
||||
@@ -67,30 +68,30 @@ export async function getSimilarTracks(id: string, limit: number = 10): Promise<
|
||||
|
||||
// Analysis
|
||||
export async function analyzeFolder(request: AnalyzeFolderRequest): Promise<{ job_id: string }> {
|
||||
const response = await apiClient.post('/api/analyze/folder', request)
|
||||
const response = await getApiClient().post('/api/analyze/folder', request)
|
||||
return response.data
|
||||
}
|
||||
|
||||
export async function getAnalyzeStatus(jobId: string): Promise<JobStatus> {
|
||||
const response = await apiClient.get(`/api/analyze/status/${jobId}`)
|
||||
const response = await getApiClient().get(`/api/analyze/status/${jobId}`)
|
||||
return response.data
|
||||
}
|
||||
|
||||
export async function deleteJob(jobId: string): Promise<void> {
|
||||
await apiClient.delete(`/api/analyze/job/${jobId}`)
|
||||
await getApiClient().delete(`/api/analyze/job/${jobId}`)
|
||||
}
|
||||
|
||||
// Audio
|
||||
export function getStreamUrl(trackId: string): string {
|
||||
return `${API_BASE_URL}/api/audio/stream/${trackId}`
|
||||
return `${getApiUrl()}/api/audio/stream/${trackId}`
|
||||
}
|
||||
|
||||
export function getDownloadUrl(trackId: string): string {
|
||||
return `${API_BASE_URL}/api/audio/download/${trackId}`
|
||||
return `${getApiUrl()}/api/audio/download/${trackId}`
|
||||
}
|
||||
|
||||
export async function getWaveform(trackId: string, numPeaks: number = 800): Promise<WaveformData> {
|
||||
const response = await apiClient.get(`/api/audio/waveform/${trackId}`, {
|
||||
const response = await getApiClient().get(`/api/audio/waveform/${trackId}`, {
|
||||
params: { num_peaks: numPeaks },
|
||||
})
|
||||
return response.data
|
||||
@@ -98,14 +99,12 @@ export async function getWaveform(trackId: string, numPeaks: number = 800): Prom
|
||||
|
||||
// Stats
|
||||
export async function getStats(): Promise<Stats> {
|
||||
const response = await apiClient.get('/api/stats')
|
||||
const response = await getApiClient().get('/api/stats')
|
||||
return response.data
|
||||
}
|
||||
|
||||
// Health
|
||||
export async function healthCheck(): Promise<{ status: string }> {
|
||||
const response = await apiClient.get('/health')
|
||||
const response = await getApiClient().get('/health')
|
||||
return response.data
|
||||
}
|
||||
|
||||
export default apiClient
|
||||
|
||||
Reference in New Issue
Block a user