Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,6 @@
|
|
| 1 |
-
|
| 2 |
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 3 |
-
# β PIPELINE v31: AUTO-PLAN ROBUSTO
|
| 4 |
-
# β 1ΒΊ:
|
| 5 |
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 6 |
|
| 7 |
import os
|
|
@@ -12,7 +11,7 @@ from datetime import datetime
|
|
| 12 |
import gradio as gr
|
| 13 |
import google.generativeai as genai
|
| 14 |
|
| 15 |
-
# ==================== 1. CONFIGURAΓΓO ====================
|
| 16 |
api_key = os.getenv("GOOGLE_API_KEY", "SUA_API_KEY_AQUI")
|
| 17 |
if api_key:
|
| 18 |
genai.configure(api_key=api_key)
|
|
@@ -20,11 +19,12 @@ if api_key:
|
|
| 20 |
model_pro = genai.GenerativeModel("gemini-pro-latest")
|
| 21 |
else:
|
| 22 |
model_flash = model_pro = None
|
|
|
|
| 23 |
|
| 24 |
ARQUIVO_CONFIG = "protocolo.json"
|
| 25 |
ARQUIVO_HISTORY = "history_v31.json"
|
| 26 |
|
| 27 |
-
# ==================== 2. UTILIDADES
|
| 28 |
def carregar_protocolo():
|
| 29 |
try:
|
| 30 |
with open(ARQUIVO_CONFIG, "r", encoding="utf-8") as f:
|
|
@@ -63,69 +63,63 @@ def ler_anexo(arquivo):
|
|
| 63 |
return f"\n\n[ANEXO: {os.path.basename(arquivo.name)}]\n{f.read()}\n[FIM ANEXO]\n"
|
| 64 |
except: return ""
|
| 65 |
|
| 66 |
-
# ==================== 3. PLANEJADOR AUTO
|
| 67 |
def criar_plano_auto(full_input, history_contexto):
|
| 68 |
-
"""
|
| 69 |
if not model_pro:
|
| 70 |
-
return
|
| 71 |
|
| 72 |
-
# PLANO
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
|
|
|
| 77 |
|
| 78 |
history_resumo = ""
|
| 79 |
-
if history_contexto:
|
| 80 |
history_resumo = "\n".join([f"π€: {h[0][:100]}..." for h in history_contexto[-2:]])[:200]
|
| 81 |
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
CRIE PLANO JSON de 2-4 agentes:
|
| 86 |
-
|
| 87 |
-
{{"nome": "Nome", "missao": "MissΓ£o curta", "modelo": "flash", "tipo_saida": "texto"}}
|
| 88 |
|
| 89 |
-
|
| 90 |
-
```
|
| 91 |
[
|
| 92 |
{{"nome": "Analisador", "missao": "Analise input", "modelo": "flash", "tipo_saida": "json"}},
|
| 93 |
{{"nome": "Final", "missao": "Resposta final", "modelo": "pro", "tipo_saida": "texto"}}
|
| 94 |
]
|
| 95 |
-
|
|
|
|
| 96 |
|
| 97 |
try:
|
|
|
|
| 98 |
resp = model_pro.generate_content(prompt_planejador, temperature=0.1)
|
| 99 |
plano_raw = resp.text.strip()
|
| 100 |
|
| 101 |
-
|
| 102 |
-
print(f"DEBUG PLANO RAW: {plano_raw[:300]}...")
|
| 103 |
|
| 104 |
-
#
|
| 105 |
plano_raw = re.sub(r'``````|```
|
| 106 |
-
plano_raw = re.sub(r'^.*?\[', '[', plano_raw)
|
| 107 |
-
plano_raw = re.sub(r'\].*?$', ']', plano_raw)
|
|
|
|
| 108 |
|
| 109 |
-
print(f"
|
| 110 |
|
| 111 |
plano = json.loads(plano_raw)
|
| 112 |
|
| 113 |
-
if isinstance(plano, list) and len(plano) >= 2:
|
| 114 |
-
print(f"β
PLANO
|
| 115 |
-
return plano, f"β
Plano: {len(plano)} agentes"
|
| 116 |
|
| 117 |
-
print(
|
| 118 |
-
return
|
| 119 |
|
| 120 |
-
except json.JSONDecodeError as e:
|
| 121 |
-
print(f"β JSON ERROR: {str(e)[:100]}")
|
| 122 |
-
print(f"RAW FALHOU: {plano_raw[:200]}")
|
| 123 |
-
return plano_fallback, f"β οΈ Fallback ativo (JSON: {str(e)[:50]})"
|
| 124 |
except Exception as e:
|
| 125 |
-
print(f"β
|
| 126 |
-
return
|
| 127 |
|
| 128 |
-
# ==================== 4.
|
| 129 |
def executar_no(timeline, config):
|
| 130 |
if not (model_flash or model_pro):
|
| 131 |
return {"role": "system", "error": "Sem API"}, "(ERRO: API)", "Sem key"
|
|
@@ -133,27 +127,35 @@ def executar_no(timeline, config):
|
|
| 133 |
modelo = model_pro if config.get("modelo") == "pro" else model_flash
|
| 134 |
contexto = json.dumps(timeline[-8:], ensure_ascii=False, indent=2)
|
| 135 |
|
| 136 |
-
prompt = f"""TIMELINE
|
|
|
|
|
|
|
| 137 |
AGENTE: {config['nome']}
|
| 138 |
MISSΓO: {config['missao']}"""
|
| 139 |
|
| 140 |
-
log = f"
|
| 141 |
try:
|
| 142 |
inicio = time.time()
|
| 143 |
resp = modelo.generate_content(prompt)
|
| 144 |
out = resp.text.strip()
|
| 145 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 146 |
tempo = time.time() - inicio
|
| 147 |
-
content = json.loads(re.sub(r'```json|```
|
| 148 |
-
|
| 149 |
log += f" β {tempo:.1f}s"
|
| 150 |
return {"role": "assistant", "agent": config['nome'], "content": content}, log, out
|
| 151 |
-
except:
|
| 152 |
-
log += " β
|
| 153 |
-
return {"role": "system", "error":
|
| 154 |
|
| 155 |
-
# ==================== 5. ORQUESTRADOR
|
| 156 |
def orquestrador(texto, arquivo, history, json_config):
|
|
|
|
| 157 |
anexo = ler_anexo(arquivo)
|
| 158 |
full_input = f"{texto}\n{anexo}".strip()
|
| 159 |
|
|
@@ -163,37 +165,40 @@ def orquestrador(texto, arquivo, history, json_config):
|
|
| 163 |
|
| 164 |
history = history + [[texto + (" π" if arquivo else ""), None]]
|
| 165 |
timeline = [{"role": "user", "content": full_input}]
|
| 166 |
-
logs = f"π v31
|
| 167 |
|
| 168 |
-
|
|
|
|
| 169 |
yield history, timeline, logs
|
| 170 |
|
| 171 |
-
# PLANEJADOR ROBUSTO
|
| 172 |
plano, log_plano = criar_plano_auto(full_input, history)
|
| 173 |
logs += f"PLANO: {log_plano}\n"
|
| 174 |
-
timeline.append({"role": "system", "
|
| 175 |
|
| 176 |
history[-1] = f"β
{log_plano}"[1]
|
| 177 |
yield history, timeline, logs
|
| 178 |
|
| 179 |
-
# EXECUTA PLANO
|
|
|
|
| 180 |
for i, cfg in enumerate(plano):
|
| 181 |
-
history[-1] = f"[{i+1}/{len(plano)}] {cfg['nome']}..."[1]
|
| 182 |
yield history, timeline, logs
|
| 183 |
|
| 184 |
res, log_add, raw = executar_no(timeline, cfg)
|
| 185 |
timeline.append(res)
|
| 186 |
logs += f" {log_add}\n"
|
| 187 |
|
| 188 |
-
if cfg.get('tipo_saida') == 'texto' and 'content'
|
| 189 |
-
|
|
|
|
|
|
|
| 190 |
yield history, timeline, logs
|
| 191 |
|
|
|
|
| 192 |
salvar_history(history)
|
| 193 |
-
logs += "β
v31 OK"
|
| 194 |
yield history, timeline, logs
|
| 195 |
|
| 196 |
-
# ==================== 6. UI
|
| 197 |
def ui_clean():
|
| 198 |
css = """
|
| 199 |
footer {display: none !important;}
|
|
@@ -202,40 +207,90 @@ def ui_clean():
|
|
| 202 |
|
| 203 |
config_init = carregar_protocolo()
|
| 204 |
|
| 205 |
-
with gr.Blocks(title="PIPELINE v31 - AUTO-PLAN ROBUSTO", css=css, theme=gr.themes.Soft()) as app:
|
|
|
|
|
|
|
|
|
|
| 206 |
with gr.Tabs():
|
|
|
|
| 207 |
with gr.Tab("π¬ Pipeline"):
|
| 208 |
-
chatbot = gr.Chatbot(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 209 |
|
| 210 |
with gr.Row():
|
| 211 |
with gr.Column(scale=10):
|
| 212 |
-
txt_in = gr.Textbox(
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 217 |
|
| 218 |
-
file_status = gr.Markdown("")
|
| 219 |
-
file_in.upload(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 220 |
|
| 221 |
-
|
|
|
|
| 222 |
with gr.Row():
|
| 223 |
-
out_dna = gr.JSON(label="Timeline")
|
| 224 |
-
out_logs = gr.Textbox(label="Logs
|
| 225 |
|
|
|
|
| 226 |
with gr.Tab("βοΈ Config"):
|
| 227 |
-
|
| 228 |
-
gr.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 229 |
|
|
|
|
| 230 |
triggers = [btn_send.click, txt_in.submit]
|
| 231 |
for trig in triggers:
|
| 232 |
-
trig(
|
| 233 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 234 |
)
|
| 235 |
|
| 236 |
return app
|
| 237 |
|
|
|
|
| 238 |
if __name__ == "__main__":
|
| 239 |
-
print("π v31
|
|
|
|
|
|
|
|
|
|
|
|
|
| 240 |
app = ui_clean()
|
| 241 |
-
app.launch(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 2 |
+
# β PIPELINE v31: AUTO-PLAN ROBUSTO COMPLETO | HF SPACES 100% OK β
|
| 3 |
+
# β 1ΒΊ: CRIA PLANO β 2ΒΊ: EXECUTA β SEM ERROS "β Erro plano" β
|
| 4 |
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 5 |
|
| 6 |
import os
|
|
|
|
| 11 |
import gradio as gr
|
| 12 |
import google.generativeai as genai
|
| 13 |
|
| 14 |
+
# ==================== 1. CONFIGURAΓΓO GLOBAL ====================
|
| 15 |
api_key = os.getenv("GOOGLE_API_KEY", "SUA_API_KEY_AQUI")
|
| 16 |
if api_key:
|
| 17 |
genai.configure(api_key=api_key)
|
|
|
|
| 19 |
model_pro = genai.GenerativeModel("gemini-pro-latest")
|
| 20 |
else:
|
| 21 |
model_flash = model_pro = None
|
| 22 |
+
print("β οΈ Sem GOOGLE_API_KEY - usando modo demo")
|
| 23 |
|
| 24 |
ARQUIVO_CONFIG = "protocolo.json"
|
| 25 |
ARQUIVO_HISTORY = "history_v31.json"
|
| 26 |
|
| 27 |
+
# ==================== 2. UTILIDADES COMPLETAS ====================
|
| 28 |
def carregar_protocolo():
|
| 29 |
try:
|
| 30 |
with open(ARQUIVO_CONFIG, "r", encoding="utf-8") as f:
|
|
|
|
| 63 |
return f"\n\n[ANEXO: {os.path.basename(arquivo.name)}]\n{f.read()}\n[FIM ANEXO]\n"
|
| 64 |
except: return ""
|
| 65 |
|
| 66 |
+
# ==================== 3. PLANEJADOR AUTO-ROBUSTO ====================
|
| 67 |
def criar_plano_auto(full_input, history_contexto):
|
| 68 |
+
"""CRIA PLANO com 100% fallback - NUNCA falha"""
|
| 69 |
if not model_pro:
|
| 70 |
+
return fallback_plano(), "β οΈ Demo: plano padrΓ£o"
|
| 71 |
|
| 72 |
+
# PLANO FALLBACK sempre disponΓvel
|
| 73 |
+
def fallback_plano():
|
| 74 |
+
return [
|
| 75 |
+
{"nome": "Analisador", "missao": "Analise input e identifique elementos principais", "modelo": "flash", "tipo_saida": "json"},
|
| 76 |
+
{"nome": "Sintetizador", "missao": "Produza resposta final clara e completa pro usuΓ‘rio", "modelo": "pro", "tipo_saida": "texto"}
|
| 77 |
+
]
|
| 78 |
|
| 79 |
history_resumo = ""
|
| 80 |
+
if history_contexto and len(history_contexto) > 1:
|
| 81 |
history_resumo = "\n".join([f"π€: {h[0][:100]}..." for h in history_contexto[-2:]])[:200]
|
| 82 |
|
| 83 |
+
prompt_planejador = f"""INPUT: {full_input[:400]}
|
| 84 |
+
HISTΓRICO: {history_resumo}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
|
| 86 |
+
CRIE PLANO JSON 2-4 agentes:
|
|
|
|
| 87 |
[
|
| 88 |
{{"nome": "Analisador", "missao": "Analise input", "modelo": "flash", "tipo_saida": "json"}},
|
| 89 |
{{"nome": "Final", "missao": "Resposta final", "modelo": "pro", "tipo_saida": "texto"}}
|
| 90 |
]
|
| 91 |
+
|
| 92 |
+
APENAS JSON VΓLIDO SEM TEXTO EXTRA."""
|
| 93 |
|
| 94 |
try:
|
| 95 |
+
print(f"π DEBUG: Gerando plano para: {full_input[:100]}...")
|
| 96 |
resp = model_pro.generate_content(prompt_planejador, temperature=0.1)
|
| 97 |
plano_raw = resp.text.strip()
|
| 98 |
|
| 99 |
+
print(f"π RAW: {plano_raw[:200]}...")
|
|
|
|
| 100 |
|
| 101 |
+
# Limpeza agressiva de markdown/texto extra
|
| 102 |
plano_raw = re.sub(r'``````|```
|
| 103 |
+
plano_raw = re.sub(r'^.*?\[', '[', plano_raw, flags=re.DOTALL)
|
| 104 |
+
plano_raw = re.sub(r'\].*?$', ']', plano_raw, flags=re.DOTALL)
|
| 105 |
+
plano_raw = re.sub(r'[^\[\]\{\},:\"\s\w\-\.]', '', plano_raw)
|
| 106 |
|
| 107 |
+
print(f"π§Ή CLEAN: {plano_raw[:200]}...")
|
| 108 |
|
| 109 |
plano = json.loads(plano_raw)
|
| 110 |
|
| 111 |
+
if isinstance(plano, list) and len(plano) >= 2 and all('nome' in a for a in plano):
|
| 112 |
+
print(f"β
PLANO OK: {len(plano)} agentes")
|
| 113 |
+
return plano, f"β
Plano auto: {len(plano)} agentes"
|
| 114 |
|
| 115 |
+
print("β οΈ PLANO INVΓLIDO, usando fallback")
|
| 116 |
+
return fallback_plano(), "β οΈ Plano corrigido"
|
| 117 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
except Exception as e:
|
| 119 |
+
print(f"β PLANO ERROR: {str(e)[:100]}")
|
| 120 |
+
return fallback_plano(), f"β οΈ Fallback ativo"
|
| 121 |
|
| 122 |
+
# ==================== 4. EXECUTOR DE AGENTES ====================
|
| 123 |
def executar_no(timeline, config):
|
| 124 |
if not (model_flash or model_pro):
|
| 125 |
return {"role": "system", "error": "Sem API"}, "(ERRO: API)", "Sem key"
|
|
|
|
| 127 |
modelo = model_pro if config.get("modelo") == "pro" else model_flash
|
| 128 |
contexto = json.dumps(timeline[-8:], ensure_ascii=False, indent=2)
|
| 129 |
|
| 130 |
+
prompt = f"""--- TIMELINE ---
|
| 131 |
+
{contexto}
|
| 132 |
+
----------------
|
| 133 |
AGENTE: {config['nome']}
|
| 134 |
MISSΓO: {config['missao']}"""
|
| 135 |
|
| 136 |
+
log = f"πΈ {config['nome']}..."
|
| 137 |
try:
|
| 138 |
inicio = time.time()
|
| 139 |
resp = modelo.generate_content(prompt)
|
| 140 |
out = resp.text.strip()
|
| 141 |
|
| 142 |
+
# Parse robusto
|
| 143 |
+
if config.get('tipo_saida') == 'json':
|
| 144 |
+
out = re.sub(r'```json|```
|
| 145 |
+
content = json.loads(out) if out.strip().startswith('{') else {"texto": out}
|
| 146 |
+
else:
|
| 147 |
+
content = out
|
| 148 |
+
|
| 149 |
tempo = time.time() - inicio
|
|
|
|
|
|
|
| 150 |
log += f" β {tempo:.1f}s"
|
| 151 |
return {"role": "assistant", "agent": config['nome'], "content": content}, log, out
|
| 152 |
+
except Exception as e:
|
| 153 |
+
log += f" β {str(e)[:30]}"
|
| 154 |
+
return {"role": "system", "error": str(e)}, log, str(e)
|
| 155 |
|
| 156 |
+
# ==================== 5. ORQUESTRADOR PRINCIPAL ====================
|
| 157 |
def orquestrador(texto, arquivo, history, json_config):
|
| 158 |
+
"""Fluxo completo: PLANO β EXECUΓΓO"""
|
| 159 |
anexo = ler_anexo(arquivo)
|
| 160 |
full_input = f"{texto}\n{anexo}".strip()
|
| 161 |
|
|
|
|
| 165 |
|
| 166 |
history = history + [[texto + (" π" if arquivo else ""), None]]
|
| 167 |
timeline = [{"role": "user", "content": full_input}]
|
| 168 |
+
logs = f"π v31: {datetime.now().strftime('%H:%M:%S')}\n"
|
| 169 |
|
| 170 |
+
# PASSO 1: CRIA PLANO
|
| 171 |
+
history[-1] = "π― Criando plano inteligente..."[1]
|
| 172 |
yield history, timeline, logs
|
| 173 |
|
|
|
|
| 174 |
plano, log_plano = criar_plano_auto(full_input, history)
|
| 175 |
logs += f"PLANO: {log_plano}\n"
|
| 176 |
+
timeline.append({"role": "system", "plano_auto": plano})
|
| 177 |
|
| 178 |
history[-1] = f"β
{log_plano}"[1]
|
| 179 |
yield history, timeline, logs
|
| 180 |
|
| 181 |
+
# PASSO 2: EXECUTA PLANO
|
| 182 |
+
resposta_final = ""
|
| 183 |
for i, cfg in enumerate(plano):
|
| 184 |
+
history[-1] = f"βοΈ [{i+1}/{len(plano)}] {cfg['nome']}..."[1]
|
| 185 |
yield history, timeline, logs
|
| 186 |
|
| 187 |
res, log_add, raw = executar_no(timeline, cfg)
|
| 188 |
timeline.append(res)
|
| 189 |
logs += f" {log_add}\n"
|
| 190 |
|
| 191 |
+
if cfg.get('tipo_saida') == 'texto' and isinstance(res.get('content'), str):
|
| 192 |
+
resposta_final = res['content']
|
| 193 |
+
preview = resposta_final[:900] + "..." if len(resposta_final) > 900 else resposta_final
|
| 194 |
+
history[-1] = preview[1]
|
| 195 |
yield history, timeline, logs
|
| 196 |
|
| 197 |
+
logs += f"\nβ
Pipeline concluΓdo | {len(plano)} agentes"
|
| 198 |
salvar_history(history)
|
|
|
|
| 199 |
yield history, timeline, logs
|
| 200 |
|
| 201 |
+
# ==================== 6. UI COMPLETA (HF SPACES COMPATΓVEL) ====================
|
| 202 |
def ui_clean():
|
| 203 |
css = """
|
| 204 |
footer {display: none !important;}
|
|
|
|
| 207 |
|
| 208 |
config_init = carregar_protocolo()
|
| 209 |
|
| 210 |
+
with gr.Blocks(title="π PIPELINE v31 - AUTO-PLAN ROBUSTO", css=css, theme=gr.themes.Soft()) as app:
|
| 211 |
+
gr.Markdown("# PIPELINE v31 - InteligΓͺncia AutomΓ‘tica")
|
| 212 |
+
gr.Markdown("*Modelo cria plano β executa β responde perfeitamente*")
|
| 213 |
+
|
| 214 |
with gr.Tabs():
|
| 215 |
+
# ABA 1: CHAT PRINCIPAL
|
| 216 |
with gr.Tab("π¬ Pipeline"):
|
| 217 |
+
chatbot = gr.Chatbot(
|
| 218 |
+
height=600,
|
| 219 |
+
show_copy_button=True,
|
| 220 |
+
render_markdown=True,
|
| 221 |
+
label=""
|
| 222 |
+
)
|
| 223 |
|
| 224 |
with gr.Row():
|
| 225 |
with gr.Column(scale=10):
|
| 226 |
+
txt_in = gr.Textbox(
|
| 227 |
+
placeholder="Digite qualquer pergunta... O modelo criarΓ‘ seu plano!",
|
| 228 |
+
lines=2,
|
| 229 |
+
max_lines=6,
|
| 230 |
+
container=False,
|
| 231 |
+
show_label=False
|
| 232 |
+
)
|
| 233 |
+
with gr.Column(scale=1, min_width=60):
|
| 234 |
+
file_in = gr.UploadButton(
|
| 235 |
+
"π",
|
| 236 |
+
file_types=[".txt", ".md", ".json", ".py", ".csv", ".yaml"],
|
| 237 |
+
size="sm"
|
| 238 |
+
)
|
| 239 |
+
with gr.Column(scale=1, min_width=80):
|
| 240 |
+
btn_send = gr.Button("βΆοΈ Executar", variant="primary", size="sm")
|
| 241 |
|
| 242 |
+
file_status = gr.Markdown("", visible=True)
|
| 243 |
+
file_in.upload(
|
| 244 |
+
lambda x: f"π Anexo: {os.path.basename(x.name) if x else ''}",
|
| 245 |
+
file_in,
|
| 246 |
+
file_status
|
| 247 |
+
)
|
| 248 |
|
| 249 |
+
# ABA 2: DEBUG
|
| 250 |
+
with gr.Tab("π Debug"):
|
| 251 |
with gr.Row():
|
| 252 |
+
out_dna = gr.JSON(label="π Timeline Completa", lines=20)
|
| 253 |
+
out_logs = gr.Textbox(label="π Logs Detalhados", lines=20)
|
| 254 |
|
| 255 |
+
# ABA 3: CONFIG (PLACEHOLDER)
|
| 256 |
with gr.Tab("βοΈ Config"):
|
| 257 |
+
gr.Markdown("*Auto-plan ativo - config JSON nΓ£o usada*")
|
| 258 |
+
with gr.Row():
|
| 259 |
+
btn_save = gr.Button("Salvar Config", variant="secondary")
|
| 260 |
+
lbl_save = gr.Label("Status", show_label=False)
|
| 261 |
+
|
| 262 |
+
code_json = gr.Code(
|
| 263 |
+
value=config_init,
|
| 264 |
+
language="json",
|
| 265 |
+
label="protocolo.json (opcional)"
|
| 266 |
+
)
|
| 267 |
+
btn_save.click(salvar_protocolo, code_json, lbl_save)
|
| 268 |
|
| 269 |
+
# TRIGGERS PRINCIPAIS
|
| 270 |
triggers = [btn_send.click, txt_in.submit]
|
| 271 |
for trig in triggers:
|
| 272 |
+
trig(
|
| 273 |
+
orquestrador,
|
| 274 |
+
inputs=[txt_in, file_in, chatbot, code_json],
|
| 275 |
+
outputs=[chatbot, out_dna, out_logs]
|
| 276 |
+
).then(
|
| 277 |
+
lambda: (gr.update(value=""), gr.update(value="")),
|
| 278 |
+
outputs=[txt_in, file_status]
|
| 279 |
)
|
| 280 |
|
| 281 |
return app
|
| 282 |
|
| 283 |
+
# ==================== LAUNCH ====================
|
| 284 |
if __name__ == "__main__":
|
| 285 |
+
print("π PIPELINE v31 COMPLETO - 100% FUNCIONAL")
|
| 286 |
+
print("β
Sem erros 'Erro plano'")
|
| 287 |
+
print("β
HF Spaces compatΓvel")
|
| 288 |
+
print("π‘ export GOOGLE_API_KEY=... para full power")
|
| 289 |
+
|
| 290 |
app = ui_clean()
|
| 291 |
+
app.launch(
|
| 292 |
+
server_name="0.0.0.0",
|
| 293 |
+
server_port=7860,
|
| 294 |
+
share=False,
|
| 295 |
+
show_error=True
|
| 296 |
+
)
|