File size: 2,186 Bytes
00a7a0f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import gradio as gr
from transformers import pipeline

# Initialize the classification pipeline with your private model and token
pipe = pipeline(
    task="image-classification",
    model="scfive/ESPR-Weapon-Classification_App",  # Replace with your model repository identifier
)

# Define custom CSS to style the header, footer, and main container
custom_css = """
/* Header styling */
#header {
    background-color: #003366;
    color: #ffffff;
    padding: 20px;
    text-align: center;
    font-family: 'Arial', sans-serif;
}
#header img {
    max-width: 100px;
    vertical-align: middle;
    margin-right: 15px;
}

/* Footer styling */
#footer {
    background-color: #f0f4f8;
    color: #003366;
    padding: 10px;
    text-align: center;
    font-family: 'Arial', sans-serif;
    font-size: 0.9em;
}

/* Main container styling */
.main-container {
    padding: 20px;
    margin: auto;
    max-width: 800px;
}

/* Button styling */
button {
    font-size: 1em;
    padding: 10px 20px;
}
"""

# Define the image classification function
def classify_image(image_path):
    result = pipe(image_path)
    # Return the label from the first result
    return result[0]['label']

# Build the Gradio Blocks layout
with gr.Blocks(css=custom_css) as demo:
    # Header: includes a logo and the app name
    gr.HTML("""
    <div id="header">
      <img src="https://via.placeholder.com/100" alt="Logo"/>
      <span style="font-size: 2em; font-weight: bold;">Weapon Classifier</span>
    </div>
    """)
    
    # Main content area with an image input and text output
    with gr.Column(elem_classes="main-container"):
        gr.HTML("<h2>Upload an image to classify the weapon</h2>")
        with gr.Row():
            image_input = gr.Image(type="filepath", label="Weapon Image")
            output_text = gr.Textbox(label="Classification Result")
        btn = gr.Button("Classify")
        btn.click(fn=classify_image, inputs=image_input, outputs=output_text)
    
    # Footer: explains the app is for game use only
    gr.HTML("""
    <div id="footer">
      This application is intended for game use only. © 2025 My Company.
    </div>
    """)

# Launch the app
demo.launch()