Update app.py
Browse files
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 |
-
#
|
| 18 |
-
if isinstance(audio,
|
|
|
|
|
|
|
| 19 |
audio_data = audio
|
| 20 |
else:
|
| 21 |
-
|
| 22 |
-
audio_data, _ = sf.read(audio) # Dùng soundfile để đọc tệp âm thanh
|
| 23 |
|
| 24 |
-
# Kiểm tra
|
| 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="
|
| 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)
|