Spaces:
Runtime error
Runtime error
Upload 2 files
Browse files- app.py +47 -0
- requirements.txt +3 -0
app.py
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# Load the models using pipeline
|
5 |
+
audio_model = pipeline("audio-classification", model="MelodyMachine/Deepfake-audio-detection-V2")
|
6 |
+
image_model = pipeline("image-classification", model="dima806/deepfake_vs_real_image_detection")
|
7 |
+
|
8 |
+
# Define the prediction function
|
9 |
+
def predict(audio, image, model_choice):
|
10 |
+
print("Data received:", audio if model_choice == "Audio Deepfake Detection" else image) # Debugging statement
|
11 |
+
try:
|
12 |
+
if model_choice == "Audio Deepfake Detection":
|
13 |
+
result = audio_model(audio)
|
14 |
+
elif model_choice == "Image Deepfake Detection":
|
15 |
+
result = image_model(image)
|
16 |
+
else:
|
17 |
+
return {"error": "Invalid model choice"}
|
18 |
+
|
19 |
+
print("Raw prediction result:", result) # Debugging statement
|
20 |
+
# Convert the result to the expected format
|
21 |
+
output = {item['label']: item['score'] for item in result}
|
22 |
+
print("Formatted prediction result:", output) # Debugging statement
|
23 |
+
return output
|
24 |
+
except Exception as e:
|
25 |
+
print("Error during prediction:", e) # Debugging statement
|
26 |
+
return {"error": str(e)}
|
27 |
+
|
28 |
+
# Update interface based on the selected model
|
29 |
+
def update_interface(model_choice):
|
30 |
+
if model_choice == "Audio Deepfake Detection":
|
31 |
+
return gr.update(visible=True), gr.update(visible=False)
|
32 |
+
elif model_choice == "Image Deepfake Detection":
|
33 |
+
return gr.update(visible=False), gr.update(visible=True)
|
34 |
+
|
35 |
+
# Create Gradio interface
|
36 |
+
with gr.Blocks() as iface:
|
37 |
+
model_choice = gr.Radio(choices=["Audio Deepfake Detection", "Image Deepfake Detection"], label="Select Model", value="Audio Deepfake Detection")
|
38 |
+
audio_input = gr.Audio(type="filepath", label="Upload Audio File")
|
39 |
+
image_input = gr.Image(type="filepath", label="Upload Image File", visible=False)
|
40 |
+
output = gr.Label()
|
41 |
+
|
42 |
+
model_choice.change(fn=update_interface, inputs=model_choice, outputs=[audio_input, image_input])
|
43 |
+
|
44 |
+
submit_button = gr.Button("Submit")
|
45 |
+
submit_button.click(fn=predict, inputs=[audio_input, image_input, model_choice], outputs=output)
|
46 |
+
|
47 |
+
iface.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
torch
|
2 |
+
gradio
|
3 |
+
transformers
|