File size: 28,251 Bytes
d8240b4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
import React, { useState, useEffect } from 'react';
import { 
  Container, Box, Button, Typography, CircularProgress, 
  Paper, Grid, Card, CardContent, LinearProgress, 
  FormControl, IconButton, Alert, Snackbar, useMediaQuery
} from '@mui/material';
import { createTheme, ThemeProvider, styled, alpha } from '@mui/material/styles';
import MicIcon from '@mui/icons-material/Mic';
import StopIcon from '@mui/icons-material/Stop';
import UploadFileIcon from '@mui/icons-material/UploadFile';
import CloudUploadIcon from '@mui/icons-material/CloudUpload';
import AudiotrackIcon from '@mui/icons-material/Audiotrack';
import VolumeUpIcon from '@mui/icons-material/VolumeUp';
import SecurityIcon from '@mui/icons-material/Security';
import { BarChart, Bar, XAxis, YAxis, CartesianGrid, Tooltip, ResponsiveContainer } from 'recharts';
import { motion } from 'framer-motion';

// API endpoint
const API_URL = process.env.REACT_APP_API_URL || 'http://localhost:8000';

// Custom theme
const theme = createTheme({
  palette: {
    primary: {
      main: '#3a86ff',
      light: '#83b9ff',
      dark: '#0056cb',
    },
    secondary: {
      main: '#ff006e',
      light: '#ff5b9e',
      dark: '#c50052',
    },
    success: {
      main: '#38b000',
      light: '#70e000',
      dark: '#008000',
      contrastText: '#ffffff',
    },
    error: {
      main: '#d00000',
      light: '#ff5c4d',
      dark: '#9d0208',
      contrastText: '#ffffff',
    },
    background: {
      default: '#f8f9fa',
      paper: '#ffffff',
    },
  },
  typography: {
    fontFamily: "'Poppins', 'Roboto', 'Helvetica', 'Arial', sans-serif",
    h3: {
      fontWeight: 700,
      letterSpacing: '-0.5px',
    },
    h6: {
      fontWeight: 600,
    },
    subtitle1: {
      fontWeight: 500,
    }
  },
  shape: {
    borderRadius: 12,
  },
  components: {
    MuiButton: {
      styleOverrides: {
        root: {
          textTransform: 'none',
          borderRadius: 8,
          padding: '10px 16px',
          boxShadow: 'none',
          fontWeight: 600,
        },
        containedPrimary: {
          '&:hover': {
            boxShadow: '0 6px 20px rgba(58, 134, 255, 0.3)',
          },
        },
      },
    },
    MuiPaper: {
      styleOverrides: {
        root: {
          boxShadow: '0 8px 40px rgba(0, 0, 0, 0.08)',
        },
      },
    },
    MuiCard: {
      styleOverrides: {
        root: {
          overflow: 'visible',
        },
      },
    },
  },
});

// Styled components
const VisuallyHiddenInput = styled('input')({
  clip: 'rect(0 0 0 0)',
  clipPath: 'inset(50%)',
  height: 1,
  overflow: 'hidden',
  position: 'absolute',
  bottom: 0,
  left: 0,
  whiteSpace: 'nowrap',
  width: 1,
});

const StyledCard = styled(Card)(({ theme }) => ({
  height: '100%',
  display: 'flex',
  flexDirection: 'column',
  transition: 'transform 0.3s ease-in-out, box-shadow 0.3s ease-in-out',
  '&:hover': {
    transform: 'translateY(-5px)',
    boxShadow: '0 12px 50px rgba(0, 0, 0, 0.1)',
  },
}));

const ResultCard = styled(Card)(({ theme, prediction }) => ({
  backgroundColor: prediction === 'Real' 
    ? alpha(theme.palette.success.light, 0.3)
    : prediction === 'Deepfake' 
      ? alpha(theme.palette.error.light, 0.3)
      : theme.palette.grey[100],
  borderLeft: `8px solid ${
    prediction === 'Real' 
      ? theme.palette.success.main 
      : prediction === 'Deepfake' 
        ? theme.palette.error.main 
        : theme.palette.grey[300]
  }`,
  backdropFilter: 'blur(10px)',
  transition: 'all 0.3s ease',
}));

