File size: 1,975 Bytes
2e17068 9ad2f73 2e17068 9ad2f73 2e17068 9ad2f73 2e17068 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
import gradio as gr
from helpers import load_video_from_url, detect_deepfake
theme = gr.themes.Default(
primary_hue="stone",
secondary_hue="blue",
neutral_hue="zinc",
spacing_size="md",
text_size="md",
font=[gr.themes.GoogleFont("IBM Plex Mono"), "system-ui"]
)
callback = gr.CSVLogger()
with gr.Blocks(theme=theme) as demo:
# DEFINE COMPONENTS
# Text box for inputting Youtube URL
urlInput = gr.Textbox(
label="YOUTUBE VIDEO URL",
value="https://www.youtube.com/watch?v=BmrUJhY9teE"
)
# Button for downloading the video and previewing sample frames
loadVideoBtn = gr.Button("Load Video")
# Text box for displaying video title
videoTitle = gr.Textbox(
label="VIDEO TITLE",
lines=1,
interactive=False
)
# Image Gallery for previewing sample frames
sampleFrames = gr.Gallery(
label="SAMPLE FRAMES",
elem_id="gallery",
columns=[3],
rows=[1],
object_fit="contain",
height="auto"
)
# Button for generating video prediction
predVideoBtn = gr.Button(value="Classify Video", visible=False)
# Label for displaying prediction
predOutput = gr.Label(
label="DETECTED LABEL (AND CONFIDENCE LEVEL)",
num_top_classes=2,
visible=False
)
# Button for flagging the output
flagBtn = gr.Button(value="Flag Output", visible=False)
# DEFINE FUNCTIONS
# Load video from URL, display sample frames, and enable prediction button
loadVideoBtn.click(fn=load_video_from_url, inputs=[urlInput], outputs=[videoTitle, sampleFrames, predVideoBtn, predOutput])
# Generate video prediction
predVideoBtn.click(fn=detect_deepfake, outputs=[predOutput, flagBtn])
# Define flag callback
callback.setup([urlInput], "flagged_data_points")
# Flag output
flagBtn.click(fn=lambda *args: callback.flag(args), inputs=[urlInput], outputs=None)
demo.launch()
|