VidGuard / app.py
TruthLens's picture
Update app.py
dc4f473 verified
raw
history blame
1.75 kB
from transformers import pipeline
import streamlit as st
import torch
import requests
from PIL import Image
from pytube import YouTube
import tempfile
def detect_image(image):
model = pipeline("image-classification", model="google/vit-base-patch16-224")
return model(image)
def detect_video(video_url):
yt = YouTube(video_url)
stream = yt.streams.filter(file_extension='mp4').first()
with tempfile.NamedTemporaryFile(delete=False, suffix='.mp4') as tmp_file:
stream.download(filename=tmp_file.name)
video_path = tmp_file.name
return video_path
def main():
st.title("VerifiAI - Image & Video Authenticity Checker")
option = st.sidebar.selectbox("Select Option", ["Image Detection", "Video Detection"])
if option == "Image Detection":
uploaded_image = st.file_uploader("Upload an Image", type=["jpg", "jpeg", "png"])
if uploaded_image:
image = Image.open(uploaded_image)
st.image(image, caption="Uploaded Image", use_container_width=True)
with st.spinner("Analyzing Image..."):
results = detect_image(image)
for result in results:
st.write(f"{result['label']}: {result['score']*100:.2f}%")
elif option == "Video Detection":
video_url = st.text_input("Enter YouTube Video Link")
if video_url:
st.video(video_url)
with st.spinner("Analyzing Video..."):
video_path = detect_video(video_url)
st.success("Video downloaded for analysis. Video detection model coming soon.")
if __name__ == "__main__":
if not torch.cuda.is_available():
st.warning("CUDA not available. Running on CPU might be slower.")
main()