Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,49 +1,25 @@
|
|
1 |
import gradio as gr
|
2 |
from PIL import Image
|
3 |
from vit_model_test import CustomModel
|
4 |
-
import time
|
5 |
|
6 |
# Initialize the model
|
7 |
model = CustomModel()
|
8 |
|
9 |
def predict(image: Image.Image):
|
10 |
-
|
11 |
-
time.sleep(5) # 住讬诪讜诇爪讬讛 砖诇 讝诪谉 注讬讘讜讚
|
12 |
label, confidence = model.predict(image)
|
13 |
result = "AI image" if label == 1 else "Real image"
|
14 |
return result, f"Confidence: {confidence:.2f}%"
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
transition: background-color 0.3s ease;
|
29 |
-
}
|
30 |
-
.gr-button:hover {
|
31 |
-
background-color: #45a049;
|
32 |
-
}
|
33 |
-
""") as demo:
|
34 |
-
with gr.Row():
|
35 |
-
image_input = gr.Image(type="pil", label="Upload an image")
|
36 |
-
animation = gr.Video("https://cdn-uploads.huggingface.co/production/uploads/66d6f1b3b50e35e1709bfdf7/x7Ud8PO9QPfmrTvBVcCKE.mp4", visible=False)
|
37 |
-
|
38 |
-
output_label = gr.Textbox(label="Classification Result", interactive=False, visible=False)
|
39 |
-
output_confidence = gr.Textbox(label="Confidence", interactive=False, visible=False)
|
40 |
-
|
41 |
-
image_input.change(loading_animation, inputs=image_input, outputs=[animation, output_label, output_confidence])
|
42 |
-
image_input.change(show_results, inputs=image_input, outputs=[animation, output_label, output_confidence])
|
43 |
-
|
44 |
-
# 讛讜住驻转 讻驻转讜专
|
45 |
-
submit_button = gr.Button("Submit")
|
46 |
-
submit_button.click(predict, inputs=image_input, outputs=[output_label, output_confidence])
|
47 |
-
|
48 |
-
# 讛砖拽转 讛诪诪砖拽
|
49 |
-
demo.launch()
|
|
|
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 |
+
# Launch the Gradio interface
|
25 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|