AIdeaText commited on
Commit
08aea0d
verified
1 Parent(s): 951f708

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +55 -18
app.py CHANGED
@@ -39,28 +39,65 @@ def app_main():
39
  Inicializa la aplicaci贸n con Gradio.
40
  """
41
  logger.info("Iniciando AIdeaText")
42
- landing_page = create_landing_interface()
43
- login_page = create_login_interface()
44
-
45
- # Funci贸n para manejar navegaci贸n entre interfaces
46
- def navigate_to_login():
47
- return gr.update(visible=True), gr.update(visible=False)
48
-
49
- def navigate_to_landing():
50
- return gr.update(visible=False), gr.update(visible=True)
51
-
52
- # Crear la interfaz principal con redirecci贸n
53
- with gr.Blocks() as app_interface:
54
  landing_container = gr.Group(visible=True)
55
  login_container = gr.Group(visible=False)
56
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57
  with landing_container:
58
- landing_page.render(navigate_to_login)
59
-
 
60
  with login_container:
61
- login_page.render(navigate_to_landing)
62
-
63
- app_interface.launch(server_name="0.0.0.0", server_port=7860, auth=None)
 
 
 
 
 
 
 
 
 
 
64
 
65
  if __name__ == "__main__":
66
  app_main()
 
39
  Inicializa la aplicaci贸n con Gradio.
40
  """
41
  logger.info("Iniciando AIdeaText")
42
+
43
+ # Estado de la aplicaci贸n
44
+ state = gr.State({
45
+ "logged_in": False,
46
+ "username": None,
47
+ "role": None
48
+ })
49
+
50
+ with gr.Blocks(css="#container { max-width: 800px; margin: auto; }") as app_interface:
51
+ gr.HTML("<div id='container'>")
52
+
53
+ # Contenedores para cada vista
54
  landing_container = gr.Group(visible=True)
55
  login_container = gr.Group(visible=False)
56
+ user_container = gr.Group(visible=False)
57
+
58
+ # Funci贸n de navegaci贸n
59
+ def switch_view(to_view, state_update=None):
60
+ updates = {
61
+ "landing": [True, False, False],
62
+ "login": [False, True, False],
63
+ "user": [False, False, True]
64
+ }
65
+ visibilities = updates[to_view]
66
+ if state_update:
67
+ state.update(state_update)
68
+ return [gr.update(visible=v) for v in visibilities]
69
+
70
+ # Funci贸n de login
71
+ def handle_login(username, password, state):
72
+ success, role = authenticate_user(username, password)
73
+ if success:
74
+ state.update({
75
+ "logged_in": True,
76
+ "username": username,
77
+ "role": role
78
+ })
79
+ return switch_view("user", state) + [f"Bienvenido, {username}"]
80
+ return switch_view("login") + ["Credenciales incorrectas"]
81
+
82
+ # Renderizar interfaces
83
  with landing_container:
84
+ landing_interface = create_landing_interface()
85
+ landing_interface.render(lambda: switch_view("login"))
86
+
87
  with login_container:
88
+ login_interface = create_login_interface()
89
+ login_interface.render(
90
+ lambda: switch_view("landing"),
91
+ handle_login
92
+ )
93
+
94
+ with user_container:
95
+ user_interface = create_user_interface()
96
+ user_interface.render(lambda: switch_view("landing"))
97
+
98
+ gr.HTML("</div>")
99
+
100
+ app_interface.launch(server_name="0.0.0.0", server_port=7860)
101
 
102
  if __name__ == "__main__":
103
  app_main()