Update app.py
Browse files
app.py
CHANGED
|
@@ -1,36 +1,46 @@
|
|
| 1 |
-
import streamlit as st
|
| 2 |
from transformers import pipeline
|
| 3 |
-
|
|
|
|
| 4 |
import requests
|
| 5 |
-
from
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
image = Image.open(image_file)
|
| 15 |
-
results = model(image)
|
| 16 |
-
return results
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
if
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
for result in image_results:
|
| 30 |
-
st.write(f"{result['label']}: {result['score']*100:.2f}%")
|
| 31 |
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
detect_video(video_link)
|
|
|
|
|
|
|
| 1 |
from transformers import pipeline
|
| 2 |
+
import streamlit as st
|
| 3 |
+
import torch
|
| 4 |
import requests
|
| 5 |
+
from PIL import Image
|
| 6 |
+
from pytube import YouTube
|
| 7 |
+
import tempfile
|
| 8 |
+
|
| 9 |
+
def detect_image(image):
|
| 10 |
+
model = pipeline("image-classification", model="google/vit-base-patch16-224")
|
| 11 |
+
return model(image)
|
| 12 |
|
| 13 |
+
def detect_video(video_url):
|
| 14 |
+
yt = YouTube(video_url)
|
| 15 |
+
stream = yt.streams.filter(file_extension='mp4').first()
|
| 16 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix='.mp4') as tmp_file:
|
| 17 |
+
stream.download(filename=tmp_file.name)
|
| 18 |
+
video_path = tmp_file.name
|
| 19 |
+
return video_path
|
| 20 |
|
| 21 |
+
def main():
|
| 22 |
+
st.title("VerifiAI - Image & Video Authenticity Checker")
|
| 23 |
+
option = st.sidebar.selectbox("Select Option", ["Image Detection", "Video Detection"])
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
+
if option == "Image Detection":
|
| 26 |
+
uploaded_image = st.file_uploader("Upload an Image", type=["jpg", "jpeg", "png"])
|
| 27 |
+
if uploaded_image:
|
| 28 |
+
image = Image.open(uploaded_image)
|
| 29 |
+
st.image(image, caption="Uploaded Image", use_container_width=True)
|
| 30 |
+
with st.spinner("Analyzing Image..."):
|
| 31 |
+
results = detect_image(image)
|
| 32 |
+
for result in results:
|
| 33 |
+
st.write(f"{result['label']}: {result['score']*100:.2f}%")
|
| 34 |
|
| 35 |
+
elif option == "Video Detection":
|
| 36 |
+
video_url = st.text_input("Enter YouTube Video Link")
|
| 37 |
+
if video_url:
|
| 38 |
+
st.video(video_url)
|
| 39 |
+
with st.spinner("Analyzing Video..."):
|
| 40 |
+
video_path = detect_video(video_url)
|
| 41 |
+
st.success("Video downloaded for analysis. Video detection model coming soon.")
|
|
|
|
|
|
|
| 42 |
|
| 43 |
+
if __name__ == "__main__":
|
| 44 |
+
if not torch.cuda.is_available():
|
| 45 |
+
st.warning("CUDA not available. Running on CPU might be slower.")
|
| 46 |
+
main()
|
|
|