Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,8 +2,9 @@ import keras
|
|
| 2 |
import numpy as np
|
| 3 |
import streamlit as st
|
| 4 |
import random
|
| 5 |
-
from PIL import Image
|
| 6 |
import os
|
|
|
|
|
|
|
| 7 |
from huggingface_hub import snapshot_download
|
| 8 |
|
| 9 |
def random_crop(img, min_size=160, max_size=2048, ratio=5/8):
|
|
@@ -22,6 +23,14 @@ def random_crop(img, min_size=160, max_size=2048, ratio=5/8):
|
|
| 22 |
bottom = top + crop_height
|
| 23 |
|
| 24 |
return img.crop((left, top, right, bottom))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
def get_prediction(img):
|
| 27 |
x = np.array(img)
|
|
@@ -37,15 +46,18 @@ model = keras.models.load_model(local_model_path)
|
|
| 37 |
|
| 38 |
st.title("Fake Detection")
|
| 39 |
|
| 40 |
-
file_name = st.file_uploader("Choose an image..."
|
| 41 |
|
| 42 |
if file_name is not None:
|
| 43 |
col1, col2 = st.columns(2)
|
| 44 |
-
|
| 45 |
image = Image.open(file_name)
|
|
|
|
| 46 |
if image.size != (200, 200) or image.mode != 'RGB':
|
| 47 |
image = random_crop(image)
|
| 48 |
image = image.resize((200, 200))
|
|
|
|
|
|
|
|
|
|
| 49 |
|
| 50 |
col1.image(image, use_column_width=True)
|
| 51 |
predictions = get_prediction(image)
|
|
|
|
| 2 |
import numpy as np
|
| 3 |
import streamlit as st
|
| 4 |
import random
|
|
|
|
| 5 |
import os
|
| 6 |
+
from PIL import Image
|
| 7 |
+
from io import BytesIO
|
| 8 |
from huggingface_hub import snapshot_download
|
| 9 |
|
| 10 |
def random_crop(img, min_size=160, max_size=2048, ratio=5/8):
|
|
|
|
| 23 |
bottom = top + crop_height
|
| 24 |
|
| 25 |
return img.crop((left, top, right, bottom))
|
| 26 |
+
|
| 27 |
+
def jpg_compression(img):
|
| 28 |
+
quality = random.randint(65, 100)
|
| 29 |
+
jpeg_image = BytesIO()
|
| 30 |
+
img.convert("RGB").save(jpeg_image, 'JPEG', quality=quality)
|
| 31 |
+
jpeg_image.seek(0)
|
| 32 |
+
compressed_img = Image.open(jpeg_image)
|
| 33 |
+
return compressed_img
|
| 34 |
|
| 35 |
def get_prediction(img):
|
| 36 |
x = np.array(img)
|
|
|
|
| 46 |
|
| 47 |
st.title("Fake Detection")
|
| 48 |
|
| 49 |
+
file_name = st.file_uploader("Choose an image...")
|
| 50 |
|
| 51 |
if file_name is not None:
|
| 52 |
col1, col2 = st.columns(2)
|
|
|
|
| 53 |
image = Image.open(file_name)
|
| 54 |
+
|
| 55 |
if image.size != (200, 200) or image.mode != 'RGB':
|
| 56 |
image = random_crop(image)
|
| 57 |
image = image.resize((200, 200))
|
| 58 |
+
|
| 59 |
+
if image.format != "JPEG":
|
| 60 |
+
image = jpg_compression(image)
|
| 61 |
|
| 62 |
col1.image(image, use_column_width=True)
|
| 63 |
predictions = get_prediction(image)
|