Edoruin commited on
Commit
9464cfa
·
1 Parent(s): b04f82f

fix main.py: solving icon function flet sintaxis error

Browse files
Files changed (1) hide show
  1. app/main.py +32 -104
app/main.py CHANGED
@@ -1,124 +1,52 @@
1
  import flet as ft
2
  import gitlab
3
  import os
4
- import base64
5
 
6
  def main(page: ft.Page):
7
  page.title = "MAKERSPACE DATABASE"
8
  page.theme_mode = ft.ThemeMode.DARK
9
- page.padding = 20
10
-
11
- # --- 1. CONFIGURACIÓN Y CONEXIÓN INICIAL ---
12
  GITLAB_URL = os.getenv("GITLAB_URL", "https://gitlab.com")
13
  TOKEN = os.getenv("GITLAB_TOKEN")
14
  GROUP_ID = os.getenv("GITLAB_GROUP_ID")
15
 
16
- # Contenedores de interfaz
17
- repo_list = ft.ListView(expand=1, spacing=10, padding=20)
18
- loading_indicator = ft.ProgressBar(visible=False, color="blue")
19
-
20
- # Validar presencia de variables
21
- if not TOKEN or not GROUP_ID:
22
- page.add(ft.Banner(
23
- bgcolor=ft.colors.AMBER_100,
24
- leading=ft.Icon(ft.icons.WARNING_AMBER, color=ft.colors.AMBER, size=40),
25
- content=ft.Text("ERROR: Faltan variables de entorno (TOKEN o GROUP_ID) en Hugging Face.", color="black"),
26
- ))
27
- page.banner.open = True
28
- page.update()
29
- return
30
 
31
- # Intento de autenticación inicial
32
  try:
33
- gl = gitlab.Gitlab(GITLAB_URL, private_token=TOKEN, timeout=10)
 
34
  gl.auth()
 
35
  target_group = gl.groups.get(GROUP_ID)
36
- except gitlab.exceptions.GitlabAuthenticationError:
37
- page.add(ft.Text("❌ Error: Token de GitLab inválido o expirado.", color="red", size=18))
38
- return
39
- except Exception as e:
40
- page.add(ft.Text(f"❌ Error de conexión con GitLab: {e}", color="red"))
41
- return
42
-
43
- # --- 2. LÓGICA DE CARGA DE PROYECTOS ---
44
- def load_projects(e=None):
45
- loading_indicator.visible = True
46
- repo_list.controls.clear()
47
- page.update()
48
-
49
- try:
50
- # Traer proyectos específicamente del grupo
51
- projects = target_group.projects.list(all=True, include_subgroups=True)
52
-
53
- if not projects:
54
- repo_list.controls.append(ft.Text("No se encontraron proyectos en este grupo.", italic=True))
55
-
56
- for p in projects:
57
- try:
58
- # Creamos la tarjeta del proyecto con su propio manejo de errores
59
- repo_list.controls.append(
60
- ft.Container(
61
- content=ft.ListTile(
62
- leading=ft.Icon(ft.icons.FOLDER),
63
- title=ft.Text(p.name, weight="bold"),
64
- subtitle=ft.Text(f"ID: {p.id} • Creado: {p.created_at[:10]}"),
65
- trailing=ft.IconButton(
66
- icon=ft.icons.DOWNLOAD,
67
- on_click=lambda _, pid=p.id: page.launch_url(
68
- f"{GITLAB_URL}/api/v4/projects/{pid}/repository/archive.zip?private_token={TOKEN}"
69
- )
70
- ),
71
- ),
72
- bgcolor=ft.colors.SURFACE_VARIANT,
73
- border_radius=10,
74
- )
75
- )
76
- except Exception:
77
- continue # Si un proyecto falla, saltamos al siguiente
78
-
79
- except Exception as ex:
80
  repo_list.controls.append(
81
- ft.Text(f"⚠️ Error al listar proyectos: {ex}", color="amber")
 
 
 
 
 
82
  )