const GradientHeader = styled(Box)(({ theme }) => ({
  background: `linear-gradient(135deg, ${theme.palette.primary.dark} 0%, ${theme.palette.primary.main} 100%)`,
  color: '#ffffff',
  padding: theme.spacing(6, 2, 8),
  borderRadius: '0 0 24px 24px',
  marginBottom: -theme.spacing(6),
}));

const GlassCard = styled(Card)(({ theme }) => ({
  backgroundColor: alpha(theme.palette.background.paper, 0.8),
  backdropFilter: 'blur(10px)',
  border: `1px solid ${alpha('#fff', 0.2)}`,
}));

const RecordButton = styled(Button)(({ theme, isrecording }) => ({
  borderRadius: '50%',
  minWidth: '64px',
  width: '64px',
  height: '64px',
  padding: 0,
  boxShadow: isrecording === 'true' 
    ? `0 0 0 4px ${alpha(theme.palette.error.main, 0.3)}, 0 0 0 8px ${alpha(theme.palette.error.main, 0.15)}`
    : `0 0 0 4px ${alpha(theme.palette.primary.main, 0.3)}, 0 0 0 8px ${alpha(theme.palette.primary.main, 0.15)}`,
  animation: isrecording === 'true' ? 'pulse 1.5s infinite' : 'none',
  '@keyframes pulse': {
    '0%': {
      boxShadow: `0 0 0 0 ${alpha(theme.palette.error.main, 0.7)}`
    },
    '70%': {
      boxShadow: `0 0 0 15px ${alpha(theme.palette.error.main, 0)}`
    },
    '100%': {
      boxShadow: `0 0 0 0 ${alpha(theme.palette.error.main, 0)}`
    }
  }
}));

const AudioWaveAnimation = styled(Box)(({ theme, isplaying }) => ({
  display: 'flex',
  alignItems: 'center',
  justifyContent: 'center',
  gap: '3px',
  height: '40px',
  opacity: isplaying === 'true' ? 1 : 0.3,
  transition: 'opacity 0.3s ease',
  '& .bar': {
    width: '3px',
    backgroundColor: theme.palette.primary.main,
    borderRadius: '3px',
    animation: isplaying === 'true' ? 'soundwave 1s infinite' : 'none',
  },
  '@keyframes soundwave': {
    '0%': { height: '10%' },
    '50%': { height: '100%' },
    '100%': { height: '10%' }
  }
}));

