Spaces:
Runtime error
Runtime error
download the model and processor on startup
Browse files- app.py +6 -2
- predict.py +3 -7
app.py
CHANGED
@@ -1,17 +1,22 @@
|
|
1 |
import gradio as gr
|
2 |
from predict import prediction
|
|
|
|
|
3 |
|
4 |
title = "Audio deepfake Classification"
|
5 |
description = """This space uses fine-tuned kubinooo/convnext-tiny-224-audio-deepfake-classification model to classify audio files.
|
6 |
"""
|
7 |
|
|
|
|
|
|
|
8 |
demo = gr.Interface(
|
9 |
title=title,
|
10 |
inputs=gr.Audio( type="filepath",
|
11 |
interactive=True, # This prevents users from uploading their own images
|
12 |
show_label=True,
|
13 |
label="Select from examples below or upload/record your own audio"),
|
14 |
-
fn=prediction,
|
15 |
outputs=gr.Label(
|
16 |
num_top_classes=2,
|
17 |
),
|
@@ -21,5 +26,4 @@ demo = gr.Interface(
|
|
21 |
],
|
22 |
description=description
|
23 |
)
|
24 |
-
|
25 |
demo.launch(share=True,debug=True)
|
|
|
1 |
import gradio as gr
|
2 |
from predict import prediction
|
3 |
+
from transformers import AutoImageProcessor, AutoModelForImageClassification
|
4 |
+
from functools import partial
|
5 |
|
6 |
title = "Audio deepfake Classification"
|
7 |
description = """This space uses fine-tuned kubinooo/convnext-tiny-224-audio-deepfake-classification model to classify audio files.
|
8 |
"""
|
9 |
|
10 |
+
processor = AutoImageProcessor.from_pretrained("kubinooo/convnext-tiny-224-audio-deepfake-classification")
|
11 |
+
model = AutoModelForImageClassification.from_pretrained("kubinooo/convnext-tiny-224-audio-deepfake-classification")
|
12 |
+
|
13 |
demo = gr.Interface(
|
14 |
title=title,
|
15 |
inputs=gr.Audio( type="filepath",
|
16 |
interactive=True, # This prevents users from uploading their own images
|
17 |
show_label=True,
|
18 |
label="Select from examples below or upload/record your own audio"),
|
19 |
+
fn=partial(prediction, processor=processor, model=model),
|
20 |
outputs=gr.Label(
|
21 |
num_top_classes=2,
|
22 |
),
|
|
|
26 |
],
|
27 |
description=description
|
28 |
)
|
|
|
29 |
demo.launch(share=True,debug=True)
|
predict.py
CHANGED
@@ -1,11 +1,7 @@
|
|
1 |
import torch
|
2 |
-
from transformers import AutoImageProcessor, AutoModelForImageClassification
|
3 |
from process_audio import create_mel_spectrograms
|
4 |
-
import os
|
5 |
|
6 |
-
def predict_image(image):
|
7 |
-
processor = AutoImageProcessor.from_pretrained("kubinooo/convnext-tiny-224-audio-deepfake-classification")
|
8 |
-
model = AutoModelForImageClassification.from_pretrained("kubinooo/convnext-tiny-224-audio-deepfake-classification")
|
9 |
|
10 |
if image.mode != 'RGB':
|
11 |
image = image.convert('RGB')
|
@@ -30,14 +26,14 @@ def predict_image(image):
|
|
30 |
return {"real": 0.0, "fake": 1.0}
|
31 |
|
32 |
|
33 |
-
def prediction(file_path):
|
34 |
total_real = 0.0
|
35 |
total_fake = 0.0
|
36 |
|
37 |
pil_images = create_mel_spectrograms(file_path, 2, 0)
|
38 |
|
39 |
for image in pil_images:
|
40 |
-
pred = predict_image(image)
|
41 |
total_real += pred["real"]
|
42 |
total_fake += pred["fake"]
|
43 |
|
|
|
1 |
import torch
|
|
|
2 |
from process_audio import create_mel_spectrograms
|
|
|
3 |
|
4 |
+
def predict_image(image, processor, model):
|
|
|
|
|
5 |
|
6 |
if image.mode != 'RGB':
|
7 |
image = image.convert('RGB')
|
|
|
26 |
return {"real": 0.0, "fake": 1.0}
|
27 |
|
28 |
|
29 |
+
def prediction(file_path, processor, model):
|
30 |
total_real = 0.0
|
31 |
total_fake = 0.0
|
32 |
|
33 |
pil_images = create_mel_spectrograms(file_path, 2, 0)
|
34 |
|
35 |
for image in pil_images:
|
36 |
+
pred = predict_image(image, processor, model)
|
37 |
total_real += pred["real"]
|
38 |
total_fake += pred["fake"]
|
39 |
|