Update app.py
Browse files
app.py
CHANGED
@@ -8,6 +8,7 @@ import gradio as gr
|
|
8 |
import os
|
9 |
import torch.nn.functional as F
|
10 |
from scipy.special import expit
|
|
|
11 |
|
12 |
|
13 |
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
@@ -74,12 +75,19 @@ def process_audio(input_data, segment_duration=10):
|
|
74 |
else:
|
75 |
confidence_percentage = 1 - expit(decision_score).item()
|
76 |
segment_predictions.append(pred)
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
83 |
|
84 |
def gradio_interface(audio):
|
85 |
if audio:
|
|
|
8 |
import os
|
9 |
import torch.nn.functional as F
|
10 |
from scipy.special import expit
|
11 |
+
import json
|
12 |
|
13 |
|
14 |
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
|
|
75 |
else:
|
76 |
confidence_percentage = 1 - expit(decision_score).item()
|
77 |
segment_predictions.append(pred)
|
78 |
+
output_dict = {
|
79 |
+
"classification": "real" if sum(segment_predictions) > (len(segment_predictions) / 2) else "fake",
|
80 |
+
"segments": [
|
81 |
+
{
|
82 |
+
"segment": idx + 1,
|
83 |
+
"prediction": "real" if pred == 1 else "fake",
|
84 |
+
"confidence": round(conf * 100, 2)
|
85 |
+
}
|
86 |
+
for idx, (pred, conf) in enumerate(zip(segment_predictions, confidence_scores))
|
87 |
+
]
|
88 |
+
}
|
89 |
+
json_output = json.dumps(output_dict, indent=4)
|
90 |
+
return json_output
|
91 |
|
92 |
def gradio_interface(audio):
|
93 |
if audio:
|