Omnibus commited on
Commit
6364b8e
1 Parent(s): 8e144a7

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -0
app.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ from transformers import AutoFeatureExtractor, AutoModelForImageClassification
4
+
5
+ def aiornot(img):
6
+ labels = ["Real", "AI"]
7
+ feature_extractor = AutoFeatureExtractor.from_pretrained("Nahrawy/AIorNot")
8
+ model = AutoModelForImageClassification.from_pretrained("Nahrawy/AIorNot")
9
+
10
+ input = feature_extractor(image, return_tensors="pt")
11
+ with torch.no_grad():
12
+ outputs = model(**input)
13
+ logits = outputs.logits
14
+ prediction = logits.argmax(-1).item()
15
+ label = labels[prediction]
16
+ return label
17
+
18
+ with gr.Blocks() as app:
19
+ with gr.Row():
20
+ inp = gr.Image()
21
+ btn = gr.Button()
22
+ outp = gr.Textbox()
23
+ btn.click(aiornot,inp,outp)
24
+ app.launch()