83
-
84
- finally:
85
- loading_indicator.visible = False
86
- page.update()
87
 
88
- # --- 3. CONSTRUCCIÓN DE LA INTERFAZ ---
89
- try:
90
- page.add(
91
- ft.Row([
92
- ft.Icon(ft.icons.GROUPS, color="blue", size=30),
93
- ft.Column([
94
- ft.Text("MAKERSPACE DATABASE", size=25, weight="bold"),
95
- ft.Text(f"Grupo: {target_group.name}", size=15, color="blue")
96
- ])
97
- ], alignment=ft.MainAxisAlignment.START),
98
- ft.Divider(),
99
- loading_indicator,
100
- repo_list,
101
- ft.FloatingActionButton(
102
- icon=ft.icons.REFRESH,
103
- on_click=load_projects,
104
- tooltip="Actualizar lista"
105
- )
106
- )
107
- # Carga inicial
108
- load_projects()
109
-
110
- except Exception as ui_error:
111
- page.add(ft.Text(f"Error crítico de interfaz: {ui_error}"))
112
 
113
- # --- 4. ARRANQUE DEL SERVIDOR (HUGGING FACE COMPATIBLE) ---
114
  if __name__ == "__main__":
115
- try:
116
- port_env = os.getenv("PORT", "7860")
117
- ft.app(
118
- target=main,
119
- view=ft.AppView.WEB_BROWSER,
120
- host="0.0.0.0",
121
- port=int(port_env)
122
- )
123
- except Exception as startup_error:
124
- print(f"Fallo al iniciar la aplicación: {startup_error}")
 
1
  import flet as ft
2
  import gitlab
3
  import os
 
4
 
5
  def main(page: ft.Page):
6
  page.title = "MAKERSPACE DATABASE"
7
  page.theme_mode = ft.ThemeMode.DARK
8
+
9
+ # Variables de entorno
 
10
  GITLAB_URL = os.getenv("GITLAB_URL", "https://gitlab.com")
11
  TOKEN = os.getenv("GITLAB_TOKEN")
12
  GROUP_ID = os.getenv("GITLAB_GROUP_ID")
13
 
14
+ # Contenedor de lista
15
+ repo_list = ft.ListView(expand=1, spacing=10)
 
 
 
 
 
 
 
 
 
 
 
 
16
 
 
17
  try:
18
+ # CONEXIÓN BASE (Sin /api/v4 ni URLs de grupos)
19
+ gl = gitlab.Gitlab(GITLAB_URL, private_token=TOKEN)
20
  gl.auth()
21
+ # Obtener el grupo por su ID NUMÉRICO
22
  target_group = gl.groups.get(GROUP_ID)
23
+
24
+ group_title = ft.Text(f"Grupo: {target_group.name}", size=15, color="blue")
25
+
26
+ # Cargar proyectos
27
+ projects = target_group.projects.list(all=True)
28
+ for p in projects:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  repo_list.controls.append(
30
+ ft.ListTile(
31
+ # Nota el cambio a ft.Icons (con I mayúscula)
32
+ leading=ft.Icon(ft.Icons.FOLDER_OPEN),
33
+ title=ft.Text(p.name),
34
+ subtitle=ft.Text(f"ID: {p.id}")
35
+ )
36
  )
37
+ except Exception as e:
38
+ page.add(ft.Text(f"Error de conexión: Verifica GITLAB_URL y GROUP_ID numérico.", color="red"))
39
+ print(f"Detalle técnico: {e}")
40
+ return
41
 
42
+ page.add(
43
+ ft.Text("MAKERSPACE DATABASE", size=25, weight="bold"),
44
+ group_title,
45
+ ft.Divider(),
46
+ repo_list
47
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
 
 
49
  if __name__ == "__main__":
50
+ # Puerto obligatorio para Hugging Face
51
+ port = int(os.getenv("PORT", 7860))
52
+ ft.app(target=main, view=ft.AppView.WEB_BROWSER, host="0.0.0.0", port=port)