Rohit1412 commited on
Commit
6f17daf
·
verified ·
1 Parent(s): 4257bfe

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -14
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 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
 
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