Spaces:
Sleeping
Sleeping
File size: 1,092 Bytes
6364b8e 759d503 6364b8e 759d503 3de46d7 6364b8e 759d503 3de46d7 759d503 6364b8e 759d503 6364b8e |
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 |
import gradio as gr
import torch
from transformers import AutoFeatureExtractor, AutoModelForImageClassification
models=[
"Nahrawy/AIorNot",
"RishiDarkDevil/ai-image-det-resnet152",
"arnolfokam/ai-generated-image-detector",
]
def aiornot(img,mod_choose):
labels = ["Real", "AI"]
#feature_extractor = AutoFeatureExtractor.from_pretrained("microsoft/resnet-50")
mod=models[int(mod_choose)]
feature_extractor = AutoFeatureExtractor.from_pretrained("Nahrawy/AIorNot")
model = AutoModelForImageClassification.from_pretrained("Nahrawy/AIorNot")
input = feature_extractor(image, return_tensors="pt")
with torch.no_grad():
outputs = model(**input)
logits = outputs.logits
prediction = logits.argmax(-1).item()
label = labels[prediction]
return label
with gr.Blocks() as app:
with gr.Row():
with gr.Column():
inp = gr.Image(type='filepath')
mod_choose=gr.Number(value=0)
btn = gr.Button()
outp = gr.Textbox()
btn.click(aiornot,[inp,mod_choose],outp)
app.launch() |