Spaces:
Sleeping
Sleeping
App v2
Browse files
app.py
CHANGED
@@ -5,30 +5,29 @@ import gradio as gr
|
|
5 |
from transformers import pipeline
|
6 |
|
7 |
|
8 |
-
device =
|
9 |
|
10 |
# Loading in Model
|
11 |
model_name = "dima806/ai_vs_real_image_detection"
|
12 |
-
|
13 |
-
|
14 |
|
15 |
|
16 |
-
#Classification function
|
17 |
def classify_image(img: Image.Image):
|
18 |
-
|
19 |
-
results = model(inputs)
|
20 |
top = results[0]
|
21 |
label = top["label"]
|
22 |
score = top["score"]
|
23 |
return f"Prediction: {label} (Confidence: {score:.2f})"
|
24 |
|
25 |
-
|
26 |
-
|
27 |
-
# Interface
|
28 |
interface = gr.Interface(
|
29 |
fn=classify_image,
|
30 |
inputs=gr.Image(type="pil"),
|
31 |
outputs="text",
|
32 |
-
title="Real vs AI Image
|
33 |
-
description="
|
34 |
-
)
|
|
|
|
|
|
5 |
from transformers import pipeline
|
6 |
|
7 |
|
8 |
+
device = 0 if torch.cuda.is_available() else -1
|
9 |
|
10 |
# Loading in Model
|
11 |
model_name = "dima806/ai_vs_real_image_detection"
|
12 |
+
pipe = pipeline("image-classification", model=model_name, device = device)
|
13 |
+
|
14 |
|
15 |
|
16 |
+
# Classification function
|
17 |
def classify_image(img: Image.Image):
|
18 |
+
results = pipe(img)
|
|
|
19 |
top = results[0]
|
20 |
label = top["label"]
|
21 |
score = top["score"]
|
22 |
return f"Prediction: {label} (Confidence: {score:.2f})"
|
23 |
|
24 |
+
# Gradio interface
|
|
|
|
|
25 |
interface = gr.Interface(
|
26 |
fn=classify_image,
|
27 |
inputs=gr.Image(type="pil"),
|
28 |
outputs="text",
|
29 |
+
title="Real vs AI Image Detection",
|
30 |
+
description="Upload an image to see if it's REAL or AI-generated."
|
31 |
+
)
|
32 |
+
|
33 |
+
interface.launch()
|