Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -21,9 +21,8 @@ download_models()
|
|
| 21 |
|
| 22 |
@app.route('/detect', methods=['POST'])
|
| 23 |
def detect_deepfake():
|
| 24 |
-
|
| 25 |
audio_file = request.files.get('audio_file')
|
| 26 |
-
folder_path = request.form.get('folder_path')
|
| 27 |
|
| 28 |
# If a single audio file is provided
|
| 29 |
if audio_file:
|
|
@@ -44,28 +43,9 @@ def detect_deepfake():
|
|
| 44 |
except Exception as e:
|
| 45 |
return jsonify({"error": str(e)}), 500
|
| 46 |
|
| 47 |
-
#
|
| 48 |
-
elif folder_path and os.path.isdir(folder_path):
|
| 49 |
-
results = {}
|
| 50 |
-
try:
|
| 51 |
-
for file_name in os.listdir(folder_path):
|
| 52 |
-
if file_name.endswith('.wav') or file_name.endswith('.mp3'):
|
| 53 |
-
file_path = os.path.join(folder_path, file_name)
|
| 54 |
-
result = audio_model(file_path)
|
| 55 |
-
results[file_name] = {item['label']: item['score'] for item in result}
|
| 56 |
-
|
| 57 |
-
# Save results to a file
|
| 58 |
-
with open('detection_results.json', 'w') as f:
|
| 59 |
-
f.write(json.dumps(results))
|
| 60 |
-
|
| 61 |
-
return jsonify({"message": "Detection completed", "results": results}), 200
|
| 62 |
-
|
| 63 |
-
except Exception as e:
|
| 64 |
-
return jsonify({"error": str(e)}), 500
|
| 65 |
-
|
| 66 |
-
# Invalid request if neither audio file nor valid folder path is provided
|
| 67 |
else:
|
| 68 |
-
return jsonify({"error": "Invalid input.
|
| 69 |
|
| 70 |
if __name__ == '__main__':
|
| 71 |
# Run the Flask app
|
|
|
|
| 21 |
|
| 22 |
@app.route('/detect', methods=['POST'])
|
| 23 |
def detect_deepfake():
|
| 24 |
+
# Expect an audio file in the request
|
| 25 |
audio_file = request.files.get('audio_file')
|
|
|
|
| 26 |
|
| 27 |
# If a single audio file is provided
|
| 28 |
if audio_file:
|
|
|
|
| 43 |
except Exception as e:
|
| 44 |
return jsonify({"error": str(e)}), 500
|
| 45 |
|
| 46 |
+
# Invalid request if no audio file is provided
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
else:
|
| 48 |
+
return jsonify({"error": "Invalid input. Please provide an audio file."}), 400
|
| 49 |
|
| 50 |
if __name__ == '__main__':
|
| 51 |
# Run the Flask app
|