File size: 1,084 Bytes
d2686f5
 
 
 
 
 
 
 
4510960
 
 
 
 
 
 
 
 
 
 
d2686f5
 
 
 
88549e6
4510960
4c24f50
d2686f5
 
 
 
 
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
import gradio as gr
from transformers import pipeline

# Load the model using pipeline
pipe = pipeline("audio-classification", model="MelodyMachine/Deepfake-audio-detection-V2")

# Define the prediction function
def predict(audio):
    print("Audio file received:", audio)  # Debugging statement
    try:
        result = pipe(audio)
        print("Raw prediction result:", result)  # Debugging statement
        # Convert the result to the expected format
        output = {item['label']: item['score'] for item in result}
        print("Formatted prediction result:", output)  # Debugging statement
        return output
    except Exception as e:
        print("Error during prediction:", e)  # Debugging statement
        return {"error": str(e)}

# Create the Gradio interface
iface = gr.Interface(
    fn=predict,
    inputs=gr.Audio(type="filepath"),
    outputs=gr.Label(),
    title="Testing Deepfake Audio Detection Simple Interface",
    description="Upload an audio file or record your voice to detect if the audio is a deepfake."
)

# Launch the interface
iface.launch()