Commit
·
a3aaa5a
1
Parent(s):
7c86e01
Fix UI clear behavior and improve audio UX
Browse files
app.py
CHANGED
|
@@ -12,6 +12,9 @@ from audio_backend import predict_audio
|
|
| 12 |
def analyze_image(image):
|
| 13 |
label, confidence, heatmap = predict_image_pil(image)
|
| 14 |
|
|
|
|
|
|
|
|
|
|
| 15 |
if label == "Fake":
|
| 16 |
if confidence >= 90:
|
| 17 |
risk = '<span class="material-icons">error</span> High likelihood of deepfake'
|
|
@@ -37,9 +40,17 @@ def analyze_audio(audio_path):
|
|
| 37 |
label, confidence, spec_img, error = predict_audio(audio_path)
|
| 38 |
|
| 39 |
# ---------- Error handling ----------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
if error is not None:
|
| 41 |
return (
|
| 42 |
-
"
|
| 43 |
"-",
|
| 44 |
f'<span class="material-icons">error</span> {error}',
|
| 45 |
None
|
|
@@ -145,7 +156,7 @@ with gr.Blocks(css="style.css") as demo:
|
|
| 145 |
with gr.Column(scale=2):
|
| 146 |
img_pred = gr.Text(label="Prediction")
|
| 147 |
img_conf = gr.Text(label="Confidence")
|
| 148 |
-
img_risk = gr.HTML(label="Risk Assessment")
|
| 149 |
img_heatmap = gr.Image(
|
| 150 |
label="Explainability Heatmap",
|
| 151 |
height=280
|
|
@@ -158,9 +169,9 @@ with gr.Blocks(css="style.css") as demo:
|
|
| 158 |
)
|
| 159 |
|
| 160 |
img_clear.click(
|
| 161 |
-
fn=lambda: (None, "", "", None),
|
| 162 |
inputs=None,
|
| 163 |
-
outputs=[image_input, img_pred, img_conf, img_risk]
|
| 164 |
)
|
| 165 |
|
| 166 |
# =========================
|
|
@@ -172,17 +183,18 @@ with gr.Blocks(css="style.css") as demo:
|
|
| 172 |
with gr.Row():
|
| 173 |
with gr.Column(scale=1):
|
| 174 |
audio_input = gr.Audio(
|
| 175 |
-
label="Upload Audio (
|
| 176 |
type="filepath"
|
| 177 |
)
|
|
|
|
| 178 |
aud_submit = gr.Button("Submit")
|
| 179 |
aud_clear = gr.Button("Clear")
|
| 180 |
|
| 181 |
with gr.Column(scale=2):
|
| 182 |
aud_pred = gr.Text(label="Prediction")
|
| 183 |
aud_conf = gr.Text(label="Confidence")
|
| 184 |
-
aud_risk = gr.HTML(label="Risk Assessment")
|
| 185 |
-
aud_spec = gr.Image(label="Audio Spectrogram (Model Input)",height=280)
|
| 186 |
|
| 187 |
aud_submit.click(
|
| 188 |
fn=analyze_audio,
|
|
@@ -191,7 +203,7 @@ with gr.Blocks(css="style.css") as demo:
|
|
| 191 |
)
|
| 192 |
|
| 193 |
aud_clear.click(
|
| 194 |
-
fn=lambda: (None, "", ""),
|
| 195 |
inputs=None,
|
| 196 |
outputs=[audio_input, aud_pred, aud_conf, aud_risk, aud_spec]
|
| 197 |
)
|
|
|
|
| 12 |
def analyze_image(image):
|
| 13 |
label, confidence, heatmap = predict_image_pil(image)
|
| 14 |
|
| 15 |
+
if image is None:
|
| 16 |
+
return "", "", "", None
|
| 17 |
+
|
| 18 |
if label == "Fake":
|
| 19 |
if confidence >= 90:
|
| 20 |
risk = '<span class="material-icons">error</span> High likelihood of deepfake'
|
|
|
|
| 40 |
label, confidence, spec_img, error = predict_audio(audio_path)
|
| 41 |
|
| 42 |
# ---------- Error handling ----------
|
| 43 |
+
if audio_path is None:
|
| 44 |
+
return (
|
| 45 |
+
"No Input",
|
| 46 |
+
"-",
|
| 47 |
+
'<span class="material-icons">warning</span> Please upload an audio file.',
|
| 48 |
+
None
|
| 49 |
+
)
|
| 50 |
+
|
| 51 |
if error is not None:
|
| 52 |
return (
|
| 53 |
+
"Invalid Input",
|
| 54 |
"-",
|
| 55 |
f'<span class="material-icons">error</span> {error}',
|
| 56 |
None
|
|
|
|
| 156 |
with gr.Column(scale=2):
|
| 157 |
img_pred = gr.Text(label="Prediction")
|
| 158 |
img_conf = gr.Text(label="Confidence")
|
| 159 |
+
img_risk = gr.HTML(label="Risk Assessment", value="")
|
| 160 |
img_heatmap = gr.Image(
|
| 161 |
label="Explainability Heatmap",
|
| 162 |
height=280
|
|
|
|
| 169 |
)
|
| 170 |
|
| 171 |
img_clear.click(
|
| 172 |
+
fn=lambda: (None, "", "", "", None),
|
| 173 |
inputs=None,
|
| 174 |
+
outputs=[image_input, img_pred, img_conf, img_risk, img_heatmap]
|
| 175 |
)
|
| 176 |
|
| 177 |
# =========================
|
|
|
|
| 183 |
with gr.Row():
|
| 184 |
with gr.Column(scale=1):
|
| 185 |
audio_input = gr.Audio(
|
| 186 |
+
label="Upload Audio (WAV, MP3, FLAC, M4A, OGG)",
|
| 187 |
type="filepath"
|
| 188 |
)
|
| 189 |
+
|
| 190 |
aud_submit = gr.Button("Submit")
|
| 191 |
aud_clear = gr.Button("Clear")
|
| 192 |
|
| 193 |
with gr.Column(scale=2):
|
| 194 |
aud_pred = gr.Text(label="Prediction")
|
| 195 |
aud_conf = gr.Text(label="Confidence")
|
| 196 |
+
aud_risk = gr.HTML(label="Risk Assessment", value="")
|
| 197 |
+
aud_spec = gr.Image(label="Audio Spectrogram (Model Input)",height=280, value="")
|
| 198 |
|
| 199 |
aud_submit.click(
|
| 200 |
fn=analyze_audio,
|
|
|
|
| 203 |
)
|
| 204 |
|
| 205 |
aud_clear.click(
|
| 206 |
+
fn=lambda: (None, "", "", "", None),
|
| 207 |
inputs=None,
|
| 208 |
outputs=[audio_input, aud_pred, aud_conf, aud_risk, aud_spec]
|
| 209 |
)
|