From 0afb33cb89dbae61f6db991d640ea97ba8b2de9a Mon Sep 17 00:00:00 2001 From: SUFIYANJT Date: Mon, 17 Mar 2025 15:46:04 +0530 Subject: [PATCH 1/5] preview files in result page: frontend change only --- client/src/Pages/PreviewPage.tsx | 7 +- client/src/Pages/ProcessingPage.tsx | 8 +- client/src/Pages/ResultsPage.tsx | 174 +++++++--------------------- client/src/Pages/UploadPage.tsx | 2 +- 4 files changed, 52 insertions(+), 139 deletions(-) diff --git a/client/src/Pages/PreviewPage.tsx b/client/src/Pages/PreviewPage.tsx index 545c0b7..8c8bfe7 100644 --- a/client/src/Pages/PreviewPage.tsx +++ b/client/src/Pages/PreviewPage.tsx @@ -1,5 +1,6 @@ import React, { useState, useEffect, useRef } from 'react'; import { useNavigate } from 'react-router-dom'; +import { useLocation } from 'react-router-dom'; import { Typography, Container, @@ -20,7 +21,8 @@ function PreviewPage() { const [isPlaying, setIsPlaying] = useState(false); const [error, setError] = useState(false); const videoRef = useRef(null); - + const location = useLocation(); + const { audioClass } = location.state || {} // Supported video formats const supportedFormats = ['video/mp4', 'video/webm', 'video/ogg']; const isVideo = mediaFile && supportedFormats.includes(mediaFile.type); @@ -46,6 +48,7 @@ function PreviewPage() { return ( +

Audio Classification: {audioClass || "No data received"}

@@ -129,7 +132,7 @@ function PreviewPage() { diff --git a/client/src/Pages/ProcessingPage.tsx b/client/src/Pages/ProcessingPage.tsx index 0e9392b..19f9137 100644 --- a/client/src/Pages/ProcessingPage.tsx +++ b/client/src/Pages/ProcessingPage.tsx @@ -1,5 +1,5 @@ import { useState, useEffect } from "react"; -import { useNavigate } from "react-router-dom"; +import { useNavigate,useLocation } from "react-router-dom"; import { Typography, Container, Paper, Box, LinearProgress } from "@mui/material"; import StepperComponent from "../components/StepperComponent"; import { useMediaContext } from "../contexts/MediaContext"; @@ -35,6 +35,8 @@ function ProcessingPage() { console.error(`Error in step: ${url}`, error); } }; + const location = useLocation(); + const { audioClass } = location.state || {}; useEffect(() => { if (!mediaFile) { @@ -59,7 +61,9 @@ function ProcessingPage() { useEffect(() => { if (progress === 100) { - navigate("/results"); + + navigate('/results', { state: { audioClass}}) + } }, [progress]); diff --git a/client/src/Pages/ResultsPage.tsx b/client/src/Pages/ResultsPage.tsx index 46b4fb1..5d3b195 100644 --- a/client/src/Pages/ResultsPage.tsx +++ b/client/src/Pages/ResultsPage.tsx @@ -1,5 +1,5 @@ import React, { useState, useEffect, useRef } from 'react'; -import { useNavigate } from 'react-router-dom'; +import { useNavigate, useLocation } from 'react-router-dom'; import axios from 'axios'; import { Typography, @@ -23,45 +23,12 @@ import { useMediaContext } from '../contexts/MediaContext'; function ResultsPage() { const navigate = useNavigate(); const theme = useTheme(); - const { mediaFile, clearMedia,response } = useMediaContext(); + const { mediaFile, clearMedia, response } = useMediaContext(); const [isPlaying, setIsPlaying] = useState(false); - const videoRef = useRef(null); - - const processDownload = async() => { - try { - console.log('download started..') - const res = await axios.get("http://127.0.0.1:8000/api/download", { - params: { file_uuid: response.file_uuid }, // Attach file_uuid as a query param - responseType: "blob", // Treat response as a file - }); - - if (res.status === 200) { - const blob = new Blob([res.data]); - const url = window.URL.createObjectURL(blob); - - // Extract filename from headers or use default - const contentDisposition = res.headers["content-disposition"]; - const filename = contentDisposition - ? contentDisposition.split("filename=")[1] - : "downloaded_file"; - - // Auto-download the file (no user interaction needed) - const link = document.createElement("a"); - link.href = url; - link.setAttribute("download", filename); - document.body.appendChild(link); - link.click(); - - // Cleanup - document.body.removeChild(link); - window.URL.revokeObjectURL(url); - } else { - console.error("Download failed, server responded with:", res); - } - } catch (error) { - console.error("Download error:", error); - } - }; + const audioRefs = [useRef(null), useRef(null), useRef(null),useRef(null)]; + const location = useLocation(); + const { audioClass } = location.state || {}; + const isVideo = mediaFile?.type.includes('video'); useEffect(() => { if (!mediaFile) { @@ -69,26 +36,19 @@ function ResultsPage() { } }, [mediaFile, navigate]); - const togglePlay = () => { - if (videoRef.current) { + const togglePlay = (index) => { + if (audioRefs[index].current) { if (isPlaying) { - videoRef.current.pause(); + audioRefs[index].current.pause(); } else { - videoRef.current.play(); + audioRefs[index].current.play(); } setIsPlaying(!isPlaying); } }; - const handleProcessAnother = () => { - clearMedia(); - navigate('/upload'); - }; - if (!mediaFile) return ; - const isVideo = mediaFile.type.includes('video'); - return ( @@ -107,50 +67,38 @@ function ResultsPage() { {isVideo ? ( - - + @@ -132,12 +112,13 @@ function PreviewPage() { +
); } diff --git a/client/src/Pages/ProcessingPage.tsx b/client/src/Pages/ProcessingPage.tsx index 19f9137..ed66a47 100644 --- a/client/src/Pages/ProcessingPage.tsx +++ b/client/src/Pages/ProcessingPage.tsx @@ -1,5 +1,5 @@ import { useState, useEffect } from "react"; -import { useNavigate,useLocation } from "react-router-dom"; +import { useNavigate} from "react-router-dom"; import { Typography, Container, Paper, Box, LinearProgress } from "@mui/material"; import StepperComponent from "../components/StepperComponent"; import { useMediaContext } from "../contexts/MediaContext"; @@ -17,7 +17,10 @@ function ProcessingPage() { try { const formData = new FormData(); formData.append("file_uuid", response.file_uuid); - Object.entries(extraData).forEach(([key, value]) => formData.append(key, value)); + Object.entries(extraData).forEach(([key, value]) => + formData.append(key, String(value)) + ); + setStatusText(status); const startTime = Date.now(); @@ -35,8 +38,6 @@ function ProcessingPage() { console.error(`Error in step: ${url}`, error); } }; - const location = useLocation(); - const { audioClass } = location.state || {}; useEffect(() => { if (!mediaFile) { @@ -51,7 +52,7 @@ function ProcessingPage() { if (response.audio_class === "Music") { processStep("http://127.0.0.1:8000/api/resample", () => { processStep("http://127.0.0.1:8000/api/separate", () => setProgress(100), 100, "Separating sources into vocals, bass, drums and other..."); - }, 75, "Resampling audio to 44100Hz...", { sr: response.sr?.toString() || "44100" }); + }, 75, "Resampling audio to 44100Hz...", { sr: "44100" }); } else { processStep("http://127.0.0.1:8000/api/noisereduce", () => setProgress(100), 100, "Reducing background noise from the audio..."); } @@ -62,7 +63,7 @@ function ProcessingPage() { useEffect(() => { if (progress === 100) { - navigate('/results', { state: { audioClass}}) + navigate('/results') } }, [progress]); diff --git a/client/src/Pages/ResultsPage.tsx b/client/src/Pages/ResultsPage.tsx index 5d3b195..031328f 100644 --- a/client/src/Pages/ResultsPage.tsx +++ b/client/src/Pages/ResultsPage.tsx @@ -1,6 +1,6 @@ -import React, { useState, useEffect, useRef } from 'react'; -import { useNavigate, useLocation } from 'react-router-dom'; -import axios from 'axios'; +import { useEffect, useRef } from 'react'; +import { useNavigate } from 'react-router-dom'; +//import axios from 'axios'; import { Typography, Container, @@ -11,7 +11,6 @@ import { CardContent, Grid, LinearProgress, - useTheme } from '@mui/material'; import { Check as CheckIcon, @@ -22,12 +21,10 @@ import { useMediaContext } from '../contexts/MediaContext'; function ResultsPage() { const navigate = useNavigate(); - const theme = useTheme(); - const { mediaFile, clearMedia, response } = useMediaContext(); - const [isPlaying, setIsPlaying] = useState(false); + const { mediaFile, response } = useMediaContext(); +// const [isPlaying, setIsPlaying] = useState(false); const audioRefs = [useRef(null), useRef(null), useRef(null),useRef(null)]; - const location = useLocation(); - const { audioClass } = location.state || {}; + const audioClass = response.audio_class const isVideo = mediaFile?.type.includes('video'); useEffect(() => { @@ -36,16 +33,16 @@ function ResultsPage() { } }, [mediaFile, navigate]); - const togglePlay = (index) => { - if (audioRefs[index].current) { - if (isPlaying) { - audioRefs[index].current.pause(); - } else { - audioRefs[index].current.play(); - } - setIsPlaying(!isPlaying); - } - }; +// const togglePlay = (index) => { +// if (audioRefs[index].current) { +// if (isPlaying) { +// audioRefs[index].current.pause(); +// } else { +// audioRefs[index].current.play(); +// } +// setIsPlaying(!isPlaying); +// } +// }; if (!mediaFile) return ; diff --git a/client/src/Pages/UploadPage.tsx b/client/src/Pages/UploadPage.tsx index 84194d2..a6fbe78 100644 --- a/client/src/Pages/UploadPage.tsx +++ b/client/src/Pages/UploadPage.tsx @@ -20,7 +20,7 @@ import { useMediaContext } from "../contexts/MediaContext"; function UploadPage() { const navigate = useNavigate(); const theme = useTheme(); - const { setMediaFile, setResponse, response } = useMediaContext(); // ✅ Correct function name + const { setMediaFile, setResponse, response } = useMediaContext(); const [file, setFile] = useState(null); const [isDragging, setIsDragging] = useState(false); const [fileError, setFileError] = useState(""); @@ -70,8 +70,8 @@ function UploadPage() { name: file.name, url: URL.createObjectURL(file), type: file.type, - }); // ✅ Corrected function call - navigate('/preview', { state: { audioClass: response.audio_class } }); + }); // + navigate('/preview'); } else { setFileError("Please upload a file to continue."); } @@ -84,7 +84,7 @@ function UploadPage() { } const formData = new FormData(); - formData.append("file", file); // ✅ No more errors because we checked `file` is not null. + formData.append("file", file); try { const res = await axios.post<{ @@ -123,9 +123,6 @@ function UploadPage() { Upload Your Media - - Drag and drop your audio or video file, or click to browse - - {file ? file.name : "Drop your file here or click to browse"} + {file ? file.name : "Drop your file here or click to browse files"} {file && ( diff --git a/client/src/components/StepperComponent.tsx b/client/src/components/StepperComponent.tsx index 67a36ba..4ebdb9a 100644 --- a/client/src/components/StepperComponent.tsx +++ b/client/src/components/StepperComponent.tsx @@ -1,9 +1,12 @@ -import React from 'react'; import { Box, Stepper, Step, StepLabel } from '@mui/material'; const steps = ['Upload', 'Preview', 'Process', ,'Results']; -function StepperComponent({ activeStep }) { +type StepperComponentProps = { + activeStep: number; +}; + +function StepperComponent({ activeStep }: StepperComponentProps) { return ( diff --git a/client/src/main.tsx b/client/src/main.tsx index 28e7b4a..d69ed7a 100644 --- a/client/src/main.tsx +++ b/client/src/main.tsx @@ -5,6 +5,6 @@ import '@fontsource/roboto/400.css'; import '@fontsource/roboto/500.css'; import '@fontsource/roboto/700.css'; -ReactDOM.createRoot(document.getElementById('root')).render( +ReactDOM.createRoot(document.getElementById('root')!).render( ); \ No newline at end of file From 40b71c3fdb60bc3313871d12dce26a41438aa8f1 Mon Sep 17 00:00:00 2001 From: Joel Mathew Thomas <90510078+joelmathewthomas@users.noreply.github.com> Date: Tue, 18 Mar 2025 01:23:17 +0530 Subject: [PATCH 3/5] query progress for some pages --- client/src/Pages/PreviewPage.tsx | 7 ++++++- client/src/Pages/ProcessingPage.tsx | 6 ++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/client/src/Pages/PreviewPage.tsx b/client/src/Pages/PreviewPage.tsx index 2373699..0ea3898 100644 --- a/client/src/Pages/PreviewPage.tsx +++ b/client/src/Pages/PreviewPage.tsx @@ -118,7 +118,12 @@ function PreviewPage() { - + ); } diff --git a/client/src/Pages/ProcessingPage.tsx b/client/src/Pages/ProcessingPage.tsx index ed66a47..8da474c 100644 --- a/client/src/Pages/ProcessingPage.tsx +++ b/client/src/Pages/ProcessingPage.tsx @@ -97,6 +97,12 @@ function ProcessingPage() { + ); } From ba18a7a27f5f4271728f7c8f35f404daae6c0c01 Mon Sep 17 00:00:00 2001 From: Joel Mathew Thomas <90510078+joelmathewthomas@users.noreply.github.com> Date: Tue, 18 Mar 2025 01:53:53 +0530 Subject: [PATCH 4/5] setup vite proxy for development --- client/src/Pages/ProcessingPage.tsx | 10 +++++----- client/src/Pages/UploadPage.tsx | 2 +- client/vite.config.ts | 8 ++++++++ 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/client/src/Pages/ProcessingPage.tsx b/client/src/Pages/ProcessingPage.tsx index 8da474c..cc319de 100644 --- a/client/src/Pages/ProcessingPage.tsx +++ b/client/src/Pages/ProcessingPage.tsx @@ -47,14 +47,14 @@ function ProcessingPage() { console.log("Starting processing..."); - processStep("http://127.0.0.1:8000/api/normalize", () => { - processStep("http://127.0.0.1:8000/api/trim", () => { + processStep("/api/normalize", () => { + processStep("/api/trim", () => { if (response.audio_class === "Music") { - processStep("http://127.0.0.1:8000/api/resample", () => { - processStep("http://127.0.0.1:8000/api/separate", () => setProgress(100), 100, "Separating sources into vocals, bass, drums and other..."); + processStep("/api/resample", () => { + processStep("/api/separate", () => setProgress(100), 100, "Separating sources into vocals, bass, drums and other..."); }, 75, "Resampling audio to 44100Hz...", { sr: "44100" }); } else { - processStep("http://127.0.0.1:8000/api/noisereduce", () => setProgress(100), 100, "Reducing background noise from the audio..."); + processStep("/api/noisereduce", () => setProgress(100), 100, "Reducing background noise from the audio..."); } }, 50, "Trimming silent parts from the audio..."); }, 25, "Normalizing audio frequency..."); diff --git a/client/src/Pages/UploadPage.tsx b/client/src/Pages/UploadPage.tsx index a6fbe78..7359519 100644 --- a/client/src/Pages/UploadPage.tsx +++ b/client/src/Pages/UploadPage.tsx @@ -91,7 +91,7 @@ function UploadPage() { file_uuid: string; sr: number; audio_class: string; - }>("http://127.0.0.1:8000/api/upload", formData, { + }>("/api/upload", formData, { headers: { "Content-Type": "multipart/form-data", }, diff --git a/client/vite.config.ts b/client/vite.config.ts index 8b0f57b..12f020c 100644 --- a/client/vite.config.ts +++ b/client/vite.config.ts @@ -4,4 +4,12 @@ import react from '@vitejs/plugin-react' // https://vite.dev/config/ export default defineConfig({ plugins: [react()], + server: { + proxy: { + '/api': { + target: 'http://localhost:8000', + changeOrigin: true, + }, + }, + }, }) From d9fd9f65916e68e8c091a5d10ea4b66067fadf90 Mon Sep 17 00:00:00 2001 From: Joel Mathew Thomas <90510078+joelmathewthomas@users.noreply.github.com> Date: Tue, 18 Mar 2025 02:02:36 +0530 Subject: [PATCH 5/5] code refactor --- client/src/Pages/PreviewPage.tsx | 2 +- client/src/Pages/ProcessingPage.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/client/src/Pages/PreviewPage.tsx b/client/src/Pages/PreviewPage.tsx index 0ea3898..b8d976b 100644 --- a/client/src/Pages/PreviewPage.tsx +++ b/client/src/Pages/PreviewPage.tsx @@ -32,7 +32,6 @@ function PreviewPage() { return ( -

Audio Classification: {audioClass || "No data received"}

@@ -92,6 +91,7 @@ function PreviewPage() { controls /> +

Audio Classification: {audioClass || "No data received"}

) : ( diff --git a/client/src/Pages/ProcessingPage.tsx b/client/src/Pages/ProcessingPage.tsx index cc319de..5ee8734 100644 --- a/client/src/Pages/ProcessingPage.tsx +++ b/client/src/Pages/ProcessingPage.tsx @@ -51,7 +51,7 @@ function ProcessingPage() { processStep("/api/trim", () => { if (response.audio_class === "Music") { processStep("/api/resample", () => { - processStep("/api/separate", () => setProgress(100), 100, "Separating sources into vocals, bass, drums and other..."); + processStep("/api/separate", () => setProgress(100), 100, "Separating music into vocals, bass, drums and other..."); }, 75, "Resampling audio to 44100Hz...", { sr: "44100" }); } else { processStep("/api/noisereduce", () => setProgress(100), 100, "Reducing background noise from the audio...");