DavidCombei commited on
Commit
b2b5493
·
verified ·
1 Parent(s): 711f553

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -6
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
- line = f"Segment {idx + 1}: {'Real' if pred == 1 else 'Fake'} (Confidence: {np.round(confidence_percentage*100, 2)}%)"
78
- output_lines.append(line)
79
- overall_prediction = 1 if sum(segment_predictions) > (len(segment_predictions) / 2) else 0
80
- overall_line = f"Overall Prediction: {'Real' if overall_prediction == 1 else 'Fake'}"
81
- output_str = overall_line + "\n" + "\n".join(output_lines)
82
- return output_str
 
 
 
 
 
 
 
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: