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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -46
app.py CHANGED
@@ -1,8 +1,8 @@
1
  #!/usr/bin/env python3
2
  # -*- coding: utf-8 -*-
3
  """
4
- 🪶 Council Matters Classifier – PT
5
- Modern Gradio interface with animated dark theme for Portuguese administrative document classification.
6
  """
7
 
8
  import gradio as gr
@@ -12,7 +12,6 @@ import re
12
  from pathlib import Path
13
  from scipy.sparse import hstack, csr_matrix
14
 
15
- # Optional PyTorch
16
  try:
17
  import torch
18
  from transformers import AutoTokenizer, AutoModel
@@ -146,61 +145,56 @@ suggestions = [
146
  "O plano estratégico inclui medidas para atrair investimento privado.",
147
  ]
148
 
149
- # --- CSS & JS (modern dark theme with carousel) ---
150
  custom_css = """
151
  body {
152
- background-color: #0c0c0c;
153
  font-family: 'Inter', sans-serif;
 
154
  }
155
- .gradio-container { background-color: #0c0c0c; color: #f1f1f1; }
156
- h2, h3 { text-align: center; color: #00b4ff; font-weight: 600; }
157
  textarea {
158
- background-color: #181818 !important;
159
- color: #fff !important;
160
- border-radius: 12px !important;
161
- border: 1px solid #333 !important;
162
  }
163
  button {
164
- background: linear-gradient(90deg, #007aff, #00c3ff);
165
- color: white !important;
166
- font-weight: 600 !important;
167
- border-radius: 10px !important;
168
  border: none !important;
169
- transition: 0.3s;
170
  }
171
- button:hover { opacity: 0.9; transform: scale(1.04); }
172
  .output-chip {
173
- background-color: #1a1a1a;
174
- color: #00c3ff;
175
- padding: 6px 14px;
176
- border-radius: 10px;
177
  font-weight: 500;
178
- border: 1px solid #007aff33;
179
- transition: 0.3s;
180
- }
181
- .output-chip:hover {
182
- background-color: #007aff33;
183
- transform: scale(1.05);
184
  }
185
  .suggestion-box {
186
- background-color: #111;
187
- border-radius: 12px;
188
- border: 1px solid #1f1f1f;
189
- padding: 12px;
190
  display: flex;
191
  align-items: center;
192
  justify-content: space-between;
193
- color: #aaa;
194
- margin-top: 25px;
195
  }
196
  .arrow-btn {
197
  background: none;
198
  border: none;
199
- color: #00c3ff;
200
- font-size: 22px;
201
  cursor: pointer;
202
  }
203
- .arrow-btn:hover { color: #00e0ff; transform: scale(1.2); }
204
  """
205
 
206
  custom_js = f"""
@@ -219,7 +213,8 @@ function updateSuggestion(direction) {{
219
  }}
220
  """
221
 
222
- # --- Gradio Interface ---
 
223
  def classify_display(text):
224
  preds = classifier.predict(text)
225
  if not preds:
@@ -230,28 +225,28 @@ def classify_display(text):
230
  label = p["label"]
231
  prob = p["probability"]
232
  conf = p["confidence"]
233
- color = {"high": "#00ff88", "medium": "#ffd966", "low": "#ff6666"}[conf]
234
- chips += f"<span class='output-chip' style='border-color:{color}80;color:{color}'>{label} ({prob:.0%})</span>"
235
- return f"<div style='display:flex;flex-wrap:wrap;gap:10px;justify-content:center;margin-top:10px'>{chips}</div>"
236
 
237
 
238
  with gr.Blocks(css=custom_css, js=custom_js, theme="gradio/soft") as demo:
239
  gr.Markdown("## 🏛️ **Council Matters Classifier – PT**")
240
- gr.Markdown("### Enter Portuguese administrative text below:")
241
 
242
  input_text = gr.Textbox(
243
  label="",
244
- placeholder="Escreva aqui o texto em português...",
245
  lines=6,
246
  elem_id="input-text"
247
  )
248
 
249
- classify_btn = gr.Button("Classify")
250
- output = gr.HTML(label="Predicted Topics")
251
 
252
  classify_btn.click(fn=classify_display, inputs=input_text, outputs=output)
253
 
254
- gr.Markdown("### 💡 Suggestions")
255
  gr.HTML("""
256
  <div class='suggestion-box'>
257
  <button class='arrow-btn' onclick="updateSuggestion('prev')">⟨</button>
@@ -262,6 +257,5 @@ with gr.Blocks(css=custom_css, js=custom_js, theme="gradio/soft") as demo:
262
  </div>
263
  """)
264
 
265
- # ---------------- Launch ----------------
266
  if __name__ == "__main__":
267
  demo.launch()
 
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
 
12
  from pathlib import Path
13
  from scipy.sparse import hstack, csr_matrix
14
 
 
15
  try:
16
  import torch
17
  from transformers import AutoTokenizer, AutoModel
 
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"""
 
213
  }}
214
  """
215
 
216
+
217
+ # --- Interface ---
218
  def classify_display(text):
219
  preds = classifier.predict(text)
220
  if not preds:
 
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>
 
257
  </div>
258
  """)
259
 
 
260
  if __name__ == "__main__":
261
  demo.launch()