GVAmaresh commited on
Commit
d6bd955
·
1 Parent(s): 582d273

issue: shape of 4 models

Browse files
__pycache__/app.cpython-311.pyc ADDED
Binary file (23 kB). View file
 
app.py CHANGED
@@ -2,6 +2,17 @@
2
  from fastapi import FastAPI
3
 
4
  app = FastAPI()
 
 
 
 
 
 
 
 
 
 
 
5
 
6
  @app.get("/")
7
  def greet_json():
@@ -63,7 +74,6 @@ else:
63
  print(f"The file '{output_file}' does not exist at '{file_path}'.")
64
 
65
  #--------------------------------------------------------------------------------------------------------------------
66
-
67
  import os
68
  import numpy as np
69
  import tensorflow as tf
@@ -74,7 +84,10 @@ import matplotlib.pyplot as plt
74
 
75
  import os
76
  os.environ["TORCH_HOME"] = "/tmp/torch_cache"
77
-
 
 
 
78
 
79
  from tensorflow.keras.applications.vgg16 import VGG16, preprocess_input
80
  from tensorflow.keras.models import Model
@@ -86,8 +99,8 @@ class UnifiedDeepfakeDetector:
86
  def __init__(self):
87
  self.input_shape = (224, 224, 3)
88
  self.vgg_model = self.build_vgg16_model()
89
- self.dense_model = tf.keras.models.load_model('./downloads/file.h5')
90
- self.cnn_model = tf.keras.models.load_model('./downloads/file2.h5')
91
  self.melody_machine = pipeline(model="MelodyMachine/Deepfake-audio-detection-V2")
92
 
93
  def build_vgg16_model(self):
@@ -178,7 +191,7 @@ class UnifiedDeepfakeDetector:
178
  # CNN Model Analysis
179
  if model_choice in ["CNN", "all"]:
180
  mfcc = librosa.feature.mfcc(y=audio, sr=sr, n_mfcc=40)
181
- mfcc_scaled = np.mean(mfcc.T, axis=0).reshape(1, 40, 1, 1)
182
  pred = self.cnn_model.predict(mfcc_scaled)
