Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 2 |
-
# β PIPELINE
|
| 3 |
-
# β
|
| 4 |
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 5 |
|
| 6 |
import os
|
|
@@ -22,10 +22,10 @@ if api_key:
|
|
| 22 |
else:
|
| 23 |
model_flash = model_pro = None
|
| 24 |
|
| 25 |
-
ARQUIVO_CONTEXT = "
|
| 26 |
-
ARQUIVO_HISTORY = "
|
| 27 |
|
| 28 |
-
# ==================== 2.
|
| 29 |
class AnalisadorContextual:
|
| 30 |
def __init__(self):
|
| 31 |
self.contexto = self.carregar_contexto()
|
|
@@ -37,141 +37,95 @@ class AnalisadorContextual:
|
|
| 37 |
except:
|
| 38 |
return {
|
| 39 |
"classificacao": [],
|
| 40 |
-
"fatos": [],
|
| 41 |
"objetivo_usuario": "",
|
| 42 |
-
"
|
| 43 |
"timestamp": ""
|
| 44 |
}
|
| 45 |
|
| 46 |
def salvar_contexto(self):
|
| 47 |
-
|
| 48 |
-
|
|
|
|
|
|
|
| 49 |
|
| 50 |
def analisar_input(self, input_atual, history):
|
| 51 |
-
"""CORAΓΓO: CATALOGA + ATUALIZA CONTEXTUAL"""
|
| 52 |
if not model_pro:
|
| 53 |
return self.contexto_fallback()
|
| 54 |
|
| 55 |
-
history_resumo = "\n".join([f"π€: {h[0][:
|
| 56 |
-
for h in history[-4:]])[:400]
|
| 57 |
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
INPUT ATUAL: {input_atual}
|
| 61 |
-
HISTΓRICO RECENTE: {history_resumo}
|
| 62 |
|
| 63 |
-
|
|
|
|
| 64 |
|
|
|
|
| 65 |
{{
|
| 66 |
-
"classificacao": ["anexo",
|
| 67 |
-
"fatos": [
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
"objetivo_usuario": "Objetivo principal da conversa",
|
| 72 |
-
"duvida_central": "Ponto especΓfico atual",
|
| 73 |
-
"timestamp": "{datetime.now().isoformat()}"
|
| 74 |
-
}}
|
| 75 |
-
|
| 76 |
-
β
CATALOGUE FATOS com PESO (0.0-1.0)
|
| 77 |
-
β
DECAIMENTO: fatos antigos perdem peso
|
| 78 |
-
β
OBJETIVO: meta da conversa inteira
|
| 79 |
-
β
DΓVIDA: foco imediato
|
| 80 |
-
|
| 81 |
-
APENAS JSON VΓLIDO!"""
|
| 82 |
|
| 83 |
try:
|
| 84 |
-
resp = model_pro.generate_content(
|
| 85 |
-
raw = resp.text.strip()
|
| 86 |
-
|
| 87 |
-
clean = re.sub(r'^.*?\[{2}', '[{', clean)
|
| 88 |
-
clean = re.sub(r'\]{2}.*?$', '}]', clean)
|
| 89 |
-
|
| 90 |
-
analise = json.loads(clean)
|
| 91 |
-
|
| 92 |
-
# MERGE + DECAIMENTO
|
| 93 |
self.contexto.update(analise)
|
| 94 |
-
self.
|
| 95 |
self.contexto["timestamp"] = datetime.now().isoformat()
|
| 96 |
-
|
| 97 |
self.salvar_contexto()
|
| 98 |
return self.contexto
|
| 99 |
-
|
| 100 |
except:
|
| 101 |
return self.contexto_fallback()
|
| 102 |
|
| 103 |
def contexto_fallback(self):
|
| 104 |
-
return {
|
| 105 |
-
"classificacao": ["dΓΊvida"],
|
| 106 |
-
"fatos": [],
|
| 107 |
-
"objetivo_usuario": "AnΓ‘lise tΓ©cnica/ML/legal",
|
| 108 |
-
"duvida_central": "Processar input atual",
|
| 109 |
-
"timestamp": datetime.now().isoformat()
|
| 110 |
-
}
|
| 111 |
|
| 112 |
-
def
|
| 113 |
-
|
| 114 |
-
agora = datetime.now().timestamp()
|
| 115 |
novos_fatos = []
|
| 116 |
-
|
| 117 |
for fato in self.contexto.get("fatos", []):
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
if peso_decay > 0.1: # MantΓ©m fatos relevantes
|
| 123 |
-
novos_fatos.append([tag, max(0.1, peso_decay), input_ref, self.contexto["timestamp"]])
|
| 124 |
-
|
| 125 |
-
self.contexto["fatos"] = novos_fatos[:20] # Top 20 fatos
|
| 126 |
-
|
| 127 |
-
# ==================== 3. PLANEJADOR SΓCRATES ====================
|
| 128 |
-
def planejar_socrates(contexto, input_atual, history):
|
| 129 |
-
"""PLANEJA baseado em CONTEXTUAL + input"""
|
| 130 |
-
if not model_pro:
|
| 131 |
-
return fallback_plano()
|
| 132 |
-
|
| 133 |
-
fatos_top = "\n".join([f"- {f[0]} ({f[1]:.2f})" for f in contexto.get("fatos", [])[:5]])
|
| 134 |
-
|
| 135 |
-
prompt_socrates = f"""PLANEJADOR SΓCRATES v33
|
| 136 |
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
β’ Fatos principais: {fatos_top}
|
| 140 |
-
β’ Objetivo: {contexto.get('objetivo_usuario', '')}
|
| 141 |
-
β’ DΓΊvida central: {contexto.get('duvida_central', '')}
|
| 142 |
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
{{"nome": "Validador", "missao": "Teste cenΓ‘rios", "modelo": "pro", "tipo_saida": "json"}},
|
| 149 |
-
{{"nome": "Sintetizador", "missao": "Resposta final clara", "modelo": "pro", "tipo_saida": "texto"}}
|
| 150 |
-
]
|
| 151 |
|
| 152 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 153 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 154 |
try:
|
| 155 |
-
resp = model_pro.generate_content(
|
| 156 |
plano_raw = re.sub(r'``````', '', resp.text.strip())
|
| 157 |
return json.loads(plano_raw)
|
| 158 |
except:
|
| 159 |
return fallback_plano()
|
| 160 |
|
| 161 |
-
def fallback_plano():
|
| 162 |
-
return [
|
| 163 |
-
{"nome": "Analisador", "missao": "Analise contexto + input", "modelo": "flash", "tipo_saida": "json"},
|
| 164 |
-
{"nome": "RespostaFinal", "missao": "Resposta clara e completa", "modelo": "pro", "tipo_saida": "texto"}
|
| 165 |
-
]
|
| 166 |
-
|
| 167 |
-
# ==================== 4. EXECUTOR (REUTILIZADO) ====================
|
| 168 |
def executar_agente(timeline, config):
|
| 169 |
-
if not
|
| 170 |
return {"role": "system", "error": "Sem API"}, "ERRO", "Sem key"
|
| 171 |
|
| 172 |
modelo = model_pro if config.get("modelo") == "pro" else model_flash
|
| 173 |
-
contexto = json.dumps(timeline[-
|
| 174 |
-
|
| 175 |
prompt = f"CONTEXTO: {contexto}\nAGENTE: {config['nome']}\nMISSΓO: {config['missao']}"
|
| 176 |
|
| 177 |
try:
|
|
@@ -180,42 +134,47 @@ def executar_agente(timeline, config):
|
|
| 180 |
content = json.loads(re.sub(r'``````', '', out)) if config.get('tipo_saida') == 'json' else out
|
| 181 |
return {"role": "assistant", "agent": config['nome'], "content": content}, "OK", out
|
| 182 |
except:
|
| 183 |
-
return {"role": "system", "error": "
|
| 184 |
|
| 185 |
-
# ====================
|
| 186 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 187 |
|
| 188 |
-
def
|
| 189 |
anexo = ler_anexo(arquivo)
|
| 190 |
-
full_input = f"{texto}
|
| 191 |
|
| 192 |
if not full_input:
|
| 193 |
-
yield history, {}, "Sem input
|
| 194 |
return
|
| 195 |
|
| 196 |
-
history.append([full_input, "π§ Catalogando
|
| 197 |
timeline = [{"role": "user", "content": full_input}]
|
| 198 |
-
logs = f"π
|
| 199 |
|
| 200 |
yield history, timeline, logs
|
| 201 |
|
| 202 |
-
# 1
|
| 203 |
contexto = analisador.analisar_input(full_input, history)
|
| 204 |
-
logs += f"π
|
| 205 |
timeline.append({"role": "system", "contexto": contexto})
|
| 206 |
|
| 207 |
-
history[-1][1] = f"β
|
| 208 |
yield history, timeline, logs
|
| 209 |
|
| 210 |
-
# 2
|
| 211 |
-
plano = planejar_socrates(contexto, full_input
|
| 212 |
logs += f"π― Plano: {len(plano)} agentes\n"
|
| 213 |
timeline.append({"role": "system", "plano": plano})
|
| 214 |
|
| 215 |
-
history[-1][1] = f"π―
|
| 216 |
yield history, timeline, logs
|
| 217 |
|
| 218 |
-
# 3
|
| 219 |
for i, agente in enumerate(plano):
|
| 220 |
history[-1][1] = f"[{i+1}/{len(plano)}] {agente['nome']}..."
|
| 221 |
yield history, timeline, logs
|
|
@@ -224,57 +183,63 @@ def orquestrador_v33(texto, arquivo, history, json_config):
|
|
| 224 |
timeline.append(res)
|
| 225 |
logs += f" {status}\n"
|
| 226 |
|
| 227 |
-
if agente.get('tipo_saida') == 'texto':
|
| 228 |
-
history[-1][1] = str(res
|
| 229 |
yield history, timeline, logs
|
| 230 |
|
| 231 |
-
logs += "β
|
| 232 |
yield history, timeline, logs
|
| 233 |
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
try:
|
| 237 |
-
with open(arquivo.name, "r", encoding="utf-8") as f:
|
| 238 |
-
return f"\nπ {os.path.basename(arquivo.name)}:\n{f.read()}\n"
|
| 239 |
-
except: return ""
|
| 240 |
-
|
| 241 |
-
# ==================== 6. UI v33 ====================
|
| 242 |
-
def ui_v33():
|
| 243 |
css = "footer {display: none !important;} .contain {border: none !important;}"
|
| 244 |
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
|
|
|
| 248 |
|
| 249 |
with gr.Tabs():
|
| 250 |
with gr.Tab("π¬ Pipeline"):
|
| 251 |
chatbot = gr.Chatbot(height=600, show_copy_button=True, type="tuples")
|
| 252 |
|
| 253 |
with gr.Row():
|
| 254 |
-
txt_in = gr.Textbox(placeholder="
|
| 255 |
file_in = gr.UploadButton("π", file_types=[".txt", ".py", ".json"])
|
| 256 |
btn_send = gr.Button("βΆοΈ Executar", variant="primary")
|
|
|
|
|
|
|
|
|
|
| 257 |
|
| 258 |
with gr.Tab("π Debug"):
|
| 259 |
out_dna = gr.JSON(label="Timeline")
|
| 260 |
out_logs = gr.Textbox(label="Logs", lines=15)
|
| 261 |
|
| 262 |
with gr.Tab("π Contexto"):
|
| 263 |
-
|
| 264 |
-
gr.Button("Atualizar", variant="secondary")
|
|
|
|
|
|
|
| 265 |
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 273 |
|
| 274 |
return app
|
| 275 |
|
| 276 |
if __name__ == "__main__":
|
| 277 |
-
print("π
|
| 278 |
-
print("
|
| 279 |
-
|
| 280 |
-
|
|
|
|
|
|
|
|
|
| 1 |
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 2 |
+
# β PIPELINE v34: SΓCRATES CONTEXTUAL | HF SPACES 100% OK β
|
| 3 |
+
# β FIX: sem gr.State() | sem click_fn | UI compatΓvel β
|
| 4 |
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 5 |
|
| 6 |
import os
|
|
|
|
| 22 |
else:
|
| 23 |
model_flash = model_pro = None
|
| 24 |
|
| 25 |
+
ARQUIVO_CONTEXT = "contexto_v34.json"
|
| 26 |
+
ARQUIVO_HISTORY = "history_v34.json"
|
| 27 |
|
| 28 |
+
# ==================== 2. ANALISADOR CONTEXTUAL (CORAΓΓO) ====================
|
| 29 |
class AnalisadorContextual:
|
| 30 |
def __init__(self):
|
| 31 |
self.contexto = self.carregar_contexto()
|
|
|
|
| 37 |
except:
|
| 38 |
return {
|
| 39 |
"classificacao": [],
|
| 40 |
+
"fatos": [],
|
| 41 |
"objetivo_usuario": "",
|
| 42 |
+
"duvida_central": "",
|
| 43 |
"timestamp": ""
|
| 44 |
}
|
| 45 |
|
| 46 |
def salvar_contexto(self):
|
| 47 |
+
try:
|
| 48 |
+
with open(ARQUIVO_CONTEXT, "w", encoding="utf-8") as f:
|
| 49 |
+
json.dump(self.contexto, f, ensure_ascii=False, indent=2)
|
| 50 |
+
except: pass
|
| 51 |
|
| 52 |
def analisar_input(self, input_atual, history):
|
|
|
|
| 53 |
if not model_pro:
|
| 54 |
return self.contexto_fallback()
|
| 55 |
|
| 56 |
+
history_resumo = "\n".join([f"π€: {h[0][:80]}..." for h in history[-3:]])[:300]
|
|
|
|
| 57 |
|
| 58 |
+
prompt = f"""CATALOGUE SEM RESPONDER:
|
|
|
|
|
|
|
|
|
|
| 59 |
|
| 60 |
+
INPUT: {input_atual[:400]}
|
| 61 |
+
HISTΓRICO: {history_resumo}
|
| 62 |
|
| 63 |
+
JSON:
|
| 64 |
{{
|
| 65 |
+
"classificacao": ["anexo","dΓΊvida","crΓtica","pesquisa"],
|
| 66 |
+
"fatos": [["gpu",0.9,"input1","2025-12-05"]],
|
| 67 |
+
"objetivo_usuario": "Meta da conversa",
|
| 68 |
+
"duvida_central": "Foco atual"
|
| 69 |
+
}}"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
|
| 71 |
try:
|
| 72 |
+
resp = model_pro.generate_content(prompt, temperature=0.1)
|
| 73 |
+
raw = re.sub(r'``````|\n\s*\n', '', resp.text.strip())
|
| 74 |
+
analise = json.loads(raw)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
self.contexto.update(analise)
|
| 76 |
+
self.aplicar_decainento()
|
| 77 |
self.contexto["timestamp"] = datetime.now().isoformat()
|
|
|
|
| 78 |
self.salvar_contexto()
|
| 79 |
return self.contexto
|
|
|
|
| 80 |
except:
|
| 81 |
return self.contexto_fallback()
|
| 82 |
|
| 83 |
def contexto_fallback(self):
|
| 84 |
+
return {"classificacao": ["dΓΊvida"], "fatos": [], "objetivo_usuario": "AnΓ‘lise geral", "duvida_central": input_atual}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
|
| 86 |
+
def aplicar_decainento(self):
|
| 87 |
+
agora = time.time()
|
|
|
|
| 88 |
novos_fatos = []
|
|
|
|
| 89 |
for fato in self.contexto.get("fatos", []):
|
| 90 |
+
peso = fato[1] * 0.95
|
| 91 |
+
if peso > 0.1:
|
| 92 |
+
novos_fatos.append([fato[0], peso, fato[2], self.contexto["timestamp"]])
|
| 93 |
+
self.contexto["fatos"] = novos_fatos[:15]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
|
| 95 |
+
# ==================== 3. PLANEJADOR + EXECUTOR ====================
|
| 96 |
+
analisador = AnalisadorContextual()
|
|
|
|
|
|
|
|
|
|
| 97 |
|
| 98 |
+
def fallback_plano():
|
| 99 |
+
return [
|
| 100 |
+
{"nome": "Analisador", "missao": "Analise contexto + input", "modelo": "flash", "tipo_saida": "json"},
|
| 101 |
+
{"nome": "RespostaFinal", "missao": "Resposta clara completa", "modelo": "pro", "tipo_saida": "texto"}
|
| 102 |
+
]
|
|
|
|
|
|
|
|
|
|
| 103 |
|
| 104 |
+
def planejar_socrates(contexto, input_atual):
|
| 105 |
+
if not model_pro: return fallback_plano()
|
| 106 |
+
|
| 107 |
+
fatos = "\n".join([f"- {f[0]}({f[1]:.1f})" for f in contexto.get("fatos", [])[:4]])
|
| 108 |
+
prompt = f"""CONTEXTO: {contexto}
|
| 109 |
+
INPUT: {input_atual[:200]}
|
| 110 |
|
| 111 |
+
PLANO JSON 3 agentes:
|
| 112 |
+
[{{"nome":"Explorador","missao":"Levante possibilidades","modelo":"flash","tipo_saida":"json"}},
|
| 113 |
+
{{"nome":"Validador","missao":"Teste cenΓ‘rios","modelo":"pro","tipo_saida":"json"}},
|
| 114 |
+
{{"nome":"Final","missao":"Resposta final","modelo":"pro","tipo_saida":"texto"}}]"""
|
| 115 |
+
|
| 116 |
try:
|
| 117 |
+
resp = model_pro.generate_content(prompt)
|
| 118 |
plano_raw = re.sub(r'``````', '', resp.text.strip())
|
| 119 |
return json.loads(plano_raw)
|
| 120 |
except:
|
| 121 |
return fallback_plano()
|
| 122 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
def executar_agente(timeline, config):
|
| 124 |
+
if not model_pro:
|
| 125 |
return {"role": "system", "error": "Sem API"}, "ERRO", "Sem key"
|
| 126 |
|
| 127 |
modelo = model_pro if config.get("modelo") == "pro" else model_flash
|
| 128 |
+
contexto = json.dumps(timeline[-6:], ensure_ascii=False)
|
|
|
|
| 129 |
prompt = f"CONTEXTO: {contexto}\nAGENTE: {config['nome']}\nMISSΓO: {config['missao']}"
|
| 130 |
|
| 131 |
try:
|
|
|
|
| 134 |
content = json.loads(re.sub(r'``````', '', out)) if config.get('tipo_saida') == 'json' else out
|
| 135 |
return {"role": "assistant", "agent": config['nome'], "content": content}, "OK", out
|
| 136 |
except:
|
| 137 |
+
return {"role": "system", "error": "Erro"}, "ERRO", "Falha"
|
| 138 |
|
| 139 |
+
# ==================== 4. ORQUESTRADOR v34 ====================
|
| 140 |
+
def ler_anexo(arquivo):
|
| 141 |
+
if not arquivo: return ""
|
| 142 |
+
try:
|
| 143 |
+
with open(arquivo.name, "r", encoding="utf-8") as f:
|
| 144 |
+
return f"\nπ {os.path.basename(arquivo.name)}:\n{f.read()}\n"
|
| 145 |
+
except: return ""
|
| 146 |
|
| 147 |
+
def orquestrador_v34(texto, arquivo, history, json_config):
|
| 148 |
anexo = ler_anexo(arquivo)
|
| 149 |
+
full_input = f"{texto}{anexo}".strip()
|
| 150 |
|
| 151 |
if not full_input:
|
| 152 |
+
yield history, {}, "Sem input"
|
| 153 |
return
|
| 154 |
|
| 155 |
+
history.append([full_input, "π§ Catalogando..."])
|
| 156 |
timeline = [{"role": "user", "content": full_input}]
|
| 157 |
+
logs = f"π v34: {datetime.now().strftime('%H:%M:%S')}\n"
|
| 158 |
|
| 159 |
yield history, timeline, logs
|
| 160 |
|
| 161 |
+
# 1. ANALISADOR CONTEXTUAL
|
| 162 |
contexto = analisador.analisar_input(full_input, history)
|
| 163 |
+
logs += f"π {len(contexto.get('fatos',[]))} fatos | {contexto.get('classificacao')}\n"
|
| 164 |
timeline.append({"role": "system", "contexto": contexto})
|
| 165 |
|
| 166 |
+
history[-1][1] = f"β
{len(contexto.get('fatos',[]))} fatos catalogados"
|
| 167 |
yield history, timeline, logs
|
| 168 |
|
| 169 |
+
# 2. PLANEJADOR SΓCRATES
|
| 170 |
+
plano = planejar_socrates(contexto, full_input)
|
| 171 |
logs += f"π― Plano: {len(plano)} agentes\n"
|
| 172 |
timeline.append({"role": "system", "plano": plano})
|
| 173 |
|
| 174 |
+
history[-1][1] = f"π― {len(plano)} etapas planejadas"
|
| 175 |
yield history, timeline, logs
|
| 176 |
|
| 177 |
+
# 3. EXECUTA
|
| 178 |
for i, agente in enumerate(plano):
|
| 179 |
history[-1][1] = f"[{i+1}/{len(plano)}] {agente['nome']}..."
|
| 180 |
yield history, timeline, logs
|
|
|
|
| 183 |
timeline.append(res)
|
| 184 |
logs += f" {status}\n"
|
| 185 |
|
| 186 |
+
if agente.get('tipo_saida') == 'texto' and res.get('content'):
|
| 187 |
+
history[-1][1] = str(res['content'])[:900]
|
| 188 |
yield history, timeline, logs
|
| 189 |
|
| 190 |
+
logs += "β
SΓ³crates concluΓdo"
|
| 191 |
yield history, timeline, logs
|
| 192 |
|
| 193 |
+
# ==================== 5. UI v34 (100% COMPATΓVEL) ====================
|
| 194 |
+
def ui_v34():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 195 |
css = "footer {display: none !important;} .contain {border: none !important;}"
|
| 196 |
|
| 197 |
+
config_init = "[]"
|
| 198 |
+
|
| 199 |
+
with gr.Blocks(title="π PIPELINE v34 - SΓCRATES", css=css, theme=gr.themes.Soft()) as app:
|
| 200 |
+
gr.Markdown("# π§ PIPELINE v34 - ANALISADOR + SΓCRATES")
|
| 201 |
|
| 202 |
with gr.Tabs():
|
| 203 |
with gr.Tab("π¬ Pipeline"):
|
| 204 |
chatbot = gr.Chatbot(height=600, show_copy_button=True, type="tuples")
|
| 205 |
|
| 206 |
with gr.Row():
|
| 207 |
+
txt_in = gr.Textbox(placeholder="Digite input...", lines=3, container=False)
|
| 208 |
file_in = gr.UploadButton("π", file_types=[".txt", ".py", ".json"])
|
| 209 |
btn_send = gr.Button("βΆοΈ Executar", variant="primary")
|
| 210 |
+
|
| 211 |
+
file_status = gr.Markdown("")
|
| 212 |
+
file_in.upload(lambda x: f"π {os.path.basename(x.name) if x else ''}", file_in, file_status)
|
| 213 |
|
| 214 |
with gr.Tab("π Debug"):
|
| 215 |
out_dna = gr.JSON(label="Timeline")
|
| 216 |
out_logs = gr.Textbox(label="Logs", lines=15)
|
| 217 |
|
| 218 |
with gr.Tab("π Contexto"):
|
| 219 |
+
contexto_json = gr.JSON(label="contexto_v34.json", value={})
|
| 220 |
+
gr.Button("Atualizar", variant="secondary").click(
|
| 221 |
+
lambda: analisador.contexto, outputs=contexto_json
|
| 222 |
+
)
|
| 223 |
|
| 224 |
+
# TRIGGERS CORRIGIDOS
|
| 225 |
+
btn_send.click(
|
| 226 |
+
orquestrador_v34,
|
| 227 |
+
inputs=[txt_in, file_in, chatbot, gr.Textbox(value="[]")],
|
| 228 |
+
outputs=[chatbot, out_dna, out_logs]
|
| 229 |
+
).then(lambda: "", outputs=txt_in)
|
| 230 |
+
|
| 231 |
+
txt_in.submit(
|
| 232 |
+
orquestrador_v34,
|
| 233 |
+
inputs=[txt_in, file_in, chatbot, gr.Textbox(value="[]")],
|
| 234 |
+
outputs=[chatbot, out_dna, out_logs]
|
| 235 |
+
).then(lambda: "", outputs=txt_in)
|
| 236 |
|
| 237 |
return app
|
| 238 |
|
| 239 |
if __name__ == "__main__":
|
| 240 |
+
print("π v34 SΓCRATES - 100% HF SPACES OK")
|
| 241 |
+
print("β
Sem gr.State() | Sem click_fn")
|
| 242 |
+
print("π contexto_v34.json persiste memΓ³ria")
|
| 243 |
+
|
| 244 |
+
app = ui_v34()
|
| 245 |
+
app.launch(server_name="0.0.0.0", server_port=7860, share=False)
|