Spaces:
Sleeping
Sleeping
Upload 3 files
Browse files- app.py +49 -0
- requirements.txt +3 -0
- yolo_trained_model.zip +3 -0
app.py
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import os
|
| 3 |
+
import zipfile
|
| 4 |
+
from ultralytics import YOLO
|
| 5 |
+
from PIL import Image
|
| 6 |
+
import numpy as np
|
| 7 |
+
|
| 8 |
+
# Title
|
| 9 |
+
st.title("π Deepfake Image Detection using YOLOv8")
|
| 10 |
+
|
| 11 |
+
# Extract model if not extracted
|
| 12 |
+
model_dir = "yolo_model"
|
| 13 |
+
zip_path = "yolo_trained_model.zip"
|
| 14 |
+
|
| 15 |
+
if not os.path.exists(model_dir):
|
| 16 |
+
with zipfile.ZipFile(zip_path, 'r') as zip_ref:
|
| 17 |
+
zip_ref.extractall(model_dir)
|
| 18 |
+
st.success("β
Model unzipped successfully.")
|
| 19 |
+
|
| 20 |
+
# Load model
|
| 21 |
+
model_files = [f for f in os.listdir(model_dir) if f.endswith('.pt')]
|
| 22 |
+
if model_files:
|
| 23 |
+
model_path = os.path.join(model_dir, model_files[0])
|
| 24 |
+
model = YOLO(model_path)
|
| 25 |
+
st.success("β
YOLOv8 Model loaded!")
|
| 26 |
+
else:
|
| 27 |
+
st.error("β No .pt file found in the unzipped model folder.")
|
| 28 |
+
|
| 29 |
+
# Upload image
|
| 30 |
+
uploaded_image = st.file_uploader("π Upload an Image", type=["jpg", "jpeg", "png"])
|
| 31 |
+
|
| 32 |
+
if uploaded_image is not None:
|
| 33 |
+
image = Image.open(uploaded_image).convert("RGB")
|
| 34 |
+
st.image(image, caption="Uploaded Image", use_column_width=True)
|
| 35 |
+
|
| 36 |
+
# Prediction button
|
| 37 |
+
if st.button("Detect Deepfake"):
|
| 38 |
+
with st.spinner("Analyzing..."):
|
| 39 |
+
results = model.predict(image)
|
| 40 |
+
|
| 41 |
+
# Draw boxes on the image
|
| 42 |
+
result_image = results[0].plot() # This plots bounding boxes
|
| 43 |
+
|
| 44 |
+
# Convert to PIL Image and display
|
| 45 |
+
result_pil = Image.fromarray(result_image[..., ::-1]) # BGR to RGB
|
| 46 |
+
st.image(result_pil, caption="Detection Result", use_column_width=True)
|
| 47 |
+
|
| 48 |
+
# Optional: Show label info
|
| 49 |
+
st.write("π Detected Labels:", results[0].names)
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit
|
| 2 |
+
ultralytics
|
| 3 |
+
pillow
|
yolo_trained_model.zip
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:9e1904c908edcf867b661b1f9019d8e51ab1fe8372c9587be8122917d7383eb8
|
| 3 |
+
size 11329168
|