anonymous12321 commited on
Commit
bbb9e13
·
verified ·
1 Parent(s): e285299

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +51 -44
app.py CHANGED
@@ -1,8 +1,8 @@
1
  #!/usr/bin/env python3
2
  # -*- coding: utf-8 -*-
3
  """
4
- 🪶 Council Matters Classifier – PT (Light Edition)
5
- Simplified modern Gradio interface with light minimal theme.
6
  """
7
 
8
  import gradio as gr
@@ -127,11 +127,8 @@ class PortugueseClassifier:
127
  return predicted_labels
128
 
129
 
130
- # ---------------- Load Classifier ----------------
131
  classifier = PortugueseClassifier()
132
 
133
-
134
- # ---------------- Gradio UI ----------------
135
  suggestions = [
136
  "A Câmara Municipal aprovou o novo orçamento para 2025, com foco em sustentabilidade.",
137
  "Foi decidido avançar com o projeto de requalificação do centro histórico.",
@@ -145,115 +142,125 @@ suggestions = [
145
  "O plano estratégico inclui medidas para atrair investimento privado.",
146
  ]
147
 
148
- # --- Simplified Light CSS ---
149
  custom_css = """
150
  body {
151
- background-color: #fafafa;
 
152
  font-family: 'Inter', sans-serif;
153
- color: #222;
154
  }
155
- .gradio-container { background-color: #fafafa; color: #222; }
156
- h2, h3 { text-align: center; color: #0078cc; font-weight: 600; }
157
  textarea {
158
- background-color: #fff !important;
159
- color: #222 !important;
160
- border-radius: 8px !important;
161
- border: 1px solid #ccc !important;
162
  }
163
  button {
164
- background-color: #0078cc !important;
165
- color: #fff !important;
 
166
  border-radius: 8px !important;
167
  border: none !important;
168
- font-weight: 600 !important;
169
  }
170
- button:hover { background-color: #0094ff !important; }
171
  .output-chip {
172
- background-color: #f3f9ff;
173
- color: #005fa3;
174
  padding: 5px 12px;
175
  border-radius: 8px;
 
176
  font-weight: 500;
177
- border: 1px solid #cde5ff;
178
  }
179
  .suggestion-box {
180
- background-color: #fff;
181
  border-radius: 10px;
182
- border: 1px solid #ddd;
183
  padding: 10px;
184
  display: flex;
185
  align-items: center;
186
  justify-content: space-between;
187
- color: #555;
188
- margin-top: 20px;
189
  }
190
  .arrow-btn {
191
  background: none;
192
  border: none;
193
- color: #0078cc;
194
- font-size: 20px;
195
  cursor: pointer;
196
  }
197
- .arrow-btn:hover { color: #0094ff; transform: scale(1.1); }
198
  """
199
 
 
200
  custom_js = f"""
201
  let examples = {suggestions};
202
  let index = 0;
203
- function updateSuggestion(direction) {{
204
  const el = document.getElementById('suggestion-text');
 
205
  el.style.opacity = 0;
206
  setTimeout(() => {{
207
- if (direction === 'next') index = (index + 1) % examples.length;
208
- else index = (index - 1 + examples.length) % examples.length;
209
  el.innerText = examples[index];
210
  document.getElementById('input-text').value = examples[index];
211
  el.style.opacity = 1;
212
- }}, 200);
213
  }}
214
- """
215
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
216
 
217
- # --- Interface ---
218
  def classify_display(text):
219
  preds = classifier.predict(text)
220
  if not preds:
221
  return "<div style='color:#777;text-align:center'>No topics detected.</div>"
222
-
223
  chips = ""
224
  for p in preds[:10]:
225
  label = p["label"]
226
  prob = p["probability"]
227
  conf = p["confidence"]
228
- color = {"high": "#009e60", "medium": "#d1a000", "low": "#d13f3f"}[conf]
229
- chips += f"<span class='output-chip' style='border-color:{color}33;color:{color}'>{label} ({prob:.0%})</span>"
230
- return f"<div style='display:flex;flex-wrap:wrap;gap:8px;justify-content:center;margin-top:10px'>{chips}</div>"
231
-
232
 
233
  with gr.Blocks(css=custom_css, js=custom_js, theme="gradio/soft") as demo:
234
  gr.Markdown("## 🏛️ **Council Matters Classifier – PT**")
235
- gr.Markdown("### Introduza texto administrativo em português:")
236
 
237
  input_text = gr.Textbox(
238
  label="",
239
- placeholder="Escreva aqui o texto...",
240
  lines=6,
241
  elem_id="input-text"
242
  )
243
 
244
  classify_btn = gr.Button("Classificar")
245
  output = gr.HTML(label="Tópicos previstos")
246
-
247
  classify_btn.click(fn=classify_display, inputs=input_text, outputs=output)
248
 
249
  gr.Markdown("### 💡 Sugestões")
250
  gr.HTML("""
251
  <div class='suggestion-box'>
252
- <button class='arrow-btn' onclick="updateSuggestion('prev')">⟨</button>
253
  <span id='suggestion-text' style='flex:1;text-align:center;padding:0 10px;transition:opacity 0.3s'>
254
  A Câmara Municipal aprovou o novo orçamento para 2025, com foco em sustentabilidade.
255
  </span>
256
- <button class='arrow-btn' onclick="updateSuggestion('next')">⟩</button>
257
  </div>
258
  """)
259
 
 
1
  #!/usr/bin/env python3
2
  # -*- coding: utf-8 -*-
3
  """
4
+ 🪶 Council Matters Classifier – PT (Optimized Dark Theme)
5
+ Simplified dark interface with working suggestion carousel.
6
  """
7
 
8
  import gradio as gr
 
127
  return predicted_labels
128
 
129
 
 
130
  classifier = PortugueseClassifier()
131
 
 
 
132
  suggestions = [
133
  "A Câmara Municipal aprovou o novo orçamento para 2025, com foco em sustentabilidade.",
134
  "Foi decidido avançar com o projeto de requalificação do centro histórico.",
 
142
  "O plano estratégico inclui medidas para atrair investimento privado.",
143
  ]
144
 
145
+ # ---------------- CSS ----------------
146
  custom_css = """
147
  body {
148
+ background-color: #0c0c0c;
149
+ color: #f1f1f1;
150
  font-family: 'Inter', sans-serif;
 
151
  }
152
+ .gradio-container { background-color: #0c0c0c; color: #f1f1f1; }
153
+ h2, h3 { text-align: center; color: #00b4ff; font-weight: 600; }
154
  textarea {
155
+ background-color: #181818 !important;
156
+ color: #fff !important;
157
+ border-radius: 10px !important;
158
+ border: 1px solid #333 !important;
159
  }
160
  button {
161
+ background-color: #007aff !important;
162
+ color: white !important;
163
+ font-weight: 600 !important;
164
  border-radius: 8px !important;
165
  border: none !important;
 
166
  }
167
+ button:hover { background-color: #00aaff !important; }
168
  .output-chip {
169
+ background-color: #1a1a1a;
170
+ color: #00c3ff;
171
  padding: 5px 12px;
172
  border-radius: 8px;
173
+ border: 1px solid #007aff33;
174
  font-weight: 500;
 
175
  }
176
  .suggestion-box {
177
+ background-color: #111;
178
  border-radius: 10px;
179
+ border: 1px solid #222;
180
  padding: 10px;
181
  display: flex;
182
  align-items: center;
183
  justify-content: space-between;
184
+ color: #aaa;
185
+ margin-top: 25px;
186
  }
187
  .arrow-btn {
188
  background: none;
189
  border: none;
190
+ color: #00c3ff;
191
+ font-size: 22px;
192
  cursor: pointer;
193
  }
194
+ .arrow-btn:hover { color: #00e0ff; transform: scale(1.15); }
195
  """
196
 
197
+ # ---------------- JS ----------------
198
  custom_js = f"""
199
  let examples = {suggestions};
200
  let index = 0;
201
+ function updateSuggestionText() {{
202
  const el = document.getElementById('suggestion-text');
203
+ if (!el) return;
204
  el.style.opacity = 0;
205
  setTimeout(() => {{
 
 
206
  el.innerText = examples[index];
207
  document.getElementById('input-text').value = examples[index];
208
  el.style.opacity = 1;
209
+ }}, 150);
210
  }}
 
211
 
212
+ window.addEventListener('DOMContentLoaded', () => {{
213
+ const prev = document.getElementById('prev-btn');
214
+ const next = document.getElementById('next-btn');
215
+ if (prev && next) {{
216
+ prev.addEventListener('click', () => {{
217
+ index = (index - 1 + examples.length) % examples.length;
218
+ updateSuggestionText();
219
+ }});
220
+ next.addEventListener('click', () => {{
221
+ index = (index + 1) % examples.length;
222
+ updateSuggestionText();
223
+ }});
224
+ }}
225
+ }});
226
+ """
227
 
 
228
  def classify_display(text):
229
  preds = classifier.predict(text)
230
  if not preds:
231
  return "<div style='color:#777;text-align:center'>No topics detected.</div>"
 
232
  chips = ""
233
  for p in preds[:10]:
234
  label = p["label"]
235
  prob = p["probability"]
236
  conf = p["confidence"]
237
+ color = {"high": "#00ff88", "medium": "#ffd966", "low": "#ff6666"}[conf]
238
+ chips += f"<span class='output-chip' style='color:{color}'>{label} ({prob:.0%})</span>"
239
+ return f"<div style='display:flex;flex-wrap:wrap;gap:10px;justify-content:center;margin-top:10px'>{chips}</div>"
 
240
 
241
  with gr.Blocks(css=custom_css, js=custom_js, theme="gradio/soft") as demo:
242
  gr.Markdown("## 🏛️ **Council Matters Classifier – PT**")
243
+ gr.Markdown("### Insira texto administrativo em português:")
244
 
245
  input_text = gr.Textbox(
246
  label="",
247
+ placeholder="Escreva aqui o texto em português...",
248
  lines=6,
249
  elem_id="input-text"
250
  )
251
 
252
  classify_btn = gr.Button("Classificar")
253
  output = gr.HTML(label="Tópicos previstos")
 
254
  classify_btn.click(fn=classify_display, inputs=input_text, outputs=output)
255
 
256
  gr.Markdown("### 💡 Sugestões")
257
  gr.HTML("""
258
  <div class='suggestion-box'>
259
+ <button id='prev-btn' class='arrow-btn'>⟨</button>
260
  <span id='suggestion-text' style='flex:1;text-align:center;padding:0 10px;transition:opacity 0.3s'>
261
  A Câmara Municipal aprovou o novo orçamento para 2025, com foco em sustentabilidade.
262
  </span>
263
+ <button id='next-btn' class='arrow-btn'>⟩</button>
264
  </div>
265
  """)
266