183
  results["CNN"] = {
184
  "prediction": "FAKE" if np.argmax(pred[0]) == 0 else "REAL",
@@ -280,6 +293,7 @@ import librosa
280
  os.environ["TF_CPP_MIN_LOG_LEVEL"] = "2"
281
  os.environ["MPLCONFIGDIR"] = "/tmp/matplotlib"
282
  os.environ["FONTCONFIG_PATH"] = "/tmp/fontconfig"
 
283
  os.environ["HF_HOME"] = "/tmp/huggingface_cache"
284
 
285
  os.makedirs("/tmp/matplotlib", exist_ok=True)
@@ -299,6 +313,7 @@ def reencode_audio(input_path, output_path):
299
  #--------------------------------------------------------------------------------------------------------------------
300
  from collections import Counter
301
  from datetime import datetime
 
302
 
303
  @app.post("/upload")
304
  async def upload_file(file: UploadFile = File(...)):
@@ -368,7 +383,7 @@ async def upload_file(file: UploadFile = File(...)):
368
  result = list(result)
369
  result.append("FAKE" if float(entropy) < 150 else "REAL")
370
  print(result)
371
- r_normalized = [x.upper() for x in result]
372
  counter = Counter(r_normalized)
373
 
374
  most_common_element, _ = counter.most_common(1)[0]
 
2
  from fastapi import FastAPI
3
 
4
  app = FastAPI()
5
+ from fastapi.middleware.cors import CORSMiddleware
6
+ origins = [
7
+ "*"
8
+ ]
9
+ app.add_middleware(
10
+ CORSMiddleware,
11
+ allow_origins=origins,
12
+ allow_credentials=True,
13
+ allow_methods=["*"],
14
+ allow_headers=["*"],
15
+ )
16
 
17
  @app.get("/")
18
  def greet_json():
 
74
  print(f"The file '{output_file}' does not exist at '{file_path}'.")
75
 
76
  #--------------------------------------------------------------------------------------------------------------------
 
77
  import os
78
  import numpy as np
79
  import tensorflow as tf
 
84
 
85
  import os
86
  os.environ["TORCH_HOME"] = "/tmp/torch_cache"
87
+ os.environ["TF_ENABLE_ONEDNN_OPTS"] = "0"
88
+ os.environ["MPLCONFIGDIR"] = "/tmp/matplotlib_config"
89
+ os.environ["FONTCONFIG_PATH"] = "/tmp/fontconfig"
90
+ os.environ["HF_HOME"] = "/tmp/huggingface_cache"
91
 
92
  from tensorflow.keras.applications.vgg16 import VGG16, preprocess_input
93
  from tensorflow.keras.models import Model
 
99
  def __init__(self):
100
  self.input_shape = (224, 224, 3)
101
  self.vgg_model = self.build_vgg16_model()
102
+ self.dense_model = tf.keras.models.load_model('downloads/file2.h5')
103
+ self.cnn_model = tf.keras.models.load_model('downloads/file.h5')
104
  self.melody_machine = pipeline(model="MelodyMachine/Deepfake-audio-detection-V2")
105
 
106
  def build_vgg16_model(self):
 
191
  # CNN Model Analysis
192
  if model_choice in ["CNN", "all"]:
193
  mfcc = librosa.feature.mfcc(y=audio, sr=sr, n_mfcc=40)
194
+ mfcc_scaled = np.mean(mfcc.T, axis=0).reshape(None, 40, 1, 1)
195
  pred = self.cnn_model.predict(mfcc_scaled)
196
  results["CNN"] = {
197
  "prediction": "FAKE" if np.argmax(pred[0]) == 0 else "REAL",
 
293
  os.environ["TF_CPP_MIN_LOG_LEVEL"] = "2"
294
  os.environ["MPLCONFIGDIR"] = "/tmp/matplotlib"
295
  os.environ["FONTCONFIG_PATH"] = "/tmp/fontconfig"
296
+ os.environ["TF_ENABLE_ONEDNN_OPTS"]="0"
297
  os.environ["HF_HOME"] = "/tmp/huggingface_cache"
298
 
299
  os.makedirs("/tmp/matplotlib", exist_ok=True)
 
313
  #--------------------------------------------------------------------------------------------------------------------
314
  from collections import Counter
315
  from datetime import datetime
316
+ import base64
317
 
318
  @app.post("/upload")
319
  async def upload_file(file: UploadFile = File(...)):
 
383
  result = list(result)
384
  result.append("FAKE" if float(entropy) < 150 else "REAL")
385
  print(result)
386
+ r_normalized = [x.upper() for x in result if x is not None]
387
  counter = Counter(r_normalized)
388
 
389
  most_common_element, _ = counter.most_common(1)[0]
audio/20250104_105108_reencoded.wav ADDED
Binary file (88.4 kB). View file
 
audio/20250104_105122_reencoded.wav ADDED
Binary file (88.4 kB). View file
 
audio/20250104_110519_reencoded.wav ADDED
Binary file (67.3 kB). View file
 
audio/20250104_110528_reencoded.wav ADDED
Binary file (67.3 kB). View file
 
audio/20250104_110831_reencoded.wav ADDED
Binary file (119 kB). View file
 
audio/20250104_110832_reencoded.wav ADDED
Binary file (119 kB). View file
 
audio/20250104_111006_reencoded.wav ADDED
Binary file (94.2 kB). View file
 
audio/20250104_111036_reencoded.wav ADDED
Binary file (94.2 kB). View file
 
audio/20250104_111151_reencoded.wav ADDED
Binary file (115 kB). View file
 
audio/20250104_111159_reencoded.wav ADDED
Binary file (115 kB). View file
 
audio/20250104_111351_reencoded.wav ADDED
Binary file (365 kB). View file
 
audio/20250104_111401_reencoded.wav ADDED
Binary file (365 kB). View file
 
audio/20250104_112850_reencoded.wav ADDED
Binary file (80.7 kB). View file
 
audio/20250104_112858_reencoded.wav ADDED
Binary file (80.7 kB). View file
 
downloads/file.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1894bc00368d6b754f9ccbd7dec92c0fcd0fe741d23e87a92c3d54a3cc211b25
3
+ size 4003296
downloads/file2.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b3036383c72926c51fb8814b33f9bfb77f4f3d447fb34719c43319a252a4b741
3
+ size 900560
spectrogram_plot.png ADDED