haxerwddle commited on
Commit
7f59dbf
·
1 Parent(s): bd07189

UI change

Browse files
Files changed (1) hide show
  1. app.py +119 -13
app.py CHANGED
@@ -62,29 +62,135 @@ def full_pipeline(image):
62
 
63
 
64
  # ------------------ GRADIO UI ------------------
65
- with gr.Blocks() as demo:
66
- gr.Markdown("<h1 style='text-align:center;'>♻️ AI Waste Classifier</h1>")
67
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68
  with gr.Row():
69
- img_input = gr.Image(type="pil", label="Upload waste image")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
 
71
- cls_output = gr.Label(num_top_classes=3, label="Classifier Prediction")
72
- gr.Markdown("<h1 style='text-align:center;'>♻️ Disposal Advisor</h1>")
73
  explain_output = gr.Textbox(
74
- label="Detailed Recycling & Disposal Advice",
75
  elem_id="explainbox",
76
  lines=18
77
  )
78
 
79
- analyze_btn = gr.Button("Analyze", variant="primary")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80
 
81
  analyze_btn.click(
82
  full_pipeline,
83
  inputs=img_input,
84
- outputs=[cls_output, explain_output]
 
85
  )
86
 
87
- demo.launch(
88
- theme=gr.themes.Soft(primary_hue="green"),
89
- css="#explainbox {height: 330px; font-size: 15px;}"
90
- )
 
62
 
63
 
64
  # ------------------ GRADIO UI ------------------
65
+ # =========================
66
+ # CSS TÙY CHỈNH GIAO DIỆN
67
+ # =========================
68
+ custom_css = """
69
+ #main-title {
70
+ text-align: center;
71
+ color: #2E7D32;
72
+ font-size: 34px;
73
+ font-weight: 800;
74
+ margin-bottom: 22px;
75
+ }
76
+
77
+ .gradio-container {
78
+ background: linear-gradient(135deg, #E8F5E9 0%, #F1F8E9 100%);
79
+ font-family: 'Segoe UI', sans-serif;
80
+ }
81
+
82
+ #explainbox textarea {
83
+ background: #ffffff;
84
+ border: 2px solid #A5D6A7;
85
+ border-radius: 12px;
86
+ padding: 12px;
87
+ font-size: 15px;
88
+ }
89
+
90
+ .gr-button.primary {
91
+ background: #43A047 !important;
92
+ color: white !important;
93
+ border-radius: 12px !important;
94
+ padding: 12px 20px !important;
95
+ font-size: 17px !important;
96
+ box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.15);
97
+ transition: 0.2s ease;
98
+ }
99
+
100
+ .gr-button.primary:hover {
101
+ background: #2E7D32 !important;
102
+ transform: translateY(-2px);
103
+ }
104
+
105
+ /* PROGRESS BAR CUSTOM */
106
+ #loading-container {
107
+ width: 100%;
108
+ height: 12px;
109
+ margin-top: 15px;
110
+ margin-bottom: 5px;
111
+ background: #C8E6C9;
112
+ border-radius: 10px;
113
+ }
114
+
115
+ #loading-bar {
116
+ width: 0%;
117
+ height: 100%;
118
+ background: #66BB6A;
119
+ border-radius: 10px;
120
+ transition: width 0.25s ease-out;
121
+ }
122
+ """
123
+
124
+ # =========================
125
+ # GRADIO UI
126
+ # =========================
127
+ with gr.Blocks(css=custom_css) as demo:
128
+
129
+ # ---- TITLE
130
+ gr.Markdown("<h1 id='main-title'>♻️ AI Waste Classifier + Eco Advisor</h1>")
131
+
132
+ # ---- INPUT ROW
133
  with gr.Row():
134
+ with gr.Column(scale=1):
135
+ img_input = gr.Image(
136
+ type="pil",
137
+ label="📸 Upload waste image",
138
+ elem_id="upload-area"
139
+ )
140
+
141
+ with gr.Column(scale=1):
142
+ gr.Markdown(
143
+ """
144
+ <div style="border:2px solid #A5D6A7; padding:16px; border-radius:14px; background:white;">
145
+ <h3 style="color:#2E7D32;">🌍 Mẹo phân loại nhanh:</h3>
146
+ <ul>
147
+ <li>Rác hữu cơ → thùng xanh</li>
148
+ <li>Nhựa, kim loại → tái chế</li>
149
+ <li>Thủy tinh nhớ rửa sạch</li>
150
+ <li>Pin, thiết bị điện → xử lý đặc biệt</li>
151
+ </ul>
152
+ </div>
153
+ """
154
+ )
155
+
156
+ # ---- OUTPUTS
157
+ cls_output = gr.Label(
158
+ num_top_classes=3,
159
+ label="🔍 Classifier Prediction (Top 3)"
160
+ )
161
 
 
 
162
  explain_output = gr.Textbox(
163
+ label="🧩 Detailed Recycling & Disposal Advice",
164
  elem_id="explainbox",
165
  lines=18
166
  )
167
 
168
+ # ---- BUTTON + PROGRESS BAR
169
+ analyze_btn = gr.Button("Analyze Waste", variant="primary")
170
+
171
+ progress_html = gr.HTML(
172
+ """
173
+ <div id="loading-container">
174
+ <div id="loading-bar"></div>
175
+ </div>
176
+ """
177
+ )
178
+
179
+ # ---- JS ANIMATION FOR PROGRESS BAR
180
+ animate_js = """
181
+ function(p){
182
+ let bar = document.getElementById('loading-bar');
183
+ if (bar){
184
+ bar.style.width = (p * 100) + "%";
185
+ }
186
+ }
187
+ """
188
 
189
  analyze_btn.click(
190
  full_pipeline,
191
  inputs=img_input,
192
+ outputs=[cls_output, explain_output],
193
+ progress=animate_js
194
  )
195
 
196
+ demo.launch()