Update app.py
Browse files
app.py
CHANGED
@@ -1,20 +1,20 @@
|
|
1 |
import gradio as gr
|
2 |
-
from transformers import AutoModelForImageClassification, pipeline, AutoImageProcessor
|
3 |
from torchvision import transforms
|
4 |
|
5 |
-
model = AutoModelForImageClassification.from_pretrained("
|
6 |
-
image_processor = AutoImageProcessor.from_pretrained("
|
7 |
clf = pipeline(model=model, task="image-classification", image_processor=image_processor)
|
8 |
|
9 |
-
class_names = ['
|
10 |
|
11 |
def predict_image(img):
|
12 |
img = transforms.ToPILImage()(img)
|
13 |
-
img = transforms.Resize((
|
14 |
prediction=clf.predict(img)
|
15 |
return {class_names[i]: float(prediction[i]["score"]) for i in range(2)}
|
16 |
|
17 |
-
image = gr.Image(label="
|
18 |
label = gr.Label(num_top_classes=2)
|
19 |
|
20 |
-
gr.Interface(fn=predict_image, inputs=image, outputs=label, title="
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import AutoModelForImageClassification, pipeline, AutoImageProcessor, SwinForImageClassification
|
3 |
from torchvision import transforms
|
4 |
|
5 |
+
model = AutoModelForImageClassification.from_pretrained("haywoodsloan/ai-image-detector-deploy")
|
6 |
+
image_processor = AutoImageProcessor.from_pretrained("haywoodsloan/ai-image-detector-deploy")
|
7 |
clf = pipeline(model=model, task="image-classification", image_processor=image_processor)
|
8 |
|
9 |
+
class_names = ['artificial', 'real']
|
10 |
|
11 |
def predict_image(img):
|
12 |
img = transforms.ToPILImage()(img)
|
13 |
+
img = transforms.Resize((256,256))(img)
|
14 |
prediction=clf.predict(img)
|
15 |
return {class_names[i]: float(prediction[i]["score"]) for i in range(2)}
|
16 |
|
17 |
+
image = gr.Image(label="Image to Analyze", sources=['upload'])
|
18 |
label = gr.Label(num_top_classes=2)
|
19 |
|
20 |
+
gr.Interface(fn=predict_image, inputs=image, outputs=label, title="AI Generated Classification").launch()
|