Skip to content

Commit

Permalink
Major Update Api Selection and Quota Type
Browse files Browse the repository at this point in the history
  • Loading branch information
Moibe committed Dec 29, 2024
1 parent e5f69bf commit 8b06d80
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 54 deletions.
1 change: 1 addition & 0 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

def iniciar():
app_path = globales.app_path
main.queue(max_size=globales.max_size)
main.launch(auth=autorizador.authenticate, root_path=app_path, server_port=globales.server_port)

#Credit Related Elements
Expand Down
2 changes: 1 addition & 1 deletion autorizador.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def authenticate(username, password):
lista_usuarios = ast.literal_eval(cadena_usuarios)
for u, p in lista_usuarios:
if username == u and password == p:
api, tipo_api = tools.elijeAPI()
api, tipo_api = tools.eligeAPI(globales.seleccion_api)
tools.initAPI(api)
return True
return False
Binary file removed data/__pycache__/data.cpython-310.pyc
Binary file not shown.
Binary file removed data/__pycache__/data_girls.cpython-310.pyc
Binary file not shown.
Binary file removed data/__pycache__/data_heroes.cpython-310.pyc
Binary file not shown.
Binary file modified data/__pycache__/data_rev.cpython-310.pyc
Binary file not shown.
6 changes: 0 additions & 6 deletions debit_rules.py

This file was deleted.

23 changes: 6 additions & 17 deletions funciones.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@
import sulkuFront
import gradio as gr
import gradio_client
import splashmix.splash_tools as splash_tools
import splashmix.prompter as prompter
import tools
import time

tipo_api = None
import random
import splashmix.splash_tools as splash_tools

btn_buy = gr.Button("Get Credits", visible=False, size='lg')

Expand Down Expand Up @@ -47,12 +45,7 @@ def perform(input1, request: gr.Request):
#MASS es la que ejecuta la aplicación EXTERNA
def mass(input1):

if globales.same_api == False: #Si son diferentes apis, realiza el proceso de selección.
api, tipo_api = tools.elijeAPI()
print("Una vez elegido API, el tipo api es: ", tipo_api)
else: #Si no, deja la primera y no corras ningun proceso.
api = globales.api_zero
tipo_api = "cost"
api, tipo_api = tools.eligeAPI(globales.seleccion_api)

client = gradio_client.Client(api, hf_token=bridges.hug)
#client = gradio_client.Client("https://058d1a6dcdbaca0dcf.gradio.live/") #MiniProxy
Expand All @@ -69,7 +62,7 @@ def mass(input1):
#creacion.style = "Anime"
prompt = prompter.prompteador(creacion)
########################################

