File size: 1,471 Bytes
373e186
49babfe
 
93a4013
49babfe
 
373e186
49babfe
a64f4ed
 
 
 
 
 
373e186
a64f4ed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49babfe
 
f83a3a3
 
 
333fd10
49babfe
4744348
a64f4ed
 
5dde09c
a64f4ed
5dde09c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import gradio as gr
from PIL import Image
from vit_model_test import CustomModel

# Initialize the model
model = CustomModel()

def predict(image: Image.Image):
    try:
        label, confidence = model.predict(image)
        result = "AI image" if label == 1 else "Real image"
        return result, f"Confidence: {confidence:.2f}%"
    except Exception as e:
        return "Error in prediction", str(e)

# Custom HTML and CSS to replace the logo with a video
custom_html = """
<style>
    /* Hide the default logo */
    .gradio-logo {
        display: none;
    }
    /* Center the video container */
    .loading-container {
        text-align: center;
        margin-top: 20px;
    }
    .loading-container video {
        width: 320px; /* Adjust video size */
        height: auto; /* Maintain aspect ratio */
    }
</style>
<div class="loading-container">
    <video autoplay muted loop>
        <source src="load_screen.mp4" type="video/mp4">
        Your browser does not support the video tag.
    </video>
    <div>Processing, please wait...</div>
</div>
"""

# Define the Gradio interface
demo = gr.Interface(
    fn=predict,
    inputs=gr.Image(type="pil"),
    outputs=[gr.Textbox(), gr.Textbox()],
    title="Vision Transformer Model",
    description="Upload an image to classify it using the Vision Transformer model."
)

# Inject the custom HTML to show the video instead of the logo
demo.load(custom_html)

# Launch the Gradio interface
demo.launch()