anonymous12321 commited on
Commit
82f5d53
·
verified ·
1 Parent(s): 5222ff8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -14
app.py CHANGED
@@ -2,7 +2,7 @@
2
  # -*- coding: utf-8 -*-
3
  """
4
  🪶 Council Matters Classifier – PT
5
-
6
  """
7
 
8
  import gradio as gr
@@ -183,7 +183,7 @@ button:hover { background-color: #00aaff !important; }
183
  background-color: #112f50;
184
  border-radius: 10px;
185
  border: 1px solid #1f3c5a;
186
- padding: 10px;
187
  display: flex;
188
  align-items: center;
189
  justify-content: center;
@@ -207,7 +207,7 @@ button:hover { background-color: #00aaff !important; }
207
  .use-btn:hover { background-color:#99ccff !important; }
208
  .suggestion-box .prev-btn { position: absolute; top: 5px; left: 5px; }
209
  .suggestion-box .next-btn { position: absolute; top: 5px; right: 5px; }
210
- .suggestion-box .suggestion-text { width: 100%; text-align: center; border:none; background:none; color:#eee; font-weight:500; padding-top:8px; }
211
  """
212
 
213
  # ---------------- Gradio UI ----------------
@@ -221,17 +221,34 @@ with gr.Blocks(css=custom_css, theme="gradio/soft") as demo:
221
  output = gr.HTML()
222
  classify_btn.click(fn=classify_display, inputs=input_text, outputs=output)
223
 
224
- # Sugestões
225
- prev_btn = gr.Button("", elem_classes="prev-btn arrow-btn")
226
- suggestion_display = gr.Textbox(value=suggestions[0], interactive=False, elem_classes="suggestion-text")
227
- next_btn = gr.Button("⟩", elem_classes="next-btn arrow-btn")
228
- use_btn = gr.Button("Usar", elem_classes="use-btn")
229
-
230
- prev_btn.click(fn=prev_example, outputs=suggestion_display)
231
- next_btn.click(fn=next_example, outputs=suggestion_display)
232
- use_btn.click(fn=use_suggestion, inputs=suggestion_display, outputs=input_text)
233
-
234
- gr.Row([prev_btn, suggestion_display, next_btn, use_btn], elem_id="suggestion-box")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
235
 
236
  # ---------------- Launch ----------------
237
  if __name__ == "__main__":
 
2
  # -*- coding: utf-8 -*-
3
  """
4
  🪶 Council Matters Classifier – PT
5
+ Dark modern Gradio interface with top corner arrow buttons for suggestions.
6
  """
7
 
8
  import gradio as gr
 
183
  background-color: #112f50;
184
  border-radius: 10px;
185
  border: 1px solid #1f3c5a;
186
+ padding: 30px 10px 10px 10px;
187
  display: flex;
188
  align-items: center;
189
  justify-content: center;
 
207
  .use-btn:hover { background-color:#99ccff !important; }
208
  .suggestion-box .prev-btn { position: absolute; top: 5px; left: 5px; }
209
  .suggestion-box .next-btn { position: absolute; top: 5px; right: 5px; }
210
+ .suggestion-text { text-align: center; color: #eee; font-weight: 500; width: 100%; }
211
  """
212
 
213
  # ---------------- Gradio UI ----------------
 
221
  output = gr.HTML()
222
  classify_btn.click(fn=classify_display, inputs=input_text, outputs=output)
223
 
224
+ # Caixa de sugestões com setas no topo
225
+ suggestion_box_html = f"""
226
+ <div class="suggestion-box">
227
+ <button class="arrow-btn prev-btn" onclick="updateSuggestion('prev')">⟨</button>
228
+ <span class="suggestion-text" id="suggestion-text">{suggestions[0]}</span>
229
+ <button class="arrow-btn next-btn" onclick="updateSuggestion('next')">⟩</button>
230
+ </div>
231
+ <div style="text-align:center;margin-top:5px;">
232
+ <button class="use-btn" onclick="useSuggestion()">Usar</button>
233
+ </div>
234
+ """
235
+ suggestion_html = gr.HTML(suggestion_box_html)
236
+
237
+ # JavaScript para navegar sugestões
238
+ demo.load(lambda: None, [], [], _js=f"""
239
+ let examples = {suggestions};
240
+ let index = 0;
241
+ function updateSuggestion(direction){{
242
+ const el = document.getElementById('suggestion-text');
243
+ if(direction==='next') index=(index+1)%examples.length;
244
+ else index=(index-1+examples.length)%examples.length;
245
+ el.innerText = examples[index];
246
+ }}
247
+ function useSuggestion(){{
248
+ const text = document.getElementById('suggestion-text').innerText;
249
+ document.querySelector('textarea').value = text;
250
+ }}
251
+ """)
252
 
253
  # ---------------- Launch ----------------
254
  if __name__ == "__main__":