Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -6,18 +6,40 @@ from vit_model_test import CustomModel
|
|
6 |
model = CustomModel()
|
7 |
|
8 |
def predict(image: Image.Image):
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
else:
|
16 |
-
result = "Real image"
|
17 |
-
|
18 |
-
return result, f"Confidence: {confidence:.2f}%"
|
19 |
|
20 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
demo = gr.Interface(
|
22 |
fn=predict,
|
23 |
inputs=gr.Image(type="pil"),
|
@@ -26,6 +48,8 @@ demo = gr.Interface(
|
|
26 |
description="Upload an image to classify it using the Vision Transformer model."
|
27 |
)
|
28 |
|
29 |
-
#
|
|
|
30 |
|
|
|
31 |
demo.launch()
|
|
|
6 |
model = CustomModel()
|
7 |
|
8 |
def predict(image: Image.Image):
|
9 |
+
try:
|
10 |
+
label, confidence = model.predict(image)
|
11 |
+
result = "AI image" if label == 1 else "Real image"
|
12 |
+
return result, f"Confidence: {confidence:.2f}%"
|
13 |
+
except Exception as e:
|
14 |
+
return "Error in prediction", str(e)
|
|
|
|
|
|
|
|
|
15 |
|
16 |
+
# Custom HTML and CSS to replace the logo with a video
|
17 |
+
custom_html = """
|
18 |
+
<style>
|
19 |
+
/* Hide the default logo */
|
20 |
+
.gradio-logo {
|
21 |
+
display: none;
|
22 |
+
}
|
23 |
+
/* Center the video container */
|
24 |
+
.loading-container {
|
25 |
+
text-align: center;
|
26 |
+
margin-top: 20px;
|
27 |
+
}
|
28 |
+
.loading-container video {
|
29 |
+
width: 320px; /* Adjust video size */
|
30 |
+
height: auto; /* Maintain aspect ratio */
|
31 |
+
}
|
32 |
+
</style>
|
33 |
+
<div class="loading-container">
|
34 |
+
<video autoplay muted loop>
|
35 |
+
<source src="load_screen.mp4" type="video/mp4">
|
36 |
+
Your browser does not support the video tag.
|
37 |
+
</video>
|
38 |
+
<div>Processing, please wait...</div>
|
39 |
+
</div>
|
40 |
+
"""
|
41 |
+
|
42 |
+
# Define the Gradio interface
|
43 |
demo = gr.Interface(
|
44 |
fn=predict,
|
45 |
inputs=gr.Image(type="pil"),
|
|
|
48 |
description="Upload an image to classify it using the Vision Transformer model."
|
49 |
)
|
50 |
|
51 |
+
# Inject the custom HTML to show the video instead of the logo
|
52 |
+
demo.load(custom_html)
|
53 |
|
54 |
+
# Launch the Gradio interface
|
55 |
demo.launch()
|