function App() {
  const [file, setFile] = useState(null);
  const [audioUrl, setAudioUrl] = useState(null);
  const [isRecording, setIsRecording] = useState(false);
  const [isPlaying, setIsPlaying] = useState(false);
  const [recorder, setRecorder] = useState(null);
  const [isLoading, setIsLoading] = useState(false);
  const [result, setResult] = useState(null);
  const [error, setError] = useState(null);
  const [modelInfo, setModelInfo] = useState(null);
  const [openSnackbar, setOpenSnackbar] = useState(false);
  
  const isMobile = useMediaQuery(theme.breakpoints.down('sm'));

  // Create audio wave bars for animation
  const audioBars = Array.from({ length: 10 }, (_, i) => {
    const randomHeight = Math.floor(Math.random() * 100) + 1;
    const randomDelay = Math.random();
    return (
      <Box 
        key={i} 
        className="bar" 
        sx={{ 
          height: `${randomHeight}%`,
          animationDelay: `${randomDelay}s` 
        }} 
      />
    );
  });

  // Audio player logic
  const audioRef = React.useRef(null);
  
  const handlePlayPause = () => {
    if (audioRef.current) {
      if (isPlaying) {
        audioRef.current.pause();
      } else {
        audioRef.current.play();
      }
      setIsPlaying(!isPlaying);
    }
  };

  // Fetch model info on component mount
  useEffect(() => {
    fetch(`${API_URL}/model-info/`)
      .then(response => response.json())
      .then(data => setModelInfo(data))
      .catch(err => console.error("Error fetching model info:", err));
  }, []);

  // Handle audio events
  useEffect(() => {
    const audioElement = audioRef.current;
    if (audioElement) {
      const handleEnded = () => setIsPlaying(false);
      audioElement.addEventListener('ended', handleEnded);
      return () => {
        audioElement.removeEventListener('ended', handleEnded);
      };
    }
  }, [audioUrl]);

  // Handle file selection
  const handleFileChange = (event) => {
    const selectedFile = event.target.files[0];
    if (selectedFile) {
      setFile(selectedFile);
      setAudioUrl(URL.createObjectURL(selectedFile));
      setIsPlaying(false);
      setResult(null); // Clear previous results
    }
  };

  // Start audio recording
  const startRecording = async () => {
    try {
      const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
      const mediaRecorder = new MediaRecorder(stream);
      const audioChunks = [];

      mediaRecorder.addEventListener("dataavailable", event => {
        audioChunks.push(event.data);
      });

      mediaRecorder.addEventListener("stop", () => {
        const audioBlob = new Blob(audioChunks, { type: 'audio/wav' });
        const audioFile = new File([audioBlob], "recorded-audio.wav", { type: 'audio/wav' });
        setFile(audioFile);
        setAudioUrl(URL.createObjectURL(audioBlob));
        setIsPlaying(false);
        setResult(null); // Clear previous results
      });

      mediaRecorder.start();
      setIsRecording(true);
      setRecorder(mediaRecorder);
    } catch (err) {
      setError("Could not access microphone. Please check permissions.");
      setOpenSnackbar(true);
      console.error("Error accessing microphone:", err);
    }
  };

  // Stop audio recording
  const stopRecording = () => {
    if (recorder && recorder.state !== "inactive") {
      recorder.stop();
      setIsRecording(false);
    }
  };

  // Submit audio for analysis
  const handleSubmit = async () => {
    if (!file) {
      setError("Please upload or record an audio file first.");
      setOpenSnackbar(true);
      return;
    }

    setIsLoading(true);
    setError(null);

    const formData = new FormData();
    formData.append('file', file);

    try {
      const response = await fetch(`${API_URL}/detect/`, {
        method: 'POST',
        body: formData,
      });

      if (!response.ok) {
        throw new Error(`Server responded with status: ${response.status}`);
      }

      const data = await response.json();
      setResult(data);
    } catch (err) {
      setError(`Error analyzing audio: ${err.message}`);
      setOpenSnackbar(true);
      console.error("Error analyzing audio:", err);
    } finally {
      setIsLoading(false);
    }
  };

  // Reset everything
  const handleReset = () => {
    setFile(null);
    setAudioUrl(null);
    setResult(null);
    setError(null);
    setIsPlaying(false);
  };

  // Format chart data
  const getChartData = () => {
    if (!result || !result.probabilities) return [];
    
    return Object.entries(result.probabilities).map(([name, value]) => ({
      name,
      value: parseFloat((value * 100).toFixed(2))
    }));
  };

  // Handle snackbar close
  const handleCloseSnackbar = (event, reason) => {
    if (reason === 'clickaway') {
      return;
    }
    setOpenSnackbar(false);
  };

  // Animation variants
  const fadeIn = {
    hidden: { opacity: 0, y: 20 },
    visible: { opacity: 1, y: 0, transition: { duration: 0.6 } }
  };

  return (
    <ThemeProvider theme={theme}>
      <Box sx={{ 
        backgroundColor: 'background.default', 
        minHeight: '100vh',
        paddingBottom: 4
      }}>
        <GradientHeader>
          <Container maxWidth="md">
            <motion.div
              initial={{ opacity: 0, y: -20 }}
              animate={{ opacity: 1, y: 0 }}
              transition={{ duration: 0.7 }}
            >
              <Box sx={{ textAlign: 'center', position: 'relative' }}>
                <Typography variant="h3" component="h1" gutterBottom>
                  Deepfake Voice Detector
                </Typography>
                
                <Typography variant="subtitle1" sx={{ maxWidth: '700px', mx: 'auto', opacity: 0.9 }}>
                  Upload or record audio to instantly verify if it's authentic or AI-generated
                </Typography>
              </Box>
            </motion.div>
          </Container>
        </GradientHeader>
        
        <Container maxWidth="md">
          <Box sx={{ mt: 2, mb: 2 }}>
            {modelInfo && (
              <motion.div
                initial={{ opacity: 0 }}
                animate={{ opacity: 1 }}
                transition={{ delay: 0.3, duration: 0.5 }}
              >
                <Box sx={{ 
                  display: 'flex', 
                  alignItems: 'center',
                  justifyContent: 'center',
                  gap: 1
                }}>
                  <SecurityIcon fontSize="small" sx={{ color: 'text.secondary' }} />
                  <Typography variant="body2" color="text.secondary">
                    Using model: {modelInfo.model_id} | Accuracy: {(modelInfo.performance.accuracy * 100).toFixed(2)}%
                  </Typography>
                </Box>
              </motion.div>
            )}
          </Box>

          <motion.div
            variants={fadeIn}
            initial="hidden"
            animate="visible"
          >
            <GlassCard elevation={0} sx={{ mb: 4, overflow: 'visible' }}>
              <CardContent sx={{ p: { xs: 2, sm: 3 } }}>
                <Grid container spacing={3}>
                  <Grid item xs={12} md={6}>
                    <StyledCard variant="outlined">
                      <CardContent sx={{ 
                        display: 'flex', 
                        flexDirection: 'column', 
                        alignItems: 'center', 
                        height: '100%',
                        p: { xs: 2, sm: 3 }
                      }}>
                        <Typography variant="h6" component="div" gutterBottom sx={{ mb: 3 }}>
                          Upload Audio
                        </Typography>
                        
                        <Button
                          component="label"
                          variant="contained"
                          startIcon={<UploadFileIcon />}
                          sx={{ 
                            width: '100%',
                            py: 1.5,
                            mb: 3,
                            backgroundColor: theme.palette.primary.light,
                            '&:hover': {
                              backgroundColor: theme.palette.primary.main,
                            }
                          }}
                        >
                          Choose Audio File
                          <VisuallyHiddenInput type="file" accept="audio/*" onChange={handleFileChange} />
                        </Button>
                        
                        <Typography variant="body2" color="text.secondary" gutterBottom>
                          Or record audio directly
                        </Typography>
                        
                        <Box sx={{ 
                          display: 'flex', 
                          flexDirection: 'column',
                          alignItems: 'center', 
                          mt: 2 
                        }}>
                          {!isRecording ? (
                            <RecordButton
                              variant="contained"
                              color="primary"
                              onClick={startRecording}
                              isrecording="false"
                            >
                              <MicIcon />
                            </RecordButton>
                          ) : (
                            <RecordButton
                              variant="contained"
                              color="error"
                              onClick={stopRecording}
                              isrecording="true"
                            >
                              <StopIcon />
                            </RecordButton>
                          )}
                          <Typography variant="body2" sx={{ mt: 1, color: isRecording ? 'error.main' : 'text.secondary' }}>
                            {isRecording ? 'Recording...' : 'Tap to record'}
                          </Typography>
                        </Box>
                      </CardContent>
                    </StyledCard>
                  </Grid>
                  
                  <Grid item xs={12} md={6}>
                    <StyledCard variant="outlined">
                      <CardContent sx={{ 
                        display: 'flex', 
                        flexDirection: 'column',
                        justifyContent: audioUrl ? 'space-between' : 'center',
                        height: '100%',
                        p: { xs: 2, sm: 3 } 
                      }}>
                        {audioUrl ? (
                          <>
                            <Box sx={{ textAlign: 'center' }}>
                              <Typography variant="h6" component="div" gutterBottom>
                                <AudiotrackIcon sx={{ verticalAlign: 'middle', mr: 1 }} />
                                Audio Preview
                              </Typography>
                            </Box>
                            
                            <Box sx={{ 
                              my: 2, 
                              display: 'flex',
                              flexDirection: 'column',
                              alignItems: 'center'
                            }}>
                              <audio 
                                ref={audioRef}
                                src={audioUrl} 
                                style={{ display: 'none' }}
                                onPlay={() => setIsPlaying(true)}
                                onPause={() => setIsPlaying(false)}
                              />
                              
                              <AudioWaveAnimation isplaying={isPlaying ? 'true' : 'false'}>
                                {audioBars}
                              </AudioWaveAnimation>
                              
                              <Box sx={{ mt: 2 }}>
                                <IconButton 
                                  color="primary" 
                                  onClick={handlePlayPause}
                                  size="large"
                                  sx={{ 
                                    backgroundColor: alpha(theme.palette.primary.main, 0.1),
                                    '&:hover': {
                                      backgroundColor: alpha(theme.palette.primary.main, 0.2),
                                    }
                                  }}
                                >
                                  <VolumeUpIcon />
                                </IconButton>
                              </Box>
                              
                              <Typography variant="body2" color="text.secondary" sx={{ mt: 1 }}>
                                {file ? file.name : "Audio loaded"}
                              </Typography>
                            </Box>
                          </>
                        ) : (
                          <Box sx={{ 
                            p: 3, 
                            textAlign: 'center',
                            display: 'flex',
                            flexDirection: 'column',
                            alignItems: 'center',
                            justifyContent: 'center',
                            height: '100%'
                          }}>
                            <CloudUploadIcon sx={{ 
                              fontSize: 60, 
                              color: alpha(theme.palette.text.secondary, 0.5),
                              mb: 2
                            }} />
                            <Typography variant="body1" color="text.secondary">
                              No audio selected
                            </Typography>
                            <Typography variant="body2" color="text.secondary" sx={{ mt: 1, opacity: 0.7 }}>
                              Upload or record to analyze
                            </Typography>
                          </Box>
                        )}
                      </CardContent>
                    </StyledCard>
                  </Grid>
                </Grid>
              </CardContent>
              
              <Box sx={{ 
                px: { xs: 2, sm: 3 }, 
                pb: { xs: 2, sm: 3 },
                textAlign: 'center' 
              }}>
                <motion.div
                  whileHover={{ scale: 1.03 }}
                  whileTap={{ scale: 0.97 }}
                >
                  <Button
                    variant="contained"
                    color="primary"
                    size="large"
                    disabled={!file || isLoading}
                    onClick={handleSubmit}
                    sx={{ 
                      px: 4, 
                      py: 1.2,
                      fontSize: '1.1rem',
                      fontWeight: 600,
                      mx: 1,
                      minWidth: { xs: '120px', sm: '160px' }
                    }}
                  >
                    {isLoading ? <CircularProgress size={24} sx={{ mr: 1 }} /> : "Analyze Audio"}
                  </Button>
                </motion.div>
                
                <Button
                  variant="outlined"
                  color="secondary"
                  size="large"
                  onClick={handleReset}
                  sx={{ 
                    mx: 1, 
                    mt: { xs: 1, sm: 0 },
                    minWidth: { xs: '120px', sm: '120px' }
                  }}
                  disabled={isLoading || (!file && !audioUrl)}
                >
                  Reset
                </Button>
              </Box>
            </GlassCard>
          </motion.div>
          
          {isLoading && (
            <motion.div
              initial={{ opacity: 0 }}
              animate={{ opacity: 1 }}
              transition={{ duration: 0.3 }}
            >
              <Box sx={{ width: '100%', my: 4 }}>
                <Typography variant="body2" color="text.secondary" gutterBottom align="center">
                  Analyzing audio...
                </Typography>
                <LinearProgress 
                  sx={{ 
                    height: 8, 
                    borderRadius: 4,
                    backgroundColor: alpha(theme.palette.primary.main, 0.15)
                  }} 
                />
              </Box>
            </motion.div>
          )}
          
          {result && (
            <motion.div
              initial={{ opacity: 0, y: 30 }}
              animate={{ opacity: 1, y: 0 }}
              transition={{ duration: 0.5 }}
            >
              <Box sx={{ my: 4 }}>
                <ResultCard 
                  elevation={2} 
                  prediction={result.prediction} 
                  sx={{ mb: 3 }}
                >
                  <CardContent sx={{ p: { xs: 2, sm: 3 } }}>
                    <Box sx={{ 
                      display: 'flex', 
                      flexDirection: { xs: 'column', sm: 'row' },
                      alignItems: { xs: 'flex-start', sm: 'center' },
                      justifyContent: 'space-between'
                    }}>
                      <Box>
                        <Typography 
                          variant="h5" 
                          component="div" 
                          gutterBottom 
                          sx={{ 
                            fontWeight: 700,
                            color: result.prediction === 'Real' 
                              ? 'success.dark' 
                              : 'error.dark'
                          }}
                        >
                          {result.prediction === 'Real' ? '✓ Authentic Voice' : '⚠ Deepfake Detected'}
                        </Typography>
                        <Typography variant="body1" sx={{ fontWeight: 500 }}>
                          Confidence: {(result.confidence * 100).toFixed(2)}%
                        </Typography>
                      </Box>
                      
                      <Box 
                        sx={{ 
                          mt: { xs: 2, sm: 0 },
                          display: 'flex',
                          alignItems: 'center',
                          px: 2,
                          py: 1,
                          backgroundColor: alpha(
                            result.prediction === 'Real' 
                              ? theme.palette.success.main 
                              : theme.palette.error.main,
                            0.1
                          ),
                          borderRadius: 2
                        }}
                      >
                        <Typography variant="body2" sx={{ fontWeight: 600, color: result.prediction === 'Real' ? 'success.dark' : 'error.dark' }}>
                          {result.prediction === 'Real' ? 'Human Voice' : 'AI-Generated'}
                        </Typography>
                      </Box>
                    </Box>
                  </CardContent>
                </ResultCard>
                
                <GlassCard elevation={2} sx={{ p: { xs: 2, sm: 3 } }}>
                  <Typography variant="h6" gutterBottom sx={{ fontWeight: 600 }}>
                    Probability Distribution
                  </Typography>
                  <Box sx={{ height: isMobile ? 250 : 300, width: '100%', mt: 2 }}>
                    <ResponsiveContainer width="100%" height="100%">
                      <BarChart
                        data={getChartData()}
                        margin={{
                          top: 30,
                          right: 30,
                          left: 20,
                          bottom: 10,
                        }}
                      >
                        <CartesianGrid strokeDasharray="3 3" stroke={alpha('#000', 0.1)} />
                        <XAxis 
                          dataKey="name" 
                          tick={{ fill: theme.palette.text.secondary }}
                          axisLine={{ stroke: alpha('#000', 0.15) }}
                        />
                        <YAxis 
                          label={{ 
                            value: 'Probability (%)', 
                            angle: -90, 
                            position: 'insideLeft',
                            style: { fill: theme.palette.text.secondary } 
                          }}
                          tick={{ fill: theme.palette.text.secondary }}
                          axisLine={{ stroke: alpha('#000', 0.15) }}
                        />
                        <Tooltip 
                          formatter={(value) => [`${value}%`, 'Probability']} 
                          contentStyle={{ 
                            borderRadius: 8, 
                            border: 'none', 
                            boxShadow: '0 4px 20px rgba(0,0,0,0.1)',
                            backgroundColor: alpha('#fff', 0.95) 
                          }}
                        />
                        <Bar 
                          dataKey="value" 
                          fill={(entry) => entry.name === 'Real' ? theme.palette.success.main : theme.palette.error.main}
                          radius={[8, 8, 0, 0]}
                          label={{ 
                            position: 'top', 
                            formatter: (value) => `${value}%`,
                            fill: theme.palette.text.secondary,
                            fontSize: 12,
                            fontWeight: 600
                          }}
                        />
                      </BarChart>
                    </ResponsiveContainer>
                  </Box>
                </GlassCard>
                
                <Box sx={{ mt: 3, textAlign: 'center' }}>
                  <Typography variant="body2" color="text.secondary">
                    Note: This model claims {modelInfo ? (modelInfo.performance.accuracy * 100).toFixed(2) : ''}% accuracy, but results may vary depending on audio quality.
                  </Typography>
                </Box>
              </Box>
            </motion.div>
          )}
        </Container>
      </Box>
      
      <Snackbar
        open={openSnackbar}
        autoHideDuration={6000}
        onClose={handleCloseSnackbar}
        anchorOrigin={{ vertical: 'bottom', horizontal: 'center' }}
      >
        <Alert 
          onClose={handleCloseSnackbar} 
          severity="error" 
          sx={{ 
            width: '100%',
            borderRadius: 2,
            boxShadow: '0 4px 20px rgba(0,0,0,0.15)'
          }}
        >
          {error}
        </Alert>
      </Snackbar>
    </ThemeProvider>
  );
}

export default App;