ThaoVo commited on
Commit
df31464
·
verified ·
1 Parent(s): 5677a1a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -6
app.py CHANGED
@@ -14,14 +14,15 @@ if not hf_token:
14
  pipe = pipeline("audio-classification", model="mo-thecreator/Deepfake-audio-detection")
15
 
16
  def predict_deepfake(audio):
17
- # Đảm bảo đầu vào numpy array đọc tệp âm thanh đúng cách
18
- if isinstance(audio, np.ndarray):
 
 
19
  audio_data = audio
20
  else:
21
- # Nếu đầu vào tệp âm thanh, ta cần đọc nó đúng cách
22
- audio_data, _ = sf.read(audio) # Dùng soundfile để đọc tệp âm thanh
23
 
24
- # Kiểm tra xem dữ liệu âm thanh có hợp lệ không
25
  if audio_data.shape[0] == 0:
26
  return "Error: Audio data is empty."
27
 
@@ -33,7 +34,7 @@ def predict_deepfake(audio):
33
  return f"Error during classification: {str(e)}"
34
 
35
  # Tạo giao diện người dùng với Gradio
36
- iface = gr.Interface(fn=predict_deepfake, inputs=gr.Audio(type="file"), outputs="text", live=True)
37
 
38
  # Khởi chạy giao diện
39
  iface.launch(share=True)
 
14
  pipe = pipeline("audio-classification", model="mo-thecreator/Deepfake-audio-detection")
15
 
16
  def predict_deepfake(audio):
17
+ # Nếu tệp âm thanh được tải lên, sử dụng soundfile để đọc
18
+ if isinstance(audio, str): # Đây là tệp âm thanh
19
+ audio_data, _ = sf.read(audio) # Đọc tệp âm thanh với soundfile
20
+ elif isinstance(audio, np.ndarray): # Nếu âm thanh đã là numpy array
21
  audio_data = audio
22
  else:
23
+ return "Error: Invalid input format. Please upload a valid audio file."
 
24
 
25
+ # Kiểm tra kích thước dữ liệu âm thanh
26
  if audio_data.shape[0] == 0:
27
  return "Error: Audio data is empty."
28
 
 
34
  return f"Error during classification: {str(e)}"
35
 
36
  # Tạo giao diện người dùng với Gradio
37
+ iface = gr.Interface(fn=predict_deepfake, inputs=gr.Audio(type="filepath"), outputs="text", live=True)
38
 
39
  # Khởi chạy giao diện
40
  iface.launch(share=True)