DavidCombei commited on
Commit
78c2a6a
1 Parent(s): 49bb77f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -15
app.py CHANGED
@@ -4,7 +4,7 @@ import torch
4
  import soundfile as sf
5
  import numpy as np
6
  import gradio as gr
7
-
8
 
9
  class HuggingFaceFeatureExtractor:
10
  def __init__(self, model_class, name):
@@ -26,7 +26,6 @@ class HuggingFaceFeatureExtractor:
26
  outputs = self.model(**inputs)
27
  return outputs.last_hidden_state
28
 
29
-
30
  FEATURE_EXTRACTORS = {
31
  "wavlm-base": lambda: HuggingFaceFeatureExtractor(WavLMModel, "microsoft/wavlm-base"),
32
  "wavLM-V1": lambda: HuggingFaceFeatureExtractor(WavLMModel, "DavidCombei/wavLM-base-DeepFake_UTCN"),
@@ -34,23 +33,17 @@ FEATURE_EXTRACTORS = {
34
  "wavLM-V3": lambda: HuggingFaceFeatureExtractor(WavLMModel, "DavidCombei/wavLM-base-UTCN_114k"),
35
  }
36
 
37
-
38
  model1 = joblib.load('model1.joblib')
39
  model2 = joblib.load('model2.joblib')
40
  model3 = joblib.load('model3.joblib')
41
  model4 = joblib.load('model4.joblib')
42
  final_model = joblib.load('final_model.joblib')
43
 
44
-
45
  def process_audio(file_audio):
46
- #audio, sr = sf.read(file_audio)
47
- audio, sr = librosa.load(file_audio,sr=16000)
48
-
49
 
50
- if len(audio.shape)>1:
51
- audio = audio[0]
52
-
53
-
54
 
55
  extractor_1 = FEATURE_EXTRACTORS['wavlm-base']()
56
  extractor_2 = FEATURE_EXTRACTORS['wavLM-V1']()
@@ -84,17 +77,16 @@ def process_audio(file_audio):
84
  final_prob = final_model.predict_proba(eval_combined_probs)[:, 1]
85
 
86
  if final_prob < 0.5:
87
- return f"Fake with a confidence of: {100-final_prob[0] * 100:.2f}"
88
  else:
89
- return f"Real with a confidence of: {final_prob[0] * 100:.2f}"
90
-
91
 
92
  interface = gr.Interface(
93
  fn=process_audio,
94
  inputs=gr.Audio(type="filepath"),
95
  outputs="text",
96
  title="Audio Deepfake Detection",
97
- description="Upload an audio file to detect whether it is fake or real.",
98
  )
99
 
100
  interface.launch(share=True)
 
4
  import soundfile as sf
5
  import numpy as np
6
  import gradio as gr
7
+ import librosa
8
 
9
  class HuggingFaceFeatureExtractor:
10
  def __init__(self, model_class, name):
 
26
  outputs = self.model(**inputs)
27
  return outputs.last_hidden_state
28
 
 
29
  FEATURE_EXTRACTORS = {
30
  "wavlm-base": lambda: HuggingFaceFeatureExtractor(WavLMModel, "microsoft/wavlm-base"),
31
  "wavLM-V1": lambda: HuggingFaceFeatureExtractor(WavLMModel, "DavidCombei/wavLM-base-DeepFake_UTCN"),
 
33
  "wavLM-V3": lambda: HuggingFaceFeatureExtractor(WavLMModel, "DavidCombei/wavLM-base-UTCN_114k"),
34
  }
35
 
 
36
  model1 = joblib.load('model1.joblib')
37
  model2 = joblib.load('model2.joblib')
38
  model3 = joblib.load('model3.joblib')
39
  model4 = joblib.load('model4.joblib')
40
  final_model = joblib.load('final_model.joblib')
41
 
 
42
  def process_audio(file_audio):
43
+ audio, sr = librosa.load(file_audio, sr=16000) # Resample to 16 kHz
 
 
44
 
45
+ if len(audio.shape) > 1:
46
+ audio = audio[0]
 
 
47
 
48
  extractor_1 = FEATURE_EXTRACTORS['wavlm-base']()
49
  extractor_2 = FEATURE_EXTRACTORS['wavLM-V1']()
 
77
  final_prob = final_model.predict_proba(eval_combined_probs)[:, 1]
78
 
79
  if final_prob < 0.5:
80
+ return f"Fake with a confidence of: {100 - final_prob[0] * 100:.2f}%"
81
  else:
82
+ return f"Real with a confidence of: {final_prob[0] * 100:.2f}%"
 
83
 
84
  interface = gr.Interface(
85
  fn=process_audio,
86
  inputs=gr.Audio(type="filepath"),
87
  outputs="text",
88
  title="Audio Deepfake Detection",
89
+ description="Upload an audio file to detect whether it is fake or real. The system uses features ensamble from wavLM base and finetuned versions. Submitted to ASVSpoof5.",
90
  )
91
 
92
  interface.launch(share=True)