Prasanna-ETH's picture
Create app.py
96ecb9d verified
import gradio as gr
import librosa
from transformers import pipeline
# Step 2: Load the "Digital Ear" (The Model)
# This model is specifically tuned to catch the "robotic hum" of AI voices
a_detector = pipeline("audio-classification", model="mo-thecreator/Deepfake-audio-detection")
# Step 3: Create the "Listener" Function
def analyze_voice(audio_file):
if not audio_file:
return "ERROR: No audio provided."
# Ask the AI: "Does this sound like a robot or a human?"
# The model returns a list of dictionaries sorted by score
results = a_detector(audio_file)
# We look at the highest confidence prediction (the first item in the list)
top_result = results[0]
verdict = top_result['label'].lower()
confidence = top_result['score']
# Most models use Label 0 for Fake/Spoof, and Label 1 for Real
if verdict == "fake" or "spoof" in verdict or "label_0" in verdict:
return f"🚨 WARNING: AI Voice Clone Detected! (Confidence: {confidence:.2%})"
else:
return f"✅ SUCCESS: Genuine Human Voice. (Confidence: {confidence:.2%})"
# Step 4: Build the IOB Helpline Demo (Gradio)
# I have added a Blocks interface here similar to the Video one for better presentation!
with gr.Blocks(title="IOB Sentinel: Voice Shield") as demo:
gr.Markdown("# IOB Sentinel: Audio Anti-Spoofing Engine")
gr.Markdown("Detecting AI voice clones and synthesized speech to prevent Vishing (Voice Phishing).")
with gr.Tabs():
with gr.TabItem("Upload Audio"):
upload_input = gr.Audio(type="filepath", label="Upload Voice Clip")
upload_output = gr.Textbox(label="Result")
upload_btn = gr.Button("Analyze Uploaded Audio", variant="primary")
upload_btn.click(fn=analyze_voice, inputs=upload_input, outputs=upload_output)
with gr.TabItem("Record Audio (Microphone)"):
# Gradio 4 syntax for microphone
mic_input = gr.Audio(sources=["microphone"], type="filepath", label="Record Voice Clip Live")
mic_output = gr.Textbox(label="Result")
mic_btn = gr.Button("Analyze Live Audio", variant="primary")
mic_btn.click(fn=analyze_voice, inputs=mic_input, outputs=mic_output)
if __name__ == "__main__":
demo.launch()