Rohit1412 commited on
Commit
c820f6a
·
verified ·
1 Parent(s): d60c7b3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -17
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
- # Classify the uploaded video and return the results
8
- predictions = video_model(video)
9
-
10
- # Create a dictionary of labels and their corresponding scores
11
- result = {pred["label"]: pred["score"] for pred in predictions}
 
 
 
 
 
12
 
13
- # Return the result dictionary
14
- return result
 
 
 
 
15
 
16
- # Create Gradio interface
17
- interface = gr.Interface(
18
- fn=classify_video,
19
- inputs=gr.Video(label="Upload Video"),
20
- outputs=gr.Label(num_top_classes=3, label="Predictions"),
21
- title="Video Classification App",
22
- description="Upload a video to classify its content."
23
- )
24
 
25
  # Launch the interface
26
  if __name__ == "__main__":
27
- interface.launch(debug=True)
 
 
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)