anonymous12321 commited on
Commit
1109ddb
·
verified ·
1 Parent(s): 625b916

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -14
app.py CHANGED
@@ -2,7 +2,7 @@
2
  # -*- coding: utf-8 -*-
3
  """
4
  🪶 Council Matters Classifier – PT
5
- Dark modern Gradio interface with working suggestions carousel.
6
  """
7
 
8
  import gradio as gr
@@ -20,8 +20,7 @@ try:
20
  except ImportError:
21
  TORCH_AVAILABLE = False
22
 
23
-
24
- # ---------------- Model Definition ----------------
25
  class PortugueseClassifier:
26
  def __init__(self):
27
  self.model_path = Path("models")
@@ -127,7 +126,6 @@ class PortugueseClassifier:
127
  predicted_labels.sort(key=lambda x: x["probability"], reverse=True)
128
  return predicted_labels
129
 
130
-
131
  # ---------------- Load Classifier ----------------
132
  classifier = PortugueseClassifier()
133
 
@@ -149,12 +147,15 @@ example_idx = 0
149
  def next_example():
150
  global example_idx
151
  example_idx = (example_idx + 1) % len(suggestions)
152
- return suggestions[example_idx], suggestions[example_idx]
153
 
154
  def prev_example():
155
  global example_idx
156
  example_idx = (example_idx - 1 + len(suggestions)) % len(suggestions)
157
- return suggestions[example_idx], suggestions[example_idx]
 
 
 
158
 
159
  def classify_display(text):
160
  preds = classifier.predict(text)
@@ -181,6 +182,8 @@ button:hover { background-color: #00aaff !important; }
181
  .suggestion-box { background-color: #111; border-radius: 10px; border: 1px solid #222; padding: 10px; display: flex; align-items: center; justify-content: space-between; color: #aaa; margin-top: 25px; }
182
  .arrow-btn { background: none; border: none; color: #00c3ff; font-size: 22px; cursor: pointer; }
183
  .arrow-btn:hover { color: #00e0ff; transform: scale(1.15); }
 
 
184
  """
185
 
186
  # ---------------- Gradio UI ----------------
@@ -188,24 +191,23 @@ with gr.Blocks(css=custom_css, theme="gradio/soft") as demo:
188
  gr.Markdown("## 🏛️ **Council Matters Classifier – PT**")
189
  gr.Markdown("### Insira texto administrativo em português:")
190
 
191
- input_text = gr.Textbox(
192
- label="", placeholder="Escreva aqui o texto em português...", lines=6, elem_id="input-text"
193
- )
194
 
195
  classify_btn = gr.Button("Classificar")
196
- output = gr.HTML(label="Tópicos previstos")
197
  classify_btn.click(fn=classify_display, inputs=input_text, outputs=output)
198
 
199
  # Sugestões
200
  prev_btn = gr.Button("⟨")
201
  suggestion_display = gr.Textbox(value=suggestions[0], interactive=False)
202
  next_btn = gr.Button("⟩")
 
203
 
204
- prev_btn.click(fn=prev_example, outputs=[input_text, suggestion_display])
205
- next_btn.click(fn=next_example, outputs=[input_text, suggestion_display])
 
206
 
207
- gr.Row([prev_btn, suggestion_display, next_btn], elem_id="suggestion-box")
208
 
209
- # ---------------- Launch ----------------
210
  if __name__ == "__main__":
211
  demo.launch()
 
2
  # -*- coding: utf-8 -*-
3
  """
4
  🪶 Council Matters Classifier – PT
5
+ Dark modern Gradio interface with suggestions carousel.
6
  """
7
 
8
  import gradio as gr
 
20
  except ImportError:
21
  TORCH_AVAILABLE = False
22
 
23
+ # ---------------- Classifier ----------------
 
24
  class PortugueseClassifier:
25
  def __init__(self):
26
  self.model_path = Path("models")
 
126
  predicted_labels.sort(key=lambda x: x["probability"], reverse=True)
127
  return predicted_labels
128
 
 
129
  # ---------------- Load Classifier ----------------
130
  classifier = PortugueseClassifier()
131
 
 
147
  def next_example():
148
  global example_idx
149
  example_idx = (example_idx + 1) % len(suggestions)
150
+ return suggestions[example_idx]
151
 
152
  def prev_example():
153
  global example_idx
154
  example_idx = (example_idx - 1 + len(suggestions)) % len(suggestions)
155
+ return suggestions[example_idx]
156
+
157
+ def use_suggestion(suggestion):
158
+ return suggestion
159
 
160
  def classify_display(text):
161
  preds = classifier.predict(text)
 
182
  .suggestion-box { background-color: #111; border-radius: 10px; border: 1px solid #222; padding: 10px; display: flex; align-items: center; justify-content: space-between; color: #aaa; margin-top: 25px; }
183
  .arrow-btn { background: none; border: none; color: #00c3ff; font-size: 22px; cursor: pointer; }
184
  .arrow-btn:hover { color: #00e0ff; transform: scale(1.15); }
185
+ .use-btn { background-color:#00c3ff !important; color:#000 !important; font-weight:600 !important; border-radius:6px !important; padding:3px 10px !important; }
186
+ .use-btn:hover { background-color:#00e0ff !important; }
187
  """
188
 
189
  # ---------------- Gradio UI ----------------
 
191
  gr.Markdown("## 🏛️ **Council Matters Classifier – PT**")
192
  gr.Markdown("### Insira texto administrativo em português:")
193
 
194
+ input_text = gr.Textbox(label="", placeholder="Escreva aqui o texto em português...", lines=6)
 
 
195
 
196
  classify_btn = gr.Button("Classificar")
197
+ output = gr.HTML()
198
  classify_btn.click(fn=classify_display, inputs=input_text, outputs=output)
199
 
200
  # Sugestões
201
  prev_btn = gr.Button("⟨")
202
  suggestion_display = gr.Textbox(value=suggestions[0], interactive=False)
203
  next_btn = gr.Button("⟩")
204
+ use_btn = gr.Button("Usar sugestão")
205
 
206
+ prev_btn.click(fn=prev_example, outputs=suggestion_display)
207
+ next_btn.click(fn=next_example, outputs=suggestion_display)
208
+ use_btn.click(fn=use_suggestion, inputs=suggestion_display, outputs=input_text)
209
 
210
+ gr.Row([prev_btn, suggestion_display, next_btn, use_btn], elem_id="suggestion-box")
211
 
 
212
  if __name__ == "__main__":
213
  demo.launch()