Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,25 +1,33 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
|
|
|
|
4 |
video_model = pipeline("video-classification", model="Rohit1412/deepfakerohit2.0")
|
5 |
|
6 |
-
def
|
7 |
-
#
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
|
|
|
|
|
|
15 |
|
16 |
# Create Gradio interface
|
17 |
interface = gr.Interface(
|
18 |
-
fn=
|
19 |
-
inputs=gr.
|
20 |
-
outputs=
|
21 |
-
|
22 |
-
|
|
|
|
|
|
|
23 |
)
|
24 |
|
25 |
# Launch the interface
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
4 |
+
# Load the models for image and video classification
|
5 |
+
#image_model = pipeline("image-classification", model="Rohit1412/Deepfake", device=0)
|
6 |
video_model = pipeline("video-classification", model="Rohit1412/deepfakerohit2.0")
|
7 |
|
8 |
+
def classify_input(input_data):
|
9 |
+
# Check if the input is an image or a video
|
10 |
+
if isinstance(input_data, str) and input_data.endswith(('.mp4', '.mov', '.avi')):
|
11 |
+
# Classify the uploaded video
|
12 |
+
predictions = video_model(input_data)
|
13 |
+
# Create a dictionary of labels and their corresponding scores
|
14 |
+
result = {pred["label"]: pred["score"] for pred in predictions}
|
15 |
+
return result
|
16 |
+
else:
|
17 |
+
# Classify the uploaded image
|
18 |
+
predictions = image_model(input_data)
|
19 |
+
return predictions[0]['label'], predictions[0]['score']
|
20 |
|
21 |
# Create Gradio interface
|
22 |
interface = gr.Interface(
|
23 |
+
fn=classify_input,
|
24 |
+
inputs=gr.inputs.Audio(source="upload", type="filepath", label="Upload Image or Video"),
|
25 |
+
outputs=[
|
26 |
+
gr.Label(num_top_classes=3, label="Predictions"),
|
27 |
+
gr.Textbox(label="Confidence", visible=False) # Hide confidence for video output
|
28 |
+
],
|
29 |
+
title="Image and Video Classification App",
|
30 |
+
description="Upload an image or a video to classify its content. Note: The model is still under training; it may give incorrect outputs."
|
31 |
)
|
32 |
|
33 |
# Launch the interface
|