scfive commited on
Commit
3081753
·
verified ·
1 Parent(s): 5660fce

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +80 -15
app.py CHANGED
@@ -1,18 +1,83 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
- examples = ["examples/example_0.jpg",
5
- "examples/example_1.png",
6
- "examples/example_2.png",
7
- "examples/example_3.png",
8
- "examples/example_4.jpg",
9
- "examples/example_5.png"]
10
-
11
- pipe = pipeline(task="image-classification",
12
- model="getesper/Weapons_class")
13
- gr.Interface.from_pipeline(pipe,
14
- title="CSGO Weapon Image Classification",
15
- description = "This is a CSGO Weapon Classifier Model that has been trained by <strong><a href='https://huggingface.co/Kaludi'>Kaludi</a></strong> to recognize <strong>11</strong> different types of Counter-Strike: Global Offensive (CSGO) Weapons, which include <strong>AK-47,AWP,Famas,Galil-AR,Glock,M4A1,M4A4,P-90,SG-553,UMP,USP</strong>. The model is capable of accurately classifying the weapon name present in an image. With its deep understanding of the characteristics of each weapon in the game, the model is a valuable tool for players and fans of CSGO.",
16
- article = "<p style='text-align: center'><a href='https://github.com/Kaludii'>Github</a> | <a href='https://huggingface.co/Kaludi'>HuggingFace</a></p>",
17
- examples=examples,
18
- ).launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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="getesper/Weapons_class", # 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()