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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -23
app.py CHANGED
@@ -1,34 +1,25 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
-
5
- # Load the models for image and video classification
6
- #image_model = pipeline("image-classification", model="Rohit1412/Deepfake", device=0)
7
  video_model = pipeline("video-classification", model="Rohit1412/deepfakerohit2.0")
8
 
9
- def classify_input(input_data):
10
- # Check if the input is an image or a video
11
- if isinstance(input_data, str) and input_data.endswith(('.mp4', '.mov', '.avi')):
12
- # Classify the uploaded video
13
- predictions = video_model(input_data)
14
- # Create a dictionary of labels and their corresponding scores
15
- result = {pred["label"]: pred["score"] for pred in predictions}
16
- return result
17
- else:
18
- # Classify the uploaded image
19
- predictions = image_model(input_data)
20
- return predictions[0]['label'], predictions[0]['score']
21
 
22
  # Create Gradio interface
23
  interface = gr.Interface(
24
- fn=classify_input,
25
- inputs=gr.inputs.Audio(source="upload", type="filepath", label="Upload Image or Video"),
26
- outputs=[
27
- gr.Label(num_top_classes=3, label="Predictions"),
28
- gr.Textbox(label="Confidence", visible=False) # Hide confidence for video output
29
- ],
30
- title="Image and Video Classification App",
31
- description="Upload an image or a video to classify its content. Note: The model is still under training; it may give incorrect outputs."
32
  )
33
 
34
  # Launch the interface
 
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