File size: 5,544 Bytes
5e014de
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
import gradio as gr
from PIL import Image
import numpy as np
import os
from face_cropper import detect_and_label_faces
# Define a custom function to convert an image to grayscale
def to_grayscale(input_image):
    grayscale_image = Image.fromarray(np.array(input_image).mean(axis=-1).astype(np.uint8))
    return grayscale_image


description_markdown = """
# Fake Face Detection tool from TrustWorthy BiometraVision Lab IISER Bhopal

## Usage
This tool expects a face image as input. Upon submission, it will process the image and provide an output with bounding boxes drawn on the face. Alongside the visual markers, the tool will give a detection result indicating whether the face is fake or real.

## Disclaimer
Please note that this tool is for research purposes only and may not always be 100% accurate. Users are advised to exercise discretion and supervise the tool's usage accordingly.

## Licensing and Permissions
This tool has been developed solely for research and demonstrative purposes. Any commercial utilization of this tool is strictly prohibited unless explicit permission has been obtained from the developers.

## Developer Contact
For further inquiries or permissions, you can reach out to the developer through the following social media accounts:
- [LAB Webpage](https://sites.google.com/iiitd.ac.in/agarwalakshay/labiiserb?authuser=0)
- [LinkedIn](https://www.linkedin.com/in/shivam-shukla-0a50ab1a2/)
- [GitHub](https://github.com/SaShukla090)
"""




# Create the Gradio app
app = gr.Interface(
    fn=detect_and_label_faces,
    inputs=gr.Image(type="pil"),
    outputs="image",
    # examples=[
    #     "path_to_example_image_1.jpg",
    #     "path_to_example_image_2.jpg"
    # ]
    examples=[
        os.path.join("Examples", image_name) for image_name in os.listdir("Examples")
    ],
    title="Fake Face Detection",
    description=description_markdown,
)

# Run the app
app.launch()

































# import torch.nn.functional as F
# import torch
# import torch.nn as nn
# import torch.optim as optim
# from torch.utils.data import DataLoader
# from sklearn.metrics import accuracy_score, precision_recall_fscore_support
# from torch.optim.lr_scheduler import CosineAnnealingLR
# from tqdm import tqdm
# import warnings
# warnings.filterwarnings("ignore")

# from utils.config import cfg
# from dataset.real_n_fake_dataloader import Extracted_Frames_Dataset
# from utils.data_transforms import get_transforms_train, get_transforms_val
# from net.Multimodalmodel import Image_n_DCT
# import gradio as gr




# import os
# import json
# import torch
# from torchvision import transforms
# from torch.utils.data import DataLoader, Dataset
# from PIL import Image
# import numpy as np
# import pandas as pd
# import cv2
# import argparse






# from sklearn.metrics import classification_report, confusion_matrix
# import matplotlib.pyplot as plt
# import seaborn as sns



    

# class Test_Dataset(Dataset):
#     def __init__(self, test_data_path = None, transform = None, image = None):
#         """
#         Args:   
#         returns:
#             """
        
#         if test_data_path is None and image is not None:
#             self.dataset = [(image, 2)]
#             self.transform = transform

#     def __len__(self):
#         return len(self.dataset)

#     def __getitem__(self, idx):
#         sample_input = self.get_sample_input(idx)
#         return sample_input
    

#     def get_sample_input(self, idx):
#         rgb_image = self.get_rgb_image(self.dataset[idx][0])
#         dct_image = self.compute_dct_color(self.dataset[idx][0])
#         # label = self.get_label(idx)
#         sample_input = {"rgb_image": rgb_image, "dct_image": dct_image}

#         return sample_input
    

#     def get_rgb_image(self, rgb_image):
#         # rgb_image_path = self.dataset[idx][0]
#         # rgb_image = Image.open(rgb_image_path)
#         if self.transform:
#             rgb_image = self.transform(rgb_image)
#         return rgb_image
    
#     def get_dct_image(self, idx):
#         rgb_image_path = self.dataset[idx][0]
#         rgb_image = cv2.imread(rgb_image_path)
#         dct_image = self.compute_dct_color(rgb_image)
#         if self.transform:
#             dct_image = self.transform(dct_image)
        
#         return dct_image
    
#     def get_label(self, idx):
#         return self.dataset[idx][1]
    

#     def compute_dct_color(self, image):
#         image_float = np.float32(image)
#         dct_image = np.zeros_like(image_float)
#         for i in range(3):  
#             dct_image[:, :, i] = cv2.dct(image_float[:, :, i])
#         if self.transform:
#             dct_image = self.transform(dct_image)
#         return dct_image
    

# device = torch.device("cpu")
# # print(device)
# model = Image_n_DCT()
# model.load_state_dict(torch.load('weights/best_model.pth', map_location = device))
# model.to(device)
# model.eval()


# def classify(image):
#     test_dataset = Test_Dataset(transform = get_transforms_val(), image = image)
#     inputs = test_dataset[0]
#     rgb_image, dct_image = inputs['rgb_image'].to(device), inputs['dct_image'].to(device)
#     output = model(rgb_image.unsqueeze(0), dct_image.unsqueeze(0))
#     # _, predicted = torch.max(output.data, 1)
#     # print(f"the face is {'real' if predicted==1 else 'fake'}")
#     return {'Fake': output[0][0], 'Real': output[0][1]}

# iface = gr.Interface(fn=classify, inputs="image", outputs="label")
# if __name__ == "__main__":
#     iface.launch()