diff --git a/.gitignore b/.gitignore index a825016..43c968d 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,5 @@ bridges.py /images/positions/ /data/__pycache__/ /configuracion/__pycache__/ -/flagged/ \ No newline at end of file +/flagged/ +**/__pycache__/ \ No newline at end of file diff --git a/app.py b/app.py index 0408b4a..0f3f99c 100644 --- a/app.py +++ b/app.py @@ -12,7 +12,7 @@ def iniciar(): #INTERFAZ #Credit Related Elements html_credits = gr.HTML(visible=True) -lbl_console = gr.Label(label="AI Terminal " + globales.version + " messages", value="AI Engine ready...", container=True) +lbl_console = gr.Label(label="AI Terminal " + globales.version + " messages", value="", container=True) btn_buy = gr.Button("Get Credits", visible=False, size='lg') #Customizable Inputs and Outputs @@ -20,7 +20,7 @@ def iniciar(): with gr.Blocks(theme=globales.tema, css="footer {visibility: True}") as main: #Cargado en Load: Función, input, output - main.load(sulkuFront.precarga, None, [lbl_console, html_credits]) + main.load(sulkuFront.precarga, None, html_credits) #main.load(sulkuFront.precarga, None, [lbl_console, html_credits]) with gr.Row(): diff --git a/autorizador.py b/autorizador.py index 6beb857..7c5581d 100644 --- a/autorizador.py +++ b/autorizador.py @@ -1,12 +1,15 @@ import ast import globales import sulkuPypi +import sulkuFront +import gradio as gr +import tools def authenticate(username, password): cadena_usuarios = sulkuPypi.getData(globales.aplicacion) - lista_usuarios = ast.literal_eval(cadena_usuarios) - + lista_usuarios = ast.literal_eval(cadena_usuarios) for u, p in lista_usuarios: if username == u and password == p: + tools.initAPI() return True return False \ No newline at end of file diff --git a/configuracion/__pycache__/globales.cpython-310.pyc b/configuracion/__pycache__/globales.cpython-310.pyc deleted file mode 100644 index 9ad4a92..0000000 Binary files a/configuracion/__pycache__/globales.cpython-310.pyc and /dev/null differ diff --git a/configuracion/splashmix.py b/configuracion/splashmix.py index 17cb196..5348f64 100644 --- a/configuracion/splashmix.py +++ b/configuracion/splashmix.py @@ -5,5 +5,5 @@ selected_databank = Hotgirl creacion = "Hotgirl" #"Superhero" o "Hotgirl" -positions_path = "superheroes" +positions_path = "girlsAllPositions" # prob_position = 0.1 \ No newline at end of file diff --git a/funciones.py b/funciones.py index 8034c4d..b770ab0 100644 --- a/funciones.py +++ b/funciones.py @@ -57,15 +57,15 @@ def perform(input1, request: gr.Request): #MASS es la que ejecuta la aplicación EXTERNA def mass(input1): - ("Entré a mass...") + + client = gradio_client.Client(globales.api, hf_token=bridges.hug) + #client = gradio_client.Client("https://058d1a6dcdbaca0dcf.gradio.live/") #MiniProxy + imagenSource = gradio_client.handle_file(input1) print("Ésto es imagenSource después de ser procesada: ", imagenSource) imagenPosition = gradio_client.handle_file(splash_tools.getPosition()) creacion=splash_tools.creadorObjeto() prompt = prompter.prompteador(creacion) - - client = gradio_client.Client(globales.api, hf_token=bridges.hug) - #client = gradio_client.Client("https://058d1a6dcdbaca0dcf.gradio.live/") #MiniProxy print("Llegué a la ejecución de la API dentro de Mass:") try: diff --git a/globales.py b/globales.py index f7ceeb4..5c273de 100644 --- a/globales.py +++ b/globales.py @@ -1,7 +1,7 @@ import gradio as gr #MAIN -version = "4.5.13" +version = "4.6.13" env = "dev" aplicacion = "superheroes-dev" #como se llama en tu repo y tu dominio. #api = "Moibe/splashmix" diff --git a/sulkuFront.py b/sulkuFront.py index 649f5bf..bdf7c08 100644 --- a/sulkuFront.py +++ b/sulkuFront.py @@ -7,38 +7,13 @@ import threading from huggingface_hub import HfApi -result_from_displayTokens = None +result_from_displayTokens = None +result_from_initAPI = None -def initAPI(): - #PROCESO1 - global result_from_initAPI - - try: - repo_id = globales.api - api = HfApi(token=bridges.hug) - runtime = api.get_space_runtime(repo_id=repo_id) - print("Hardware: ", runtime.hardware) - print("Stage: ", runtime.stage) - #"RUNNING_BUILDING", "APP_STARTING", "SLEEPING", "RUNNING" - if runtime.stage == "SLEEPING": - print("Estoy durmiendo..., Despierta") - api.restart_space(repo_id=repo_id) - print("Desperando") - print("Hardware: ", runtime.hardware) - # #"cpu-basic" - - # client = gradio_client.Client(globales.api, hf_token=bridges.hug) - # print("Éste cliente: ", client.api_url) - result_from_initAPI = runtime.stage - # client = None - except Exception as e: - print("No api, encendiendo: ", e) - result_from_initAPI = str(e) +def displayTokens(request: gr.Request): - print("API Result displayed: ", result_from_initAPI) + global result_from_displayTokens -def displayTokens(request: gr.Request): - #PROCESO2 print("Running displayTokens...") novelty = sulkuPypi.getNovelty(sulkuPypi.encripta(request.username).decode("utf-8"), globales.aplicacion) if novelty == "new_user": @@ -46,29 +21,25 @@ def displayTokens(request: gr.Request): else: tokens = sulkuPypi.getTokens(sulkuPypi.encripta(request.username).decode("utf-8"), globales.env) display = visualizar_creditos(tokens, request.username) - - global result_from_displayTokens + result_from_displayTokens = display - print("Tokens displayed: ", result_from_displayTokens) - def precarga(request: gr.Request): - global result_from_initAPI - global result_from_displayTokens + # global result_from_initAPI + # global result_from_displayTokens - thread1 = threading.Thread(target=initAPI) + #thread1 = threading.Thread(target=initAPI) thread2 = threading.Thread(target=displayTokens, args=(request,)) - thread1.start() + #thread1.start() thread2.start() - thread1.join() # Espera a que el hilo 1 termine + #thread1.join() # Espera a que el hilo 1 termine thread2.join() # Espera a que el hilo 2 termine - return result_from_initAPI, result_from_displayTokens - - + #return result_from_initAPI, result_from_displayTokens + return result_from_displayTokens def visualizar_creditos(nuevos_creditos, usuario): @@ -90,12 +61,35 @@ def noCredit(usuario): def aError(usuario, tokens, excepcion): #aError se usa para llenar todos los elementos visuales en el front. - info_window = tools.manejadorExcepciones(excepcion) + info_window = manejadorExcepciones(excepcion) path = 'images/error.png' tokens = tokens html_credits = visualizar_creditos(tokens, usuario) return info_window, path, html_credits +def manejadorExcepciones(excepcion): + #El parámetro que recibe es el texto despliega ante determinada excepción: + if excepcion == "PAUSED": + info_window = "AI Engine Paused, ready soon." + elif excepcion == "RUNTIME_ERROR": + info_window = "Error building AI environment, please contact me." + elif excepcion == "STARTING": + info_window = "Server Powering UP, wait a few minutes and try again." + elif excepcion == "HANDSHAKE_ERROR": + info_window = "Connection error try again." + elif excepcion == "GENERAL": + info_window = "Network error, no credits were debited." + elif excepcion == "NO_FACE": + info_window = "Unable to detect a face in the image. Please upload a different photo with a clear face." + elif excepcion == "NO_FILE": + info_window = "No file, please add a valid archive." + elif "quota" in excepcion: #Caso especial porque el texto cambiará citando la cuota. + info_window = excepcion + else: + info_window = "Error. No credits were debited." + + return info_window + def presentacionFinal(usuario, accion): capsule = sulkuPypi.encripta(usuario).decode("utf-8") #decode es para quitarle el 'b diff --git a/tools.py b/tools.py index 8bab02b..6d825e7 100644 --- a/tools.py +++ b/tools.py @@ -1,6 +1,9 @@ import random import traceback import gradio as gr +import globales +from huggingface_hub import HfApi +import bridges def theme_selector(): temas_posibles = [ @@ -14,9 +17,31 @@ def theme_selector(): print("Tema random: ", tema) return tema -def titulizaExcepDeAPI(e): - #Resume una excepción a un título manejable. +def initAPI(): + + global result_from_initAPI + + try: + repo_id = globales.api + api = HfApi(token=bridges.hug) + runtime = api.get_space_runtime(repo_id=repo_id) + print("Stage: ", runtime.stage) + #"RUNNING_BUILDING", "APP_STARTING", "SLEEPING", "RUNNING", "PAUSED", "RUNTIME_ERROR" + if runtime.stage == "SLEEPING": + api.restart_space(repo_id=repo_id) + print("Desperando") + print("Hardware: ", runtime.hardware) + result_from_initAPI = runtime.stage + + except Exception as e: + #Creo que ya no debería de llegar aquí. + print("No api, encendiendo: ", e) + result_from_initAPI = str(e) + return result_from_initAPI + +def titulizaExcepDeAPI(e): + #Resume una excepción a un título manejable. if "RUNTIME_ERROR" in str(e): resultado = "RUNTIME_ERROR" #api mal construida tiene error. elif "PAUSED" in str(e): @@ -36,28 +61,7 @@ def titulizaExcepDeAPI(e): return resultado -def manejadorExcepciones(excepcion): - #El parámetro que recibe es el texto despliega ante determinada excepción: - if excepcion == "PAUSED": - info_window = "AI Engine Paused, ready soon." - elif excepcion == "RUNTIME_ERROR": - info_window = "Error building AI environment, please contact me." - elif excepcion == "STARTING": - info_window = "Server Powering UP, wait a few minutes and try again." - elif excepcion == "HANDSHAKE_ERROR": - info_window = "Connection error try again." - elif excepcion == "GENERAL": - info_window = "Network error, no credits were debited." - elif excepcion == "NO_FACE": - info_window = "Unable to detect a face in the image. Please upload a different photo with a clear face." - elif excepcion == "NO_FILE": - info_window = "No file, please add a valid archive." - elif "quota" in excepcion: #Caso especial porque el texto cambiará citando la cuota. - info_window = excepcion - else: - info_window = "Error. No credits were debited." - return info_window def recortadorQuota(texto_quota): # Encontrar el índice de inicio (después de "exception:")