|
import gradio as gr |
|
|
|
from transformers import ImageClassificationPipeline, AutoImageProcessor, AutoModelForImageClassification, ResNetForImageClassification |
|
|
|
|
|
import torch |
|
|
|
from transformers import pipeline |
|
|
|
feature_extractor = AutoImageProcessor.from_pretrained("artfan123/resnet-18-finetuned-ai-art") |
|
model = AutoModelForImageClassification.from_pretrained("artfan123/resnet-18-finetuned-ai-art") |
|
|
|
image_pipe = ImageClassificationPipeline(model=model, feature_extractor=feature_extractor) |
|
|
|
def classify_image(image): |
|
results = image_pipe(image) |
|
|
|
output = {} |
|
for prediction in results: |
|
predicted_label = prediction['label'] |
|
score = prediction['score'] |
|
output[predicted_label] = score |
|
return output |
|
|
|
image = gr.inputs.Image(type="pil") |
|
label = gr.outputs.Label(num_top_classes=2) |
|
examples = [['50.jpg'], ['344.jpg'],['24.jpg'], ['339.jpg'], ['105.jpg']] |
|
title = "AI Art Detector" |
|
description = "A deep learning model that detects whether an image is AI generated or human made. Upload image or use the example images below." |
|
gr.Interface(fn=classify_image, inputs=image, outputs=label, title=title, description=description, examples=examples, enable_queue=True).launch(debug=True) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|