|
import gradio as gr |
|
import os |
|
import logging |
|
|
|
from modules.auth.auth import ( |
|
create_auth_interface, |
|
authenticate_admin, |
|
authenticate_student, |
|
register_student, |
|
update_student_info, |
|
delete_student, |
|
logout, |
|
hash_password, |
|
verify_password |
|
) |
|
|
|
from modules.database.database_init import initialize_database_connections |
|
import spaces |
|
import torch |
|
|
|
zero = torch.Tensor([0]).cuda() |
|
print(zero.device) |
|
|
|
@spaces.GPU |
|
def greet(n): |
|
print(zero.device) |
|
return f"Hello {zero + n} Tensor" |
|
|
|
|
|
logging.basicConfig(level=logging.INFO) |
|
logger = logging.getLogger(__name__) |
|
|
|
|
|
COSMOS_ENDPOINT = os.getenv("COSMOS_ENDPOINT") |
|
COSMOS_KEY = os.getenv("COSMOS_KEY") |
|
if not COSMOS_ENDPOINT or not COSMOS_KEY: |
|
raise ValueError("Faltan variables de entorno: COSMOS_ENDPOINT y COSMOS_KEY.") |
|
|
|
|
|
if not initialize_database_connections(): |
|
raise ValueError("No se pudo inicializar la conexi贸n a la base de datos.") |
|
|
|
|
|
|
|
|
|
|
|
def main_interface(): |
|
""" |
|
Crea la interfaz principal con redirecci贸n al login o user page. |
|
""" |
|
with gr.Blocks() as app_interface: |
|
|
|
login_page = create_auth_interface() |
|
user_page = create_user_page() |
|
|
|
|
|
login_container = gr.Group(visible=True) |
|
user_container = gr.Group(visible=False) |
|
|
|
|
|
def handle_login_redirect(username, role): |
|
if username and role: |
|
return { |
|
login_container: gr.update(visible=False), |
|
user_container: gr.update(visible=True) |
|
} |
|
return { |
|
login_container: gr.update(visible=True), |
|
user_container: gr.update(visible=False) |
|
} |
|
|
|
|
|
with login_container: |
|
login_page.load(fn=handle_login_redirect, inputs=[], outputs=[]) |
|
|
|
|
|
with user_container: |
|
user_page |
|
|
|
return app_interface |
|
|
|
|
|
if __name__ == "__main__": |
|
app = main_interface() |
|
app.launch(server_name="0.0.0.0", server_port=7860, auth=None) |
|
|
|
|
|
if __name__ == "__main__": |
|
app.launch(server_name="0.0.0.0", server_port=7860, auth=None) |
|
|