Spaces:
Sleeping
Sleeping
Update app.py
Browse filesAtualização do erro em historico_dataframe
app.py
CHANGED
|
@@ -170,6 +170,31 @@ def carregar_historico_inicial():
|
|
| 170 |
# Inicializar Firestore ao carregar o app
|
| 171 |
_inicializar_firestore()
|
| 172 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 173 |
# ============================================
|
| 174 |
# FUNÇÕES DE GERAÇÃO (Sem alterações)
|
| 175 |
# ============================================
|
|
@@ -347,8 +372,11 @@ def gerar_post_interface(tema, nicho, estilo, formato, descricao_imagem, gerar_i
|
|
| 347 |
# Salvar no Histórico (DB e cache) e obter o estado atualizado
|
| 348 |
historico_atualizado = atualizar_historico(history_entry)
|
| 349 |
|
| 350 |
-
#
|
| 351 |
-
|
|
|
|
|
|
|
|
|
|
| 352 |
|
| 353 |
|
| 354 |
# ============================================
|
|
@@ -478,9 +506,9 @@ with gr.Blocks(theme=custom_theme, title="Gerador de Posts") as demo:
|
|
| 478 |
|
| 479 |
# Dataframe para o Histórico (usado como output)
|
| 480 |
historico_dataframe = gr.Dataframe(
|
| 481 |
-
headers=["Data/Hora", "
|
| 482 |
interactive=False,
|
| 483 |
-
value=post_history,
|
| 484 |
visible=False # Mantido invisível aqui, mas atualizado como output
|
| 485 |
)
|
| 486 |
|
|
@@ -498,10 +526,9 @@ with gr.Blocks(theme=custom_theme, title="Gerador de Posts") as demo:
|
|
| 498 |
|
| 499 |
# Dataframe de exibição que é atualizado pelo output do botão
|
| 500 |
historico_display = gr.Dataframe(
|
| 501 |
-
headers=["Data/Hora", "
|
| 502 |
interactive=False,
|
| 503 |
-
value=carregar_historico_inicial() # Carrega histórico (DB ou vazio)
|
| 504 |
-
|
| 505 |
)
|
| 506 |
# Garantir que o historico_display seja atualizado sempre que o historico_dataframe (invisível) for atualizado
|
| 507 |
historico_dataframe.change(lambda x: x, historico_dataframe, historico_display)
|
|
@@ -571,3 +598,4 @@ with gr.Blocks(theme=custom_theme, title="Gerador de Posts") as demo:
|
|
| 571 |
# Lançar aplicação
|
| 572 |
if __name__ == "__main__":
|
| 573 |
demo.launch()
|
|
|
|
|
|
| 170 |
# Inicializar Firestore ao carregar o app
|
| 171 |
_inicializar_firestore()
|
| 172 |
|
| 173 |
+
# ============================================
|
| 174 |
+
# HELPER FUNCTION PARA GRADIO
|
| 175 |
+
# ============================================
|
| 176 |
+
def _formatar_historico_para_df(history_list):
|
| 177 |
+
"""
|
| 178 |
+
Converte a lista de dicionários (do Firestore) para uma
|
| 179 |
+
lista de listas (para o gr.Dataframe).
|
| 180 |
+
"""
|
| 181 |
+
formatted_list = []
|
| 182 |
+
if not history_list:
|
| 183 |
+
return []
|
| 184 |
+
|
| 185 |
+
# A ordem DEVE bater com os headers do gr.Dataframe
|
| 186 |
+
for entry in history_list:
|
| 187 |
+
formatted_list.append([
|
| 188 |
+
entry.get("Data/Hora", ""),
|
| 189 |
+
entry.get("Tema", ""),
|
| 190 |
+
entry.get("Nicho", ""),
|
| 191 |
+
entry.get("Estilo", ""),
|
| 192 |
+
entry.get("Formato", ""),
|
| 193 |
+
entry.get("Texto (Preview)", ""),
|
| 194 |
+
entry.get("Status", "")
|
| 195 |
+
])
|
| 196 |
+
return formatted_list
|
| 197 |
+
|
| 198 |
# ============================================
|
| 199 |
# FUNÇÕES DE GERAÇÃO (Sem alterações)
|
| 200 |
# ============================================
|
|
|
|
| 372 |
# Salvar no Histórico (DB e cache) e obter o estado atualizado
|
| 373 |
historico_atualizado = atualizar_historico(history_entry)
|
| 374 |
|
| 375 |
+
# Formatar a lista de dicts para o formato de lista de listas do Gradio
|
| 376 |
+
historico_formatado_df = _formatar_historico_para_df(historico_atualizado)
|
| 377 |
+
|
| 378 |
+
# Retornar 4 valores na ordem: (texto, imagem, status, histórico formatado)
|
| 379 |
+
return texto, imagem, status_final, historico_formatado_df
|
| 380 |
|
| 381 |
|
| 382 |
# ============================================
|
|
|
|
| 506 |
|
| 507 |
# Dataframe para o Histórico (usado como output)
|
| 508 |
historico_dataframe = gr.Dataframe(
|
| 509 |
+
headers=["Data/Hora", "Tema", "Nicho", "Estilo", "Formato", "Texto (Preview)", "Status"],
|
| 510 |
interactive=False,
|
| 511 |
+
value=_formatar_historico_para_df(post_history), # Usar o cache formatado
|
| 512 |
visible=False # Mantido invisível aqui, mas atualizado como output
|
| 513 |
)
|
| 514 |
|
|
|
|
| 526 |
|
| 527 |
# Dataframe de exibição que é atualizado pelo output do botão
|
| 528 |
historico_display = gr.Dataframe(
|
| 529 |
+
headers=["Data/Hora", "Tema", "Nicho", "Estilo", "Formato", "Texto (Preview)", "Status"],
|
| 530 |
interactive=False,
|
| 531 |
+
value=_formatar_historico_para_df(carregar_historico_inicial()), # Carrega histórico (DB ou vazio) E FORMATA
|
|
|
|
| 532 |
)
|
| 533 |
# Garantir que o historico_display seja atualizado sempre que o historico_dataframe (invisível) for atualizado
|
| 534 |
historico_dataframe.change(lambda x: x, historico_dataframe, historico_display)
|
|
|
|
| 598 |
# Lançar aplicação
|
| 599 |
if __name__ == "__main__":
|
| 600 |
demo.launch()
|
| 601 |
+
|