try:
result = client.predict(
imagenSource,
Expand All @@ -85,7 +78,7 @@ def mass(input1):
depth_strength=0.4,
controlnet_selection=["depth"], #pueden ser ['pose', 'canny', 'depth'] #Al parecer pose ya no.
guidance_scale=5,
seed=42,
seed=random.randint(0, 2147483647),
scheduler="EulerDiscreteScheduler",
enable_LCM=False,
enhance_face_region=True,
Expand All @@ -108,17 +101,13 @@ def mass(input1):
# result = ast.literal_eval(result)

#(Si llega aquí, debes debitar de la quota, incluso si detecto no-face o algo.)
if tipo_api == "gratis":
print("Como el tipo api fue gratis, si debitaremos la quota.")
if tipo_api == "quota":
sulkuPypi.updateQuota(globales.process_cost)
#No debitas la cuota si no era gratis, solo aplica para Zero.

result = tools.desTuplaResultado(result)
return result

except Exception as e:
print("Hubo un errora al ejecutar MASS:", e)
#Errores al correr la API.
#La no detección de un rostro es mandado aquí?! Siempre?
mensaje = tools.titulizaExcepDeAPI(e)
return mensaje
20 changes: 12 additions & 8 deletions globales.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
import gradio as gr

#MAIN
version = "0.0.3"
version = "1.0.3"
env = "prod"
aplicacion = "superheroes" #como se llama en tu repo y tu dominio.

#api = "Moibe/splashmix"
api_zero = "Moibe/InstantID2" #Risky but leave @ 25.
api_cost = "Moibe/InstantID2-B" #Corriendo en Zero, 22 segundos. Quota limitada.
same_api = False #Hay diferencia en las apis por eso si se debe correr proceso de selección.
#api = "charlieguo610/InstantID" #Corriendo en A10G, 22 segundos. Libre!!
#api = "InstantX/InstantID" #Como es externa pide 60s.

seleccion_api = "eligeQuotaOCosto" #eligeQuotaOCosto , eligeAOB o eligeGratisOCosto
max_size = 20
#Quota o Costo
api_zero = ("Moibe/InstantID2", "quota")
api_cost = ("Moibe/InstantID2-B", "costo")
#A o B
api_a = ("Moibe/sampler", "gratis") #Para music-sampler en particular aquí la diferencia será el formato: mp3
api_b = ("Moibe/music-separation", "gratis") #wav
#Gratis o Costo
api_gratis = ("Moibe/image-blend", "gratis")
api_costo = ("Moibe/image-blend", "costo")
process_cost = 25

seto = "splashmix"
Expand Down
80 changes: 58 additions & 22 deletions tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,63 @@ def theme_selector():
#print("Tema random: ", tema)
return tema

def eligeAPI(opcion):

funciones = {
"eligeQuotaOCosto": eligeQuotaOCosto,
"eligeAOB": eligeAOB,
"eligeGratisOCosto": eligeGratisOCosto
}

if opcion in funciones:
print("Opción en Funciones")
funcion_elegida = funciones[opcion]
api, tipo_api = funcion_elegida()
else:
print("Opción no válida")

return api, tipo_api

#Los tipos de elección son diferentes porque tienen diferentes reglas de negocio.

def eligeGratisOCosto():
#Se eligirá en los casos en los que sin costo funciona bien como Astroblend pero por si se quiere mejorar hacia Costo.
#Por ahora funcionará exactamente igual que eligeAoB, en el futuro se basará en reglas de membresía.
apis = [globales.api_a, globales.api_b]
api_elegida = random.choice(apis)
print("Print api elegida: ", api_elegida)
api, tipo_api = api_elegida
return api, tipo_api

def eligeAOB():
#Se eligirá cuando se tenga un control sobre la cantidad en queu y se redirija hacia una segunda fuente alternativa.
# Lista con las opciones
#apis = [globales.api_a, globales.api_b]
#api_elegida = random.choice(apis)
#IMPORTANTE, aquí A o B por ahora siempre será A, porque queremos que lo haga con MP3.
api_elegida = globales.api_a
print("Print api elegida: ", api_elegida)
api, tipo_api = api_elegida
return api, tipo_api

def eligeQuotaOCosto():
#Se eligirá en los casos en los que se use Zero, para extender las posibilidades de Quota y después usar Costo.
diferencia = sulkuPypi.getQuota() - globales.process_cost

if diferencia >= 0:
#Entonces puedes usar Zero.
api, tipo_api = globales.api_zero
#Además Si el resultado puede usar la Zero "por última vez", debe de ir prendiendo la otra.
#if diferencia es menor que el costo de un sig. del proceso, ve iniciando ya la otra API.
if diferencia < globales.process_cost:
print("Preventivamente iremos prendiendo la otra.")
initAPI(globales.api_cost)
else:
api, tipo_api = globales.api_cost

print("La API elegida es: ", api)
return api, tipo_api

def initAPI(api):

global result_from_initAPI
Expand Down Expand Up @@ -117,25 +174,4 @@ def desTuplaResultado(resultado):
# mensaje = "concurrent.futures._base.CancelledError"
# concurrents = concurrents + 1
finally:
pass

def elijeAPI():

diferencia = sulkuPypi.getQuota() - globales.process_cost

if diferencia >= 0:
#Puedes usar Zero.
api = globales.api_zero
tipo_api = "gratis"
#Además Si el resultado puede usar la Zero "por última vez", debe de ir prendiendo la otra.
#if diferencia es menor que el costo de un sig. del proceso, ve iniciando ya la otra API.
if diferencia < globales.process_cost:
print("Preventivamente iremos prendiendo la otra.")
initAPI(globales.api_cost)
else:
api = globales.api_cost
tipo_api = "costo"

print("La API elegida es: ", api)

return api, tipo_api
pass

0 comments on commit 8b06d80

Please sign in to comment.