Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,15 +1,26 @@
|
|
1 |
-
import
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from PIL import Image
|
3 |
+
from vit_model_test import CustomModel
|
4 |
+
|
5 |
+
# Initialize the model
|
6 |
+
model = CustomModel()
|
7 |
+
|
8 |
+
def predict(image: Image.Image):
|
9 |
+
|
10 |
+
label, confidence = model.predict(image)
|
11 |
+
result = "AI image" if label == 1 else "Real image"
|
12 |
+
return result, f"Confidence: {confidence:.2f}%"
|
13 |
+
|
14 |
+
|
15 |
+
# Define the Gradio interface
|
16 |
+
demo = gr.Interface(
|
17 |
+
fn=predict,
|
18 |
+
inputs=gr.Image(type="pil"),
|
19 |
+
outputs=[gr.Textbox(), gr.Textbox()],
|
20 |
+
title="Vision Transformer Model",
|
21 |
+
description="Upload an image to classify it using the Vision Transformer model."
|
22 |
+
)
|
23 |
+
|
24 |
+
|
25 |
+
# Launch the Gradio interface
|
26 |
+
demo.launch()
|