Spaces:
Runtime error
Runtime error
coder
commited on
Commit
·
d5f461a
1
Parent(s):
e8e0c14
update home
Browse files
Home.py
CHANGED
|
@@ -1,10 +1,17 @@
|
|
| 1 |
from core.controllers.pages_controller import Page
|
| 2 |
-
from
|
| 3 |
-
from pages.LiveDemo import Live_Demo
|
| 4 |
|
| 5 |
|
| 6 |
class Home(Page):
|
| 7 |
variables_globales = {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
}
|
| 9 |
archivos_css = ["main",
|
| 10 |
"home"]
|
|
@@ -12,92 +19,131 @@ class Home(Page):
|
|
| 12 |
def __init__(self, title=str("Bienvenido"), icon=str("🖼️"), init_page=False):
|
| 13 |
super().__init__()
|
| 14 |
if init_page:
|
| 15 |
-
self.new_page(title=title,
|
| 16 |
-
|
| 17 |
self.init_globals(globals=self.variables_globales)
|
| 18 |
for archivo in self.archivos_css:
|
| 19 |
self.cargar_css(archivo_css=archivo)
|
| 20 |
|
| 21 |
-
def
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
help=None,
|
| 55 |
-
body="""
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
|
| 93 |
def build(self):
|
| 94 |
# secciones
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
self.agregar_card_bienvenido(columna_bienvenido)
|
| 98 |
-
self.agregar_card_teoria(columna_botones)
|
| 99 |
-
self.agregar_card_live_demo(columna_botones)
|
| 100 |
-
self.agregar_card_about_me(columna_botones)
|
| 101 |
|
| 102 |
|
| 103 |
if __name__ == "__main__":
|
|
|
|
| 1 |
from core.controllers.pages_controller import Page
|
| 2 |
+
from core.controllers.main_process import Generador
|
|
|
|
| 3 |
|
| 4 |
|
| 5 |
class Home(Page):
|
| 6 |
variables_globales = {
|
| 7 |
+
"img_bytes": None,
|
| 8 |
+
"img_src": None,
|
| 9 |
+
"settings": {
|
| 10 |
+
"model": str("google/vit-base-patch16-224"),
|
| 11 |
+
"tokenizer": str("google/vit-base-patch16-224"),
|
| 12 |
+
},
|
| 13 |
+
"img_output": None,
|
| 14 |
+
"predicciones": None,
|
| 15 |
}
|
| 16 |
archivos_css = ["main",
|
| 17 |
"home"]
|
|
|
|
| 19 |
def __init__(self, title=str("Bienvenido"), icon=str("🖼️"), init_page=False):
|
| 20 |
super().__init__()
|
| 21 |
if init_page:
|
| 22 |
+
self.new_page(title=title,
|
| 23 |
+
icon=icon)
|
| 24 |
self.init_globals(globals=self.variables_globales)
|
| 25 |
for archivo in self.archivos_css:
|
| 26 |
self.cargar_css(archivo_css=archivo)
|
| 27 |
|
| 28 |
+
def obtener_bytes(self, archivo):
|
| 29 |
+
self.set_global(key='img_src',
|
| 30 |
+
value=archivo)
|
| 31 |
+
self.set_global(key='img_bytes',
|
| 32 |
+
value=archivo.getvalue())
|
| 33 |
+
|
| 34 |
+
def actualizar_modelo_tokenizer(self, modelo, tokenizer):
|
| 35 |
+
self.set_global(key='settings',
|
| 36 |
+
value={'model': modelo,
|
| 37 |
+
'tokenizer': tokenizer})
|
| 38 |
+
|
| 39 |
+
def procesar_imagen(self):
|
| 40 |
+
proceso = Generador(configuraciones=self.get_global('settings'))
|
| 41 |
+
proceso.generar_prediccion(imagen_bytes=self.imgg.open(
|
| 42 |
+
self.get_global('img_src')).convert("RGB"))
|
| 43 |
+
self.set_global(key='img_output', value=self.get_global('img_bytes'))
|
| 44 |
+
self.set_global(key='predicciones', value=proceso.prediccion)
|
| 45 |
+
|
| 46 |
+
def expander_instrucciones(self, placeholder):
|
| 47 |
+
instrucciones = placeholder.expander(expanded=False,
|
| 48 |
+
label="Instrucciones")
|
| 49 |
+
instrucciones.markdown(unsafe_allow_html=False,
|
| 50 |
+
help=None,
|
| 51 |
+
body="""
|
| 52 |
+
1. **Cargue su Imagen Base**:
|
| 53 |
+
|
| 54 |
+
De click o toque con el dedo en la opción *"Imagen Base"* para cargar su imagen.
|
| 55 |
+
|
| 56 |
+
Tendrá dos opciones para cargar su imagen:
|
| 57 |
+
|
| 58 |
+
* **Desde Galería**: cargue la imagen desde la galería de su teléfono o computadora.
|
| 59 |
+
|
| 60 |
+
* **Desde su cámara**: cargue la imagen directamente desde la cámara de su teléfono o computadora.
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
2. **Clasificación / Predicciones**:
|
| 64 |
+
|
| 65 |
+
Realice la **clasificación de su imagen** con base a las predicciones realizadas por el **modelo** pre-entrenado seleccionado.
|
| 66 |
+
|
| 67 |
+
A partir del dataset con el que fue pre-entrenado el modelo, tratará de predecir cuales son los objetos en la imagen cargada.
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
* **Configuraciones Avanzadas**:
|
| 71 |
+
|
| 72 |
+
*Elija un modelo y procesador de la lista disponible, o elija uno directamente de la base de modelos disponible en HuggingFace.*
|
| 73 |
+
""")
|
| 74 |
+
|
| 75 |
+
def expander_imagen_base(self, placeholder):
|
| 76 |
+
imagen_base = placeholder.expander(expanded=False,
|
| 77 |
+
label="Imagen base")
|
| 78 |
+
imagen_base.markdown(unsafe_allow_html=False,
|
| 79 |
help=None,
|
| 80 |
+
body="""
|
| 81 |
+
**Cargue su Imagen Base**:
|
| 82 |
+
""")
|
| 83 |
+
archivo_expander = imagen_base.expander(expanded=False,
|
| 84 |
+
label="Desde galería")
|
| 85 |
+
_archivo = archivo_expander.file_uploader(label="Galería",
|
| 86 |
+
accept_multiple_files=False,
|
| 87 |
+
label_visibility="visible")
|
| 88 |
+
if (archivo_expander.button(label="Cargar Archivo", help="Suba un archivo.",
|
| 89 |
+
type="secondary", use_container_width=True) and _archivo is not None):
|
| 90 |
+
self.obtener_bytes(_archivo)
|
| 91 |
+
|
| 92 |
+
camara_expander = imagen_base.expander(
|
| 93 |
+
expanded=False, label="Desde cámara")
|
| 94 |
+
_captura = camara_expander.camera_input(
|
| 95 |
+
label="Cámara", label_visibility="visible")
|
| 96 |
+
if (camara_expander.button(label="Cargar Captura", type="secondary", use_container_width=True,
|
| 97 |
+
help="Tome una fotografía.") and _captura is not None):
|
| 98 |
+
self.obtener_bytes(_captura)
|
| 99 |
+
|
| 100 |
+
def expander_configuraciones(self, placeholder):
|
| 101 |
+
configuraciones = placeholder.expander(
|
| 102 |
+
expanded=False, label="Configuraciones")
|
| 103 |
+
modelo = configuraciones.text_input(
|
| 104 |
+
label="MODELO", on_change=None, label_visibility="visible",
|
| 105 |
+
value=self.get_global('settings').get('model'))
|
| 106 |
+
tokenizer = configuraciones.text_input(
|
| 107 |
+
label="TOKENIZER", on_change=None, label_visibility="visible",
|
| 108 |
+
value=self.get_global('settings').get('tokenizer'))
|
| 109 |
+
|
| 110 |
+
if configuraciones.button(label="Configurar", type="secondary", use_container_width=True,
|
| 111 |
+
help="Actualice configuraciones"):
|
| 112 |
+
self.actualizar_modelo_tokenizer(modelo, tokenizer)
|
| 113 |
+
|
| 114 |
+
def resultados(self, placeholder):
|
| 115 |
+
card_teoria = placeholder.container()
|
| 116 |
+
|
| 117 |
+
if self.get_global('img_output', None) is not None:
|
| 118 |
+
card_teoria.image(
|
| 119 |
+
image=self.get_global('img_output'),
|
| 120 |
+
caption="Su resultado",
|
| 121 |
+
use_column_width="auto",
|
| 122 |
+
channels="RGB",
|
| 123 |
+
output_format="auto"
|
| 124 |
+
)
|
| 125 |
+
if self.get_global('predicciones', None) is not None:
|
| 126 |
+
card_teoria.success(body=self.get_global(
|
| 127 |
+
'predicciones'), icon=None)
|
| 128 |
+
|
| 129 |
+
def agregar_card_base(self, columna):
|
| 130 |
+
card_principal = columna.container()
|
| 131 |
+
|
| 132 |
+
columna_inputs, columna_outputs = card_principal.columns(
|
| 133 |
+
2, gap="small")
|
| 134 |
+
|
| 135 |
+
self.expander_instrucciones(columna_inputs)
|
| 136 |
+
self.expander_imagen_base(columna_inputs)
|
| 137 |
+
self.expander_configuraciones(columna_inputs)
|
| 138 |
+
if columna_inputs.button(label="Clasificar", help="Realizar Predicciones",
|
| 139 |
+
type="secondary", use_container_width=True):
|
| 140 |
+
self.procesar_imagen()
|
| 141 |
+
self.resultados(columna_outputs)
|
| 142 |
|
| 143 |
def build(self):
|
| 144 |
# secciones
|
| 145 |
+
columna_principal = self.get_body().columns(1, gap="small")[0]
|
| 146 |
+
self.agregar_card_base(columna_principal)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 147 |
|
| 148 |
|
| 149 |
if __name__ == "__main__":
|