Spaces:
Sleeping
Sleeping
File size: 1,503 Bytes
6364b8e 063d7d0 6364b8e 759d503 063d7d0 759d503 1573304 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 38 39 40 41 42 43 44 45 46 47 48 49 50 |
import gradio as gr
import torch
from transformers import AutoFeatureExtractor, AutoModelForImageClassification, pipeline
models=[
"Nahrawy/AIorNot",
"RishiDarkDevil/ai-image-det-resnet152",
"arnolfokam/ai-generated-image-detector",
]
pipe = pipeline("image-classification", "umm-maybe/AI-image-detector")
def image_classifier(image):
outputs = pipe(image)
results = {}
for result in outputs:
results[result['label']] = result['score']
return results
#demo = gr.Interface(fn=image_classifier, inputs=gr.Image(type="pil"), outputs="label", title=title, description=description)
#demo.launch(show_api=False)
def aiornot(image,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() |