ZappY-AI commited on
Commit
104362c
·
1 Parent(s): 79958cf

some changes

Browse files
Files changed (3) hide show
  1. app.py +8 -15
  2. cheetah.jpg +0 -0
  3. horse.jpg +0 -0
app.py CHANGED
@@ -5,12 +5,12 @@ import torchvision.models as models
5
  from torchvision.transforms import v2 as transforms
6
  import os
7
 
 
8
  class_names = ['AI-Generated Image', "Real/Non-AI-Generated Image"]
9
 
10
- # Downloading the model
11
- # model = models.vit_b_16()
12
  weights_path = "FaKe-ViT-B16.pth"
13
- model = torch.load(weights_path).to("cpu")
14
  model.eval()
15
  # Preprocessing the image
16
  preprocess = transforms.Compose([
@@ -22,7 +22,6 @@ preprocess = transforms.Compose([
22
 
23
  # Define the prediction function
24
  def predict_image(image):
25
- # inp = Image.fromarray(inp.astype('uint8'), 'RGB')
26
  image = preprocess(image)
27
  if image.shape[0] != 3:
28
  image = image[:3, :, :]
@@ -32,8 +31,6 @@ def predict_image(image):
32
  output1 = torch.argmax(torch.softmax(output,dim=1),dim=1).item()
33
  return class_names[output1]
34
 
35
- # def image_mod(image):
36
- # return image.rotate(45)
37
 
38
 
39
  demo = gr.Interface(
@@ -41,17 +38,13 @@ demo = gr.Interface(
41
  gr.Image(image_mode="RGB",type="pil"),
42
  "text",
43
  flagging_options=["incorrect prediction"],
44
- # examples=[
45
- # os.path.join(os.path.dirname(__file__), "images/cheetah1.jpg"),
46
- # os.path.join(os.path.dirname(__file__), "images/lion.jpg"),
47
- # os.path.join(os.path.dirname(__file__), "images/logo.png"),
48
- # os.path.join(os.path.dirname(__file__), "images/tower.jpg"),
49
- # ],
50
  title="FaKe-ViT-B/16: AI-Generated Image Detection using Vision Transformer(ViT-B/16)",
51
  description="This is a demo to detect AI-Generated images using Vision Transformer(ViT-B/16). Upload an image and the model will predict whether the image is AI-Generated or Real",
52
- css=""".gr-header, .gr-text {
53
- font-size: 20px;
54
- }""",
55
  article=" \nBased on the paper:'An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale', Alexey et al.\nDataset: 'Fake or Real competition dataset' at https://huggingface.co/datasets/mncai/Fake_or_Real_Competition_Dataset"
56
  )
57
 
 
5
  from torchvision.transforms import v2 as transforms
6
  import os
7
 
8
+ # Define the class names
9
  class_names = ['AI-Generated Image', "Real/Non-AI-Generated Image"]
10
 
11
+ # Load the model
 
12
  weights_path = "FaKe-ViT-B16.pth"
13
+ model = torch.load(weights_path, map_location=torch.device('cpu'))
14
  model.eval()
15
  # Preprocessing the image
16
  preprocess = transforms.Compose([
 
22
 
23
  # Define the prediction function
24
  def predict_image(image):
 
25
  image = preprocess(image)
26
  if image.shape[0] != 3:
27
  image = image[:3, :, :]
 
31
  output1 = torch.argmax(torch.softmax(output,dim=1),dim=1).item()
32
  return class_names[output1]
33
 
 
 
34
 
35
 
36
  demo = gr.Interface(
 
38
  gr.Image(image_mode="RGB",type="pil"),
39
  "text",
40
  flagging_options=["incorrect prediction"],
41
+ examples=[
42
+ os.path.join(os.path.dirname(__file__), "images/cheetah.jpg"),
43
+ os.path.join(os.path.dirname(__file__), "images/horse.jpg"),
44
+ os.path.join(os.path.dirname(__file__), "images/astronaut.png"),
45
+ ],
 
46
  title="FaKe-ViT-B/16: AI-Generated Image Detection using Vision Transformer(ViT-B/16)",
47
  description="This is a demo to detect AI-Generated images using Vision Transformer(ViT-B/16). Upload an image and the model will predict whether the image is AI-Generated or Real",
 
 
 
48
  article=" \nBased on the paper:'An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale', Alexey et al.\nDataset: 'Fake or Real competition dataset' at https://huggingface.co/datasets/mncai/Fake_or_Real_Competition_Dataset"
49
  )
50
 
cheetah.jpg ADDED
horse.jpg ADDED