Spaces:
Runtime error
Runtime error
criticalDanger
commited on
Commit
•
ac0c654
1
Parent(s):
3dc4d0a
Update app.py
Browse files
app.py
CHANGED
@@ -5,32 +5,17 @@ from transformers import pipeline
|
|
5 |
image_model = pipeline("image-classification", model="dima806/deepfake_vs_real_image_detection")
|
6 |
|
7 |
# Define the prediction function
|
8 |
-
def predict(
|
9 |
-
|
10 |
-
|
11 |
-
if model_choice == "Audio Deepfake Detection":
|
12 |
-
result = audio_model(audio)
|
13 |
-
elif model_choice == "Image Deepfake Detection":
|
14 |
-
result = image_model(image)
|
15 |
-
else:
|
16 |
-
return {"error": "Invalid model choice"}
|
17 |
-
|
18 |
-
print("Raw prediction result:", result) # Debugging statement
|
19 |
# Convert the result to the expected format
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
except Exception as e:
|
24 |
print("Error during prediction:", e) # Debugging statement
|
25 |
return {"error": str(e)}
|
26 |
|
27 |
-
# Update interface based on the selected model
|
28 |
-
def update_interface(model_choice):
|
29 |
-
if model_choice == "Audio Deepfake Detection":
|
30 |
-
return gr.update(visible=True), gr.update(visible=False)
|
31 |
-
elif model_choice == "Image Deepfake Detection":
|
32 |
-
return gr.update(visible=False), gr.update(visible=True)
|
33 |
-
|
34 |
# Create Gradio interface
|
35 |
with gr.Blocks() as iface:
|
36 |
image_input = gr.Image(type="filepath", label="Upload Image File", visible=False)
|
|
|
5 |
image_model = pipeline("image-classification", model="dima806/deepfake_vs_real_image_detection")
|
6 |
|
7 |
# Define the prediction function
|
8 |
+
def predict(image):
|
9 |
+
result = image_model(image)
|
10 |
+
print("Raw prediction result:", result) # Debugging statement
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
# Convert the result to the expected format
|
12 |
+
output = {item['label']: item['score'] for item in result}
|
13 |
+
print("Formatted prediction result:", output) # Debugging statement
|
14 |
+
return output
|
15 |
except Exception as e:
|
16 |
print("Error during prediction:", e) # Debugging statement
|
17 |
return {"error": str(e)}
|
18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
# Create Gradio interface
|
20 |
with gr.Blocks() as iface:
|
21 |
image_input = gr.Image(type="filepath", label="Upload Image File", visible=False)
|