import gradio as gr from torch.nn import functional as F from model_loader import ModelType, type_to_transforms, type_to_loaded_model def get_y(model_type, model, image): if model_type == ModelType.SYNTHETIC_DETECTOR_V2: return model.forward(image.unsqueeze(0).to("cpu")) return model.forward(image[None, ...]) def predict(raw_image, model_name): if model_name not in ModelType.get_list(): return {'error': [0.]} model_type = ModelType[str(model_name).upper()].value model = type_to_loaded_model[model_type] tfm = type_to_transforms[model_type] image = tfm(raw_image) y = get_y(model_type, model, image) y_1 = F.softmax(y, dim=1)[:, 1].cpu().detach().numpy() y_2 = F.softmax(y, dim=1)[:, 0].cpu().detach().numpy() return {'created by AI': y_1.tolist(), 'created by human': y_2.tolist()} general_examples = [ ["images/general/img_1.jpg"], ["images/general/img_2.jpg"], ["images/general/img_3.jpg"], ["images/general/img_4.jpg"], ["images/general/img_5.jpg"], ["images/general/img_6.jpg"], ["images/general/img_7.jpg"], ["images/general/img_8.jpg"], ["images/general/img_9.jpg"], ["images/general/img_10.jpg"], ] optic_examples = [ ["images/optic/img_1.jpg"], ["images/optic/img_2.jpg"], ["images/optic/img_3.jpg"], ["images/optic/img_4.jpg"], ["images/optic/img_5.jpg"], ] famous_deepfake_examples = [ ["images/famous_deepfakes/img_1.jpg"], ["images/famous_deepfakes/img_2.jpg"], ["images/famous_deepfakes/img_3.jpg"], ["images/famous_deepfakes/img_4.webp"], ] with gr.Blocks(theme=gr.themes.Soft()) as demo: gr.Markdown( """
*_200M
models are based on convnext_large_mlp.clip_laion2b_soup_ft_in12k_in1k_384
with image size 640x640
*_5M
models are based on tf_mobilenetv3_large_100.in1k
with image size 224x224
synthetic_detector_2.0
models are based on convnext_large_mlp.clip_laion2b_soup_ft_in12k_in1k_384
with image size 384x384