Rohit1412 commited on
Commit
c452545
·
verified ·
1 Parent(s): 861b324

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -33
app.py CHANGED
@@ -1,44 +1,29 @@
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)
 
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)