wli3221134 commited on
Commit
ca6274c
·
verified ·
1 Parent(s): 7a93fcf

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +74 -0
app.py ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import os
3
+ import inference
4
+
5
+ def audio_deepfake_detection(demonstration_paths, audio_path):
6
+ """Audio deepfake detection function"""
7
+ # Replace with your actual detection logic
8
+ print("Demonstration audio paths: {}".format(demonstration_paths))
9
+ print("Query audio path: {}".format(audio_path))
10
+
11
+ # Example return value, modify according to your model
12
+ result = inference.detect(demonstration_paths, audio_path)
13
+
14
+ # Return detection results and confidence scores
15
+ return {
16
+ "Is AI Generated": result["is_fake"],
17
+ "Confidence": f"{result['confidence']:.2f}%"
18
+ }
19
+
20
+ with gr.Blocks() as demo:
21
+ gr.Markdown(
22
+ """
23
+ # Audio Deepfake Detection System
24
+
25
+ This demo helps you detect whether an audio clip is AI-generated or authentic.
26
+ """
27
+ )
28
+
29
+ gr.Markdown(
30
+ """
31
+ ## Upload Audio
32
+ **Note**: Supports common audio formats (wav, mp3, etc.).
33
+ """
34
+ )
35
+
36
+ # Demonstration audio input component
37
+ demonstration_audio_input = gr.Audio(
38
+ sources=["upload"],
39
+ label="Demonstration Audios",
40
+ type="filepath",
41
+ )
42
+
43
+ # Audio input component
44
+ query_audio_input = gr.Audio(
45
+ sources=["upload"],
46
+ label="Query Audio (Audio for Detection)",
47
+ type="filepath",
48
+ )
49
+
50
+ # Submit button
51
+ submit_btn = gr.Button(value="Start Detection", variant="primary")
52
+
53
+ # Output results
54
+ output_labels = gr.Json(label="Detection Results")
55
+
56
+ # Set click event
57
+ submit_btn.click(
58
+ fn=audio_deepfake_detection,
59
+ inputs=[demonstration_audio_input, query_audio_input],
60
+ outputs=[output_labels]
61
+ )
62
+
63
+ # Examples section
64
+ gr.Markdown("## Test Examples")
65
+ gr.Examples(
66
+ examples=[
67
+ ["examples/real_audio.wav", "examples/query_audio.wav"],
68
+ ["examples/fake_audio.wav", "examples/query_audio.wav"],
69
+ ],
70
+ inputs=[demonstration_audio_input, query_audio_input],
71
+ )
72
+
73
+ if __name__ == "__main__":
74
+ demo.launch()