Skip to content

Commit

Permalink
Quota debits only on Zero
Browse files Browse the repository at this point in the history
  • Loading branch information
Moibe committed Dec 13, 2024
1 parent af12384 commit 0cff4de
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 13 deletions.
23 changes: 15 additions & 8 deletions funciones.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import tools
import time

tipo_api = None

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

#PERFORM es la app INTERNA que llamará a la app externa.
Expand All @@ -22,17 +24,14 @@ def perform(input1, request: gr.Request):
try:
resultado = mass(input1)
#El resultado ya viene destuplado.
except Exception as e:
except Exception as e:
info_window, resultado, html_credits = sulkuFront.aError(request.username, tokens, excepcion = tools.titulizaExcepDeAPI(e))
return resultado, info_window, html_credits, btn_buy
else:
#Si no hubo autorización.
info_window, resultado, html_credits = sulkuFront.noCredit(request.username)
return resultado, info_window, html_credits, btn_buy

#(Si llega aquí, debes debitar de la quota.)
sulkuPypi.updateQuota(globales.process_cost)


#Primero revisa si es imagen!:
if "image.webp" in resultado:
#Si es imagen, debitarás.
Expand All @@ -47,8 +46,10 @@ def perform(input1, request: gr.Request):

#MASS es la que ejecuta la aplicación EXTERNA
def mass(input1):

api = tools.elijeAPI()

api, tipo_api = tools.elijeAPI()
print("Una vez elegido API, el tipo api es: ", tipo_api)

client = gradio_client.Client(api, hf_token=bridges.hug)
#client = gradio_client.Client("https://058d1a6dcdbaca0dcf.gradio.live/") #MiniProxy

Expand Down Expand Up @@ -100,7 +101,13 @@ def mass(input1):
# )

# #Si viene del miniproxy, hay que rehacer la tupla.
# result = ast.literal_eval(result)
# 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.")
sulkuPypi.updateQuota(globales.process_cost)
#No debitas la cuota si no era gratis, solo aplica para Zero.

result = tools.desTuplaResultado(result)
return result
Expand Down
2 changes: 1 addition & 1 deletion globales.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import gradio as gr

#MAIN
version = "5.12.18"
version = "5.13.18"
env = "dev"
aplicacion = "superheroes-dev" #como se llama en tu repo y tu dominio.

Expand Down
Binary file added images/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion sulkuFront.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import gradio as gr
import threading
import sulkuMessages
import time

result_from_displayTokens = None
result_from_initAPI = None
Expand Down
1 change: 0 additions & 1 deletion sulkuPypi.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ def getQuota():

if response.status_code == 200:
quota = response.json()
print("Quota:", quota)
else:
error = f"Error al obtener el elemento todo: {response.status_code}"
return error
Expand Down
14 changes: 12 additions & 2 deletions tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import sulkuPypi
import time



def theme_selector():
temas_posibles = [
gr.themes.Base(),
Expand All @@ -23,7 +25,7 @@ def initAPI():
global result_from_initAPI

try:
api = elijeAPI()
api, tipo_api = elijeAPI()
repo_id = api
api = HfApi(token=bridges.hug)
runtime = api.get_space_runtime(repo_id=repo_id)
Expand Down Expand Up @@ -123,10 +125,18 @@ def desTuplaResultado(resultado):
pass

def elijeAPI():

global tipo_api

#Si el resultado puede usar la Zero "por última vez", debe de ir prendiendo la otra.
if sulkuPypi.getQuota() >= globales.process_cost:
#Puedes usar Zero.
api = globales.api_zero
tipo_api = "gratis"
else:
api = globales.api_cost
tipo_api = "costo"

print("La API elejida es: ", api)
return api

return api, tipo_api

0 comments on commit 0cff4de

Please sign in to comment.