DHEIVER commited on
Commit
dadf642
·
verified ·
1 Parent(s): 1c4c4e9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -8
app.py CHANGED
@@ -225,6 +225,13 @@ Os comportamentos podem ser adaptados conforme o contexto e as necessidades espe
225
 
226
  return report
227
 
 
 
 
 
 
 
 
228
  def create_interface():
229
  """Cria interface moderna do teste."""
230
  with gr.Blocks() as iface:
@@ -234,32 +241,48 @@ def create_interface():
234
  radios = []
235
  for i, q in enumerate(DISC_QUESTIONS, 1):
236
  gr.Markdown(f"### {i}. {q['pergunta']}")
237
- radio = gr.Radio([f"{p} - {d}" for p, d in q['opcoes']])
 
 
 
238
  radios.append(radio)
239
 
240
  # Resultados
241
- with gr.Group(visible=False) as result_box:
242
- plot = gr.Plot()
243
- output = gr.Markdown()
244
 
245
  # Botões
246
  analyze_btn = gr.Button("Analisar Perfil")
247
  reset_btn = gr.Button("Novo Teste")
248
 
249
  def process_results(*answers):
 
 
 
 
250
  perc = calcular_perfil(answers)
251
  return create_disc_plot(perc), gerar_relatorio(perc)
252
 
 
 
 
 
253
  analyze_btn.click(
254
- process_results,
255
  inputs=radios,
256
- outputs=[plot, output]
 
257
  )
258
 
259
- reset_btn.click(lambda: [None]*7, outputs=radios + [plot, output])
 
 
 
 
 
260
 
261
  return iface
262
 
263
  if __name__ == "__main__":
264
  iface = create_interface()
265
- iface.launch()
 
225
 
226
  return report
227
 
228
+ import gradio as gr
229
+ import plotly.graph_objects as go
230
+ from sentence_transformers import SentenceTransformer
231
+ import numpy as np
232
+
233
+ # [Previous code remains the same until create_interface function]
234
+
235
  def create_interface():
236
  """Cria interface moderna do teste."""
237
  with gr.Blocks() as iface:
 
241
  radios = []
242
  for i, q in enumerate(DISC_QUESTIONS, 1):
243
  gr.Markdown(f"### {i}. {q['pergunta']}")
244
+ radio = gr.Radio(
245
+ choices=[f"{p} - {d}" for p, d in q['opcoes']],
246
+ label=f"Questão {i}" # Added label for better accessibility
247
+ )
248
  radios.append(radio)
249
 
250
  # Resultados
251
+ plot = gr.Plot()
252
+ output = gr.Markdown()
 
253
 
254
  # Botões
255
  analyze_btn = gr.Button("Analisar Perfil")
256
  reset_btn = gr.Button("Novo Teste")
257
 
258
  def process_results(*answers):
259
+ # Validate if all questions are answered
260
+ if any(answer is None for answer in answers):
261
+ return None, "Por favor, responda todas as questões antes de analisar."
262
+
263
  perc = calcular_perfil(answers)
264
  return create_disc_plot(perc), gerar_relatorio(perc)
265
 
266
+ def reset_form():
267
+ return [None] * len(radios) + [None, None]
268
+
269
+ # Connect the buttons to their respective functions
270
  analyze_btn.click(
271
+ fn=process_results,
272
  inputs=radios,
273
+ outputs=[plot, output],
274
+ api_name="analyze" # Added API name for better tracking
275
  )
276
 
277
+ reset_btn.click(
278
+ fn=reset_form,
279
+ inputs=None,
280
+ outputs=radios + [plot, output],
281
+ api_name="reset" # Added API name for better tracking
282
+ )
283
 
284
  return iface
285
 
286
  if __name__ == "__main__":
287
  iface = create_interface()
288
+ iface.launch(show_error=True) # Added show_error for better debugging