Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,27 +1,44 @@
|
|
1 |
-
import gradio as gr
|
2 |
from transformers import pipeline
|
|
|
3 |
|
|
|
|
|
4 |
video_model = pipeline("video-classification", model="Rohit1412/deepfakerohit2.0")
|
5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
def classify_video(video):
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
-
|
14 |
-
|
|
|
|
|
|
|
|
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
description="Upload a video to classify its content."
|
23 |
-
)
|
24 |
|
25 |
# Launch the interface
|
26 |
if __name__ == "__main__":
|
27 |
-
|
|
|
|
|
1 |
from transformers import pipeline
|
2 |
+
import gradio as gr
|
3 |
|
4 |
+
# Load the models
|
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_image(image):
|
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 |
+
try:
|
18 |
+
predictions = video_model(video)
|
19 |
+
result = {pred["label"]: pred["score"] for pred in predictions}
|
20 |
+
return result
|
21 |
+
except Exception as e:
|
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 |
+
with gr.Tab("Image Classification"):
|
29 |
+
image_input = gr.Image(label="Upload Image")
|
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 |
+
with gr.Tab("Video Classification"):
|
36 |
+
video_input = gr.Video(label="Upload Video")
|
37 |
+
video_output = gr.Label(num_top_classes=3, label="Predictions")
|
38 |
+
video_button = gr.Button("Classify Video")
|
39 |
+
|
40 |
+
video_button.click(fn=classify_video, inputs=video_input, outputs=video_output)
|
|
|
|
|
41 |
|
42 |
# Launch the interface
|
43 |
if __name__ == "__main__":
|
44 |
+
app.launch(debug=True)
|