Analyzing...';
try {
const formData = new FormData();
formData.append('file', selectedAudioFile);
const response = await fetch('/predict_audio', {
method: 'POST',
body: formData
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const result = await response.json();
displayAudioResults(result);
} catch (error) {
console.error('Error:', error);
showNotification('Error analyzing audio. Please try again.', 'error');
} finally {
// Reset loading state
analyzeAudioBtn.disabled = false;
analyzeAudioBtn.innerHTML = 'Analyze Audio';
}
}
// Display audio results
function displayAudioResults(result) {
audioPreviewSection.style.display = 'none';
resultsSection.style.display = 'block';
const { prediction, confidence, status } = result;
// Create result HTML
if (status === 'error') {
predictionResult.innerHTML = `
${prediction}
🔧 Audio analysis model is currently unavailable. Please try again later or contact support.
`;
} else {
predictionResult.innerHTML = `
${prediction}
${status === 'warning'
? '⚠️ Deepfake detected! This audio appears to be artificially generated.'
: '✅ This audio appears to be authentic and not a deepfake.'
}
`;
}
// Update confidence meter
confidenceFill.style.width = `${confidence}%`;
confidenceValue.textContent = `${confidence}%`;
// Scroll to results
resultsSection.scrollIntoView({ behavior: 'smooth' });
}
// Reset audio functionality
function resetAudioApp() {
selectedAudioFile = null;
audioUploadBox.style.display = 'block';
audioPreviewSection.style.display = 'none';
audioFileInput.value = '';
}
// Handle video file selection
function handleVideoFileSelect(event) {
const file = event.target.files[0];
if (!file) return;
// Validate file type
if (!file.type.startsWith('video/')) {
showNotification('Please select a valid video file.', 'error');
return;
}
// Validate file size (max 100MB for video)
if (file.size > 100 * 1024 * 1024) {
showNotification('File size must be less than 100MB.', 'error');
return;
}
selectedVideoFile = file;
displayVideoPreview(file);
}
// Display video preview
function displayVideoPreview(file) {
const reader = new FileReader();
reader.onload = (e) => {
previewVideo.src = e.target.result;
videoFileName.textContent = `Selected file: ${file.name}`;
videoUploadBox.style.display = 'none';
videoPreviewSection.style.display = 'block';
};
reader.readAsDataURL(file);
}
// Analyze video
async function analyzeVideo() {
if (!selectedVideoFile) return;
// Show loading state
analyzeVideoBtn.disabled = true;
analyzeVideoBtn.innerHTML = ' Analyzing...';
try {
const formData = new FormData();
formData.append('file', selectedVideoFile);
const response = await fetch('/predict_video', {
method: 'POST',
body: formData
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const result = await response.json();
displayVideoResults(result);
} catch (error) {
console.error('Error:', error);
showNotification('Error analyzing video. Please try again.', 'error');
} finally {
// Reset loading state
analyzeVideoBtn.disabled = false;
analyzeVideoBtn.innerHTML = 'Analyze Video';
}
}
// Display video results
function displayVideoResults(result) {
videoPreviewSection.style.display = 'none';
resultsSection.style.display = 'block';
const { prediction, confidence, status } = result;
// Create result HTML
predictionResult.innerHTML = `
${prediction}
${status === 'warning'
? '⚠️ Deepfake detected! This video appears to be artificially generated.'
: '✅ This video appears to be authentic and not a deepfake.'
}
`;
// Update confidence meter
confidenceFill.style.width = `${confidence}%`;
confidenceValue.textContent = `${confidence}%`;
// Scroll to results
resultsSection.scrollIntoView({ behavior: 'smooth' });
}
// Reset video functionality
function resetVideoApp() {
selectedVideoFile = null;
videoUploadBox.style.display = 'block';
videoPreviewSection.style.display = 'none';
videoFileInput.value = '';
}
// Handle file selection
function handleFileSelect(event) {
const file = event.target.files[0];
if (!file) return;
// Validate file type
if (!file.type.startsWith('image/')) {
showNotification('Please select a valid image file.', 'error');
return;
}
// Validate file size (max 10MB)
if (file.size > 10 * 1024 * 1024) {
showNotification('File size must be less than 10MB.', 'error');
return;
}
selectedFile = file;
displayPreview(file);
}
// Display image preview
function displayPreview(file) {
const reader = new FileReader();
reader.onload = (e) => {
previewImage.src = e.target.result;
uploadBox.style.display = 'none';
previewSection.style.display = 'block';
};
reader.readAsDataURL(file);
}
// Analyze image
async function analyzeImage() {
if (!selectedFile) return;
// Show loading state
analyzeBtn.disabled = true;
analyzeBtn.innerHTML = ' Analyzing...';
try {
const formData = new FormData();
formData.append('file', selectedFile);
const response = await fetch('/predict', {
method: 'POST',
body: formData
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const result = await response.json();
displayResults(result);
} catch (error) {
console.error('Error:', error);
showNotification('Error analyzing image. Please try again.', 'error');
} finally {
// Reset loading state
analyzeBtn.disabled = false;
analyzeBtn.innerHTML = 'Analyze Image';
}
}
// Display results
function displayResults(result) {
previewSection.style.display = 'none';
resultsSection.style.display = 'block';
const { prediction, confidence, status } = result;
// Create result HTML
predictionResult.innerHTML = `
${prediction}
${status === 'warning'
? '⚠️ Deepfake detected! This image appears to be artificially generated.'
: '✅ This image appears to be authentic and not a deepfake.'
}