Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,44 +1,29 @@
|
|
1 |
from transformers import pipeline
|
2 |
import gradio as gr
|
3 |
|
4 |
-
|
5 |
-
image_model = pipeline("image-classification", model="Rohit1412/Deepfake", device=0)
|
6 |
-
video_model = pipeline("video-classification", model="Rohit1412/deepfakerohit2.0")
|
7 |
|
8 |
-
|
9 |
-
try:
|
10 |
-
predictions = image_model(image)
|
11 |
-
result = {pred["label"]: pred["score"] for pred in predictions}
|
12 |
-
return result
|
13 |
-
except Exception as e:
|
14 |
-
return {"error": f"An error occurred during image classification Make sure you choose the correct model: {str(e)}"}
|
15 |
|
16 |
def classify_video(video):
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
return {"error": f"An error occurred during video classification Make sure you choose the correct model: {str(e)}"}
|
23 |
-
|
24 |
-
# Create Gradio Blocks interface
|
25 |
-
with gr.Blocks() as app:
|
26 |
-
gr.Markdown("# Video and Image Classification App")
|
27 |
|
28 |
-
|
29 |
-
|
30 |
-
image_output = gr.Label(num_top_classes=3, label="Predictions")
|
31 |
-
image_button = gr.Button("Classify Image")
|
32 |
-
|
33 |
-
image_button.click(fn=classify_image, inputs=image_input, outputs=image_output)
|
34 |
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
|
|
|
|
41 |
|
42 |
# Launch the interface
|
43 |
if __name__ == "__main__":
|
44 |
-
|
|
|
1 |
from transformers import pipeline
|
2 |
import gradio as gr
|
3 |
|
4 |
+
from transformers import pipeline
|
|
|
|
|
5 |
|
6 |
+
video_model = pipeline("video-classification", model="Rohit1412/deepfakerohit2.0")
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
def classify_video(video):
|
9 |
+
# Classify the uploaded video and return the results
|
10 |
+
predictions = video_model(video)
|
11 |
+
|
12 |
+
# Create a dictionary of labels and their corresponding scores
|
13 |
+
result = {pred["label"]: pred["score"] for pred in predictions}
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
+
# Return the result dictionary
|
16 |
+
return result
|
|
|
|
|
|
|
|
|
17 |
|
18 |
+
# Create Gradio interface
|
19 |
+
interface = gr.Interface(
|
20 |
+
fn=classify_video,
|
21 |
+
inputs=gr.Video(label="Upload Video"),
|
22 |
+
outputs=gr.Label(num_top_classes=3, label="Predictions"),
|
23 |
+
title="Video Classification App",
|
24 |
+
description="Upload a video to classify its content."
|
25 |
+
)
|
26 |
|
27 |
# Launch the interface
|
28 |
if __name__ == "__main__":
|
29 |
+
interface.launch(debug=True)
|