Spaces:
Runtime error
Runtime error
Update interactive_report.html
Browse files245 unmodified lines246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285245 unmodified linesresultsSection.classList.add('hidden'); // Hide results when a new file is dropped});// Simulate prediction on button clickpredictButton.addEventListener('click', () => {if (uploadedFile) {// Simulate a delay for processingpredictButton.textContent = 'Analyzing...';predictButton.disabled = true;predictButton.classList.add('opacity-50', 'cursor-not-allowed');resultsSection.classList.add('hidden'); // Hide previous results during analysissetTimeout(() => {// Simulate a random prediction (True or False)const isTrue = Math.random() > 0.5;if (isTrue) {predictionText.textContent = 'The story is likely TRUE.';predictionResult.classList.remove('false');predictionResult.style.borderColor = '#10b981'; // Green borderpredictionResult.querySelector('svg').style.color = '#10b981'; // Green iconpredictionResult.style.backgroundColor = '#ecfdf5'; // Light green backgroundpredictionResult.style.color = '#065f46'; // Dark green text} else {predictionText.textContent = 'The story is likely FALSE (deceptive).';predictionResult.classList.add('false');predictionResult.style.borderColor = '#ef4444'; // Red borderpredictionResult.querySelector('svg').style.color = '#ef4444'; // Red iconpredictionResult.style.backgroundColor = '#fef2f2'; // Light red backgroundpredictionResult.style.color = '#991b1b'; // Dark red text}resultsSection.classList.remove('hidden'); // Show results sectionpredictButton.textContent = 'Analyze Truthfulness'; // Reset button textpredictButton.disabled = false;predictButton.classList.remove('opacity-50', 'cursor-not-allowed');}, 2000); // 2-second simulation delay} else {showMessage('Please upload an audio file first.', 'error');}245 unmodified lines246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309245 unmodified linesresultsSection.classList.add('hidden'); // Hide results when a new file is dropped});// Modified prediction on button click to simulate API callpredictButton.addEventListener('click', async () => {if (uploadedFile) {predictButton.textContent = 'Analyzing...';predictButton.disabled = true;predictButton.classList.add('opacity-50', 'cursor-not-allowed');resultsSection.classList.add('hidden'); // Hide previous results during analysishideMessage(); // Hide any previous messagestry {// Create FormData to send the audio fileconst formData = new FormData();formData.append('audio_file', uploadedFile);// Simulate fetching from a backend endpoint// In a real application, replace '/predict-truth' with your actual backend API endpoint// And the response would come from your Python Gradio app or a custom Flask/FastAPI endpointconst response = await new Promise(resolve => setTimeout(() => {// Simulate a random prediction result from the backendconst simulatedPrediction = Math.random() > 0.5 ? 'True Story' : 'Deceptive Story';resolve({ok: true,json: () => Promise.resolve({ prediction: simulatedPrediction })});}, 2000)); // Simulate 2-second network delayif (response.ok) {const data = await response.json();const prediction = data.prediction;if (prediction === 'True Story') {predictionText.textContent = 'The story is likely TRUE.';predictionResult.classList.remove('false');predictionResult.style.borderColor = '#10b981'; // Green borderpredictionResult.querySelector('svg').style.color = '#10b981'; // Green iconpredictionResult.style.backgroundColor = '#ecfdf5'; // Light green backgroundpredictionResult.style.color = '#065f46'; // Dark green text} else {predictionText.textContent = 'The story is likely FALSE (deceptive).';predictionResult.classList.add('false');predictionResult.style.borderColor = '#ef4444'; // Red borderpredictionResult.querySelector('svg').style.color = '#ef4444'; // Red iconpredictionResult.style.backgroundColor = '#fef2f2'; // Light red backgroundpredictionResult.style.color = '#991b1b'; // Dark red text}resultsSection.classList.remove('hidden'); // Show results section} else {showMessage('Prediction failed. Please try again.', 'error');console.error('Backend response not OK:', response.status, response.statusText);}} catch (error) {showMessage('An error occurred during analysis. Please try again.', 'error');console.error('Error during fetch:', error);} finally {predictButton.textContent = 'Analyze Truthfulness'; // Reset button textpredictButton.disabled = false;predictButton.classList.remove('opacity-50', 'cursor-not-allowed');}} else {showMessage('Please upload an audio file first.', 'error');}
interactive_report.html+46-22