Spaces:
Runtime error
Runtime error
Upload app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Initialize the classification pipeline with your private model and token
|
| 5 |
+
pipe = pipeline(
|
| 6 |
+
task="image-classification",
|
| 7 |
+
model="scfive/ESPR-Weapon-Classification_App", # Replace with your model repository identifier
|
| 8 |
+
)
|
| 9 |
+
|
| 10 |
+
# Define custom CSS to style the header, footer, and main container
|
| 11 |
+
custom_css = """
|
| 12 |
+
/* Header styling */
|
| 13 |
+
#header {
|
| 14 |
+
background-color: #003366;
|
| 15 |
+
color: #ffffff;
|
| 16 |
+
padding: 20px;
|
| 17 |
+
text-align: center;
|
| 18 |
+
font-family: 'Arial', sans-serif;
|
| 19 |
+
}
|
| 20 |
+
#header img {
|
| 21 |
+
max-width: 100px;
|
| 22 |
+
vertical-align: middle;
|
| 23 |
+
margin-right: 15px;
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
/* Footer styling */
|
| 27 |
+
#footer {
|
| 28 |
+
background-color: #f0f4f8;
|
| 29 |
+
color: #003366;
|
| 30 |
+
padding: 10px;
|
| 31 |
+
text-align: center;
|
| 32 |
+
font-family: 'Arial', sans-serif;
|
| 33 |
+
font-size: 0.9em;
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
/* Main container styling */
|
| 37 |
+
.main-container {
|
| 38 |
+
padding: 20px;
|
| 39 |
+
margin: auto;
|
| 40 |
+
max-width: 800px;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
/* Button styling */
|
| 44 |
+
button {
|
| 45 |
+
font-size: 1em;
|
| 46 |
+
padding: 10px 20px;
|
| 47 |
+
}
|
| 48 |
+
"""
|
| 49 |
+
|
| 50 |
+
# Define the image classification function
|
| 51 |
+
def classify_image(image_path):
|
| 52 |
+
result = pipe(image_path)
|
| 53 |
+
# Return the label from the first result
|
| 54 |
+
return result[0]['label']
|
| 55 |
+
|
| 56 |
+
# Build the Gradio Blocks layout
|
| 57 |
+
with gr.Blocks(css=custom_css) as demo:
|
| 58 |
+
# Header: includes a logo and the app name
|
| 59 |
+
gr.HTML("""
|
| 60 |
+
<div id="header">
|
| 61 |
+
<img src="https://via.placeholder.com/100" alt="Logo"/>
|
| 62 |
+
<span style="font-size: 2em; font-weight: bold;">Weapon Classifier</span>
|
| 63 |
+
</div>
|
| 64 |
+
""")
|
| 65 |
+
|
| 66 |
+
# Main content area with an image input and text output
|
| 67 |
+
with gr.Column(elem_classes="main-container"):
|
| 68 |
+
gr.HTML("<h2>Upload an image to classify the weapon</h2>")
|
| 69 |
+
with gr.Row():
|
| 70 |
+
image_input = gr.Image(type="filepath", label="Weapon Image")
|
| 71 |
+
output_text = gr.Textbox(label="Classification Result")
|
| 72 |
+
btn = gr.Button("Classify")
|
| 73 |
+
btn.click(fn=classify_image, inputs=image_input, outputs=output_text)
|
| 74 |
+
|
| 75 |
+
# Footer: explains the app is for game use only
|
| 76 |
+
gr.HTML("""
|
| 77 |
+
<div id="footer">
|
| 78 |
+
This application is intended for game use only. © 2025 My Company.
|
| 79 |
+
</div>
|
| 80 |
+
""")
|
| 81 |
+
|
| 82 |
+
# Launch the app
|
| 83 |
+
demo.launch()
|