|
import os |
|
from transformers import pipeline |
|
import gradio as gr |
|
import numpy as np |
|
import soundfile as sf |
|
|
|
|
|
hf_token = os.getenv('HF_TOKEN') |
|
|
|
if not hf_token: |
|
print("Warning: No Hugging Face token set. Continuing without token...") |
|
|
|
|
|
pipe = pipeline("audio-classification", model="mo-thecreator/Deepfake-audio-detection") |
|
|
|
def predict_deepfake(audio): |
|
|
|
if isinstance(audio, str): |
|
audio_data, _ = sf.read(audio) |
|
elif isinstance(audio, np.ndarray): |
|
audio_data = audio |
|
else: |
|
return "Error: Invalid input format. Please upload a valid audio file." |
|
|
|
|
|
if audio_data.shape[0] == 0: |
|
return "Error: Audio data is empty." |
|
|
|
|
|
try: |
|
result = pipe(audio_data) |
|
return result[0]['label'] |
|
except Exception as e: |
|
return f"Error during classification: {str(e)}" |
|
|
|
|
|
iface = gr.Interface(fn=predict_deepfake, inputs=gr.Audio(type="filepath"), outputs="text", live=True) |
|
|
|
|
|
iface.launch(share=True) |
|
|