Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -81,8 +81,34 @@ def predict_with_sliding_window(audio_path, onnx_model_path, window_size=64600,
|
|
| 81 |
return majority_class, avg_probability
|
| 82 |
|
| 83 |
# Streamlit app
|
| 84 |
-
st.
|
| 85 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
|
| 87 |
# File uploader
|
| 88 |
uploaded_file = st.file_uploader("Upload your audio file (WAV or MP3)", type=["wav", "mp3"])
|
|
@@ -94,18 +120,30 @@ onnx_model_url = "https://huggingface.co/Mrkomiljon/DeepVoiceGuard/resolve/main/
|
|
| 94 |
onnx_model_path = download_model(onnx_model_url)
|
| 95 |
|
| 96 |
if uploaded_file is not None:
|
|
|
|
|
|
|
| 97 |
# Save uploaded file temporarily
|
| 98 |
with open("temp_audio_file.wav", "wb") as f:
|
| 99 |
f.write(uploaded_file.read())
|
| 100 |
|
| 101 |
# Perform prediction
|
| 102 |
-
with st.spinner("
|
| 103 |
result, avg_probability = predict_with_sliding_window("temp_audio_file.wav", onnx_model_path)
|
| 104 |
|
| 105 |
# Display results
|
| 106 |
st.success(f"Prediction: {result}")
|
| 107 |
-
st.
|
| 108 |
|
| 109 |
# Clean up temporary file
|
| 110 |
os.remove("temp_audio_file.wav")
|
| 111 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
return majority_class, avg_probability
|
| 82 |
|
| 83 |
# Streamlit app
|
| 84 |
+
st.set_page_config(page_title="Audio Spoof Detection", page_icon="🎵", layout="centered")
|
| 85 |
+
|
| 86 |
+
# Header Section
|
| 87 |
+
st.markdown("<h1 style='text-align: center; color: blue;'>Audio Spoof Detection</h1>", unsafe_allow_html=True)
|
| 88 |
+
st.markdown(
|
| 89 |
+
"""
|
| 90 |
+
<p style='text-align: center;'>
|
| 91 |
+
Detect whether an uploaded audio file is <strong>Real</strong> or <strong>Fake</strong> using an ONNX model.
|
| 92 |
+
</p>
|
| 93 |
+
""",
|
| 94 |
+
unsafe_allow_html=True,
|
| 95 |
+
)
|
| 96 |
+
|
| 97 |
+
# Sidebar
|
| 98 |
+
st.sidebar.header("Instructions")
|
| 99 |
+
st.sidebar.write(
|
| 100 |
+
"""
|
| 101 |
+
- Upload an audio file in WAV or MP3 format.
|
| 102 |
+
- Wait for the model to process the file.
|
| 103 |
+
- View the prediction result and confidence score.
|
| 104 |
+
"""
|
| 105 |
+
)
|
| 106 |
+
st.sidebar.markdown("### About the Model")
|
| 107 |
+
st.sidebar.info(
|
| 108 |
+
"""
|
| 109 |
+
The model is trained to classify audio as Real or Fake using a RawNet-based architecture.
|
| 110 |
+
"""
|
| 111 |
+
)
|
| 112 |
|
| 113 |
# File uploader
|
| 114 |
uploaded_file = st.file_uploader("Upload your audio file (WAV or MP3)", type=["wav", "mp3"])
|
|
|
|
| 120 |
onnx_model_path = download_model(onnx_model_url)
|
| 121 |
|
| 122 |
if uploaded_file is not None:
|
| 123 |
+
st.markdown("<h3 style='text-align: center;'>Processing Your File...</h3>", unsafe_allow_html=True)
|
| 124 |
+
|
| 125 |
# Save uploaded file temporarily
|
| 126 |
with open("temp_audio_file.wav", "wb") as f:
|
| 127 |
f.write(uploaded_file.read())
|
| 128 |
|
| 129 |
# Perform prediction
|
| 130 |
+
with st.spinner("Running the model..."):
|
| 131 |
result, avg_probability = predict_with_sliding_window("temp_audio_file.wav", onnx_model_path)
|
| 132 |
|
| 133 |
# Display results
|
| 134 |
st.success(f"Prediction: {result}")
|
| 135 |
+
st.metric(label="Confidence", value=f"{avg_probability:.2f}%", delta=None)
|
| 136 |
|
| 137 |
# Clean up temporary file
|
| 138 |
os.remove("temp_audio_file.wav")
|
| 139 |
|
| 140 |
+
# Footer
|
| 141 |
+
st.markdown(
|
| 142 |
+
"""
|
| 143 |
+
<hr>
|
| 144 |
+
<p style='text-align: center; font-size: small;'>
|
| 145 |
+
Created with ❤️ using Streamlit.
|
| 146 |
+
</p>
|
| 147 |
+
""",
|
| 148 |
+
unsafe_allow_html=True,
|
| 149 |
+
)
|