Update app.py
Browse files
app.py
CHANGED
|
@@ -38,6 +38,7 @@ DEFAULT_SETTINGS = {
|
|
| 38 |
"min_chars_reto": 100,
|
| 39 |
"max_chars_reto": 2000,
|
| 40 |
"require_remote_eval": False,
|
|
|
|
| 41 |
"canvas": {
|
| 42 |
"width": 1920,
|
| 43 |
"height": 1080,
|
|
@@ -346,6 +347,21 @@ def hf_generate_json(model: str, prompt: str, max_new_tokens: int = 1200) -> Dic
|
|
| 346 |
return {}
|
| 347 |
|
| 348 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 349 |
def token_set(text: str) -> set:
|
| 350 |
tokens = re.findall(r"[a-záéíóúñü]{4,}", normalize_text(text))
|
| 351 |
stop = {"como", "pueden", "podrian", "deben", "estar", "para", "entre", "desde", "sobre", "mismo", "misma", "estas", "estos", "ellas", "ellos", "donde"}
|
|
@@ -616,21 +632,34 @@ def actor_table_md(actors_state: List[Dict[str, str]]) -> str:
|
|
| 616 |
return "\n".join(rows)
|
| 617 |
|
| 618 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 619 |
def add_actor(name: str, role: str, actors_state: List[Dict[str, str]]):
|
| 620 |
actors_state = actors_state or []
|
| 621 |
name = (name or "").strip()
|
| 622 |
role = (role or "").strip()
|
| 623 |
if not name:
|
| 624 |
-
return actors_state, actor_table_md(actors_state), "", ""
|
| 625 |
actors_state.append({"name": name, "role": role})
|
| 626 |
-
return actors_state, actor_table_md(actors_state), "", ""
|
| 627 |
|
| 628 |
|
| 629 |
-
def
|
| 630 |
actors_state = actors_state or []
|
| 631 |
-
|
| 632 |
-
|
| 633 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 634 |
|
| 635 |
|
| 636 |
def stepper_html(idx: int) -> str:
|
|
@@ -670,6 +699,13 @@ def load_font(size: int, bold: bool = False):
|
|
| 670 |
return ImageFont.load_default()
|
| 671 |
|
| 672 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 673 |
def draw_panel(draw, xy, title, body, font_title, font_body, colors):
|
| 674 |
x1, y1, x2, y2 = xy
|
| 675 |
draw.rounded_rectangle(xy, radius=18, fill=colors["panel_bg"], outline=colors["panel_border"], width=2)
|
|
@@ -691,7 +727,9 @@ def draw_panel(draw, xy, title, body, font_title, font_body, colors):
|
|
| 691 |
if current:
|
| 692 |
lines.append(current)
|
| 693 |
max_lines = max(4, int(((y2 - y1) - 90) / 28))
|
| 694 |
-
lines
|
|
|
|
|
|
|
| 695 |
y = y1 + 68
|
| 696 |
for line in lines:
|
| 697 |
draw.text((x1 + 24, y), line, fill=colors["text_color"], font=font_body)
|
|
@@ -704,10 +742,10 @@ def generate_canvas_image(reto: str, definicion: str, relevancia: str, conexion:
|
|
| 704 |
img = Image.new("RGBA", (W, H), s["background_color"])
|
| 705 |
draw = ImageDraw.Draw(img)
|
| 706 |
|
| 707 |
-
font_header = load_font(
|
| 708 |
font_title = load_font(24, bold=True)
|
| 709 |
font_body = load_font(18, bold=False)
|
| 710 |
-
font_footer = load_font(
|
| 711 |
|
| 712 |
colors = {
|
| 713 |
"header_color": s["header_color"],
|
|
@@ -717,28 +755,36 @@ def generate_canvas_image(reto: str, definicion: str, relevancia: str, conexion:
|
|
| 717 |
}
|
| 718 |
|
| 719 |
draw.rounded_rectangle((40, 30, W - 40, 180), radius=24, fill=colors["header_color"])
|
| 720 |
-
header_lines = textwrap.wrap(reto, width=
|
| 721 |
-
y =
|
| 722 |
for line in header_lines:
|
| 723 |
draw.text((80, y), line, fill="white", font=font_header)
|
| 724 |
-
y +=
|
| 725 |
|
| 726 |
draw_panel(draw, (40, 220, 930, 450), "1. Definición", definicion, font_title, font_body, colors)
|
| 727 |
draw_panel(draw, (40, 470, 930, 700), "2. Relevancia", relevancia, font_title, font_body, colors)
|
| 728 |
draw_panel(draw, (40, 720, 930, 940), "3. Conexión personal", conexion, font_title, font_body, colors)
|
| 729 |
draw_panel(draw, (990, 220, W - 40, 450), "4. Actores", actors_text, font_title, font_body, colors)
|
| 730 |
draw_panel(draw, (990, 470, W - 40, 940), "5. Gobernanza", gobernanza, font_title, font_body, colors)
|
| 731 |
-
|
| 732 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 733 |
|
| 734 |
footer_text = f"Generado el {datetime.now().strftime('%Y-%m-%d %H:%M')} • {APP_NAME}"
|
| 735 |
-
draw.text((60, H -
|
| 736 |
|
| 737 |
if LOGO_PATH.exists():
|
| 738 |
try:
|
| 739 |
logo = Image.open(LOGO_PATH).convert("RGBA")
|
| 740 |
-
logo.thumbnail((
|
| 741 |
-
img.alpha_composite(logo, (W - logo.width - 60, H - logo.height -
|
| 742 |
except Exception:
|
| 743 |
pass
|
| 744 |
|
|
@@ -762,7 +808,7 @@ def create_board(reto: str, definicion: str, relevancia: str, conexion: str, gob
|
|
| 762 |
session = session or {}
|
| 763 |
user_id = session.get("user_id", str(uuid4()))
|
| 764 |
actors_state = actors_state or []
|
| 765 |
-
actors_text = "\n".join([f"- {a.get('name','')} — {a.get('role','')}" if a.get("role") else f"- {a.get('name','')}" for a in actors_state])
|
| 766 |
|
| 767 |
png = generate_canvas_image(reto, definicion, relevancia, conexion, actors_text, gobernanza, iniciativas, user_id)
|
| 768 |
canvas_dict = {
|
|
@@ -782,44 +828,64 @@ def info_html() -> str:
|
|
| 782 |
return """
|
| 783 |
<div class="info-card pop-in">
|
| 784 |
<h2>Cómo funciona este sistema</h2>
|
| 785 |
-
<p>
|
| 786 |
-
|
| 787 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 788 |
<div style="background:white;border:1px solid #e5e7eb;border-radius:20px;padding:16px;margin:14px 0;">
|
| 789 |
-
<div style="font-weight:700;margin-bottom:8px;">
|
| 790 |
<div style="font-family:monospace;background:#f8fafc;border-radius:12px;padding:12px;">
|
| 791 |
Puntaje global = (C1 + C2 + C3 + C4 + C5 + C6 + C7) / 7
|
| 792 |
</div>
|
| 793 |
</div>
|
| 794 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 795 |
<ul>
|
| 796 |
-
<li><b>C1</b>
|
| 797 |
-
<li><b>C2</b>
|
| 798 |
-
<li><b>C3</b>
|
| 799 |
-
<li><b>C4</b>
|
| 800 |
-
<li><b>C5</b>
|
| 801 |
-
<li><b>C6</b>
|
| 802 |
-
<li><b>C7</b>
|
| 803 |
</ul>
|
| 804 |
-
|
| 805 |
-
<
|
| 806 |
-
<li>Se valida que el reto tenga forma mínima adecuada.</li>
|
| 807 |
-
<li>Se intenta una evaluación con modelo remoto.</li>
|
| 808 |
-
<li>Si no responde, se usa una evaluación local reforzada con similitud respecto de ejemplos guía y señales conceptuales.</li>
|
| 809 |
-
<li>Se calcula el promedio global y se muestran fortalezas y vacíos.</li>
|
| 810 |
-
</ol>
|
| 811 |
-
<h3>Cómo leer el resultado</h3>
|
| 812 |
<ul>
|
| 813 |
-
<li>
|
| 814 |
-
<li>
|
| 815 |
-
<li>40 a 59 — reto parcialmente complejo</li>
|
| 816 |
-
<li>0 a 39 — formulación débil</li>
|
| 817 |
</ul>
|
| 818 |
-
|
|
|
|
| 819 |
<ul>
|
| 820 |
<li>Snowden, D. J., & Boone, M. E. 2007. A Leader’s Framework for Decision Making. Harvard Business Review.</li>
|
| 821 |
<li>Kurtz, C. F., & Snowden, D. J. 2003. The new dynamics of strategy. IBM Systems Journal.</li>
|
| 822 |
<li>Snowden, D. J. 2010. The Cynefin framework and naturalizing sense-making.</li>
|
|
|
|
| 823 |
</ul>
|
| 824 |
</div>
|
| 825 |
"""
|
|
@@ -832,13 +898,18 @@ def reset_all():
|
|
| 832 |
[],
|
| 833 |
idx,
|
| 834 |
stepper_html(idx),
|
| 835 |
-
"", "", "<div></div>", "", "", "", "", "Sin actores agregados todavía.", "", "", None, None,
|
| 836 |
*render_step_visibility(idx),
|
| 837 |
gr.update(interactive=False),
|
| 838 |
gr.update(interactive=False)
|
| 839 |
)
|
| 840 |
|
| 841 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 842 |
def build_app():
|
| 843 |
examples = [[ex["text"]] for ex in DEFAULT_EXAMPLES]
|
| 844 |
theme = gr.themes.Soft(primary_hue="blue", secondary_hue="slate", neutral_hue="slate")
|
|
@@ -868,6 +939,7 @@ def build_app():
|
|
| 868 |
.animate-fill {animation: fillin .6s ease;}
|
| 869 |
.nav-row {display:flex; gap:12px;}
|
| 870 |
.pop-in {animation: popin .28s ease;}
|
|
|
|
| 871 |
@keyframes fillin {from {width:0;} to {width:100%;}}
|
| 872 |
@keyframes popin {from {opacity:0; transform:translateY(6px);} to {opacity:1; transform:translateY(0);}}
|
| 873 |
"""
|
|
@@ -890,6 +962,8 @@ def build_app():
|
|
| 890 |
stepper = gr.HTML(stepper_html(0))
|
| 891 |
|
| 892 |
with gr.Group(visible=True) as step0:
|
|
|
|
|
|
|
| 893 |
reto_input = gr.Textbox(label="Paso 1 • Escribe el reto", lines=6, placeholder="Escribe una pregunta de al menos 100 caracteres.")
|
| 894 |
gr.Examples(examples=examples, inputs=[reto_input], label="Ejemplos guía")
|
| 895 |
with gr.Row():
|
|
@@ -921,8 +995,9 @@ def build_app():
|
|
| 921 |
actor_role = gr.Textbox(label="Rol", scale=3)
|
| 922 |
with gr.Row():
|
| 923 |
actor_add_btn = gr.Button("Agregar actor")
|
| 924 |
-
actor_remove_btn = gr.Button("Quitar último")
|
| 925 |
actor_md = gr.Markdown("Sin actores agregados todavía.")
|
|
|
|
|
|
|
| 926 |
|
| 927 |
with gr.Group(visible=False) as step5:
|
| 928 |
gr.Markdown("## Paso 6 • Gobernanza")
|
|
@@ -948,6 +1023,8 @@ def build_app():
|
|
| 948 |
with gr.Tab("Cómo funciona"):
|
| 949 |
info = gr.HTML(info_html())
|
| 950 |
|
|
|
|
|
|
|
| 951 |
eval_btn.click(
|
| 952 |
fn=evaluate_step,
|
| 953 |
inputs=[reto_input, session],
|
|
@@ -984,8 +1061,17 @@ def build_app():
|
|
| 984 |
outputs=[conexion]
|
| 985 |
)
|
| 986 |
|
| 987 |
-
actor_add_btn.click(
|
| 988 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 989 |
|
| 990 |
ask_gob.click(
|
| 991 |
fn=lambda reto, d, r, c, g, i, actors: suggest_section_answer(reto, "gobernanza", {"definicion": d, "relevancia": r, "conexion": c, "gobernanza": g, "iniciativas": i, "actors": actors}),
|
|
@@ -1010,8 +1096,8 @@ def build_app():
|
|
| 1010 |
outputs=[
|
| 1011 |
session, actors_state, wizard_idx, stepper,
|
| 1012 |
reto_input, eval_md, eval_chart, reto_hidden,
|
| 1013 |
-
definicion, relevancia, conexion, actor_md,
|
| 1014 |
-
gobernanza, iniciativas, board_preview, board_file,
|
| 1015 |
step0, step1, step2, step3, step4, step5, step6, step7,
|
| 1016 |
prev_btn, next_btn
|
| 1017 |
]
|
|
@@ -1025,4 +1111,3 @@ app = build_app()
|
|
| 1025 |
|
| 1026 |
if __name__ == "__main__":
|
| 1027 |
app.launch()
|
| 1028 |
-
|
|
|
|
| 38 |
"min_chars_reto": 100,
|
| 39 |
"max_chars_reto": 2000,
|
| 40 |
"require_remote_eval": False,
|
| 41 |
+
"remote_timeout_note": True,
|
| 42 |
"canvas": {
|
| 43 |
"width": 1920,
|
| 44 |
"height": 1080,
|
|
|
|
| 347 |
return {}
|
| 348 |
|
| 349 |
|
| 350 |
+
def ping_remote_eval() -> Tuple[bool, str]:
|
| 351 |
+
token = get_hf_token()
|
| 352 |
+
if not token or not token.startswith("hf_"):
|
| 353 |
+
return False, "No hay token válido configurado."
|
| 354 |
+
client = build_client()
|
| 355 |
+
if client is None:
|
| 356 |
+
return False, "No fue posible inicializar el cliente remoto."
|
| 357 |
+
probe_prompt = 'Responde SOLO JSON válido {"ok":true}'
|
| 358 |
+
for model in load_settings()["models"]["eval"]:
|
| 359 |
+
out = hf_generate_json(model, probe_prompt, max_new_tokens=40)
|
| 360 |
+
if isinstance(out, dict) and out.get("ok") is True:
|
| 361 |
+
return True, f"Disponible con {model}"
|
| 362 |
+
return False, "No hubo respuesta válida de los modelos remotos."
|
| 363 |
+
|
| 364 |
+
|
| 365 |
def token_set(text: str) -> set:
|
| 366 |
tokens = re.findall(r"[a-záéíóúñü]{4,}", normalize_text(text))
|
| 367 |
stop = {"como", "pueden", "podrian", "deben", "estar", "para", "entre", "desde", "sobre", "mismo", "misma", "estas", "estos", "ellas", "ellos", "donde"}
|
|
|
|
| 632 |
return "\n".join(rows)
|
| 633 |
|
| 634 |
|
| 635 |
+
def actor_dropdown_choices(actors_state: List[Dict[str, str]]) -> gr.update:
|
| 636 |
+
actors_state = actors_state or []
|
| 637 |
+
choices = []
|
| 638 |
+
for i, actor in enumerate(actors_state):
|
| 639 |
+
label = f"{i+1}. {actor.get('name','')} — {actor.get('role','')}".strip(" —")
|
| 640 |
+
choices.append((label, str(i)))
|
| 641 |
+
return gr.update(choices=choices, value=None)
|
| 642 |
+
|
| 643 |
+
|
| 644 |
def add_actor(name: str, role: str, actors_state: List[Dict[str, str]]):
|
| 645 |
actors_state = actors_state or []
|
| 646 |
name = (name or "").strip()
|
| 647 |
role = (role or "").strip()
|
| 648 |
if not name:
|
| 649 |
+
return actors_state, actor_table_md(actors_state), "", "", actor_dropdown_choices(actors_state)
|
| 650 |
actors_state.append({"name": name, "role": role})
|
| 651 |
+
return actors_state, actor_table_md(actors_state), "", "", actor_dropdown_choices(actors_state)
|
| 652 |
|
| 653 |
|
| 654 |
+
def remove_selected_actor(selected_idx: str, actors_state: List[Dict[str, str]]):
|
| 655 |
actors_state = actors_state or []
|
| 656 |
+
try:
|
| 657 |
+
idx = int(selected_idx)
|
| 658 |
+
if 0 <= idx < len(actors_state):
|
| 659 |
+
actors_state.pop(idx)
|
| 660 |
+
except Exception:
|
| 661 |
+
pass
|
| 662 |
+
return actors_state, actor_table_md(actors_state), actor_dropdown_choices(actors_state)
|
| 663 |
|
| 664 |
|
| 665 |
def stepper_html(idx: int) -> str:
|
|
|
|
| 699 |
return ImageFont.load_default()
|
| 700 |
|
| 701 |
|
| 702 |
+
def trim_text_to_fit(text: str, max_len: int) -> str:
|
| 703 |
+
text = (text or "").strip()
|
| 704 |
+
if len(text) <= max_len:
|
| 705 |
+
return text
|
| 706 |
+
return text[:max_len - 3].rstrip() + "..."
|
| 707 |
+
|
| 708 |
+
|
| 709 |
def draw_panel(draw, xy, title, body, font_title, font_body, colors):
|
| 710 |
x1, y1, x2, y2 = xy
|
| 711 |
draw.rounded_rectangle(xy, radius=18, fill=colors["panel_bg"], outline=colors["panel_border"], width=2)
|
|
|
|
| 727 |
if current:
|
| 728 |
lines.append(current)
|
| 729 |
max_lines = max(4, int(((y2 - y1) - 90) / 28))
|
| 730 |
+
if len(lines) > max_lines:
|
| 731 |
+
lines = lines[:max_lines]
|
| 732 |
+
lines[-1] = trim_text_to_fit(lines[-1], max(20, len(lines[-1]) - 3))
|
| 733 |
y = y1 + 68
|
| 734 |
for line in lines:
|
| 735 |
draw.text((x1 + 24, y), line, fill=colors["text_color"], font=font_body)
|
|
|
|
| 742 |
img = Image.new("RGBA", (W, H), s["background_color"])
|
| 743 |
draw = ImageDraw.Draw(img)
|
| 744 |
|
| 745 |
+
font_header = load_font(34, bold=True)
|
| 746 |
font_title = load_font(24, bold=True)
|
| 747 |
font_body = load_font(18, bold=False)
|
| 748 |
+
font_footer = load_font(16, bold=False)
|
| 749 |
|
| 750 |
colors = {
|
| 751 |
"header_color": s["header_color"],
|
|
|
|
| 755 |
}
|
| 756 |
|
| 757 |
draw.rounded_rectangle((40, 30, W - 40, 180), radius=24, fill=colors["header_color"])
|
| 758 |
+
header_lines = textwrap.wrap(trim_text_to_fit(reto, 230), width=62)[:3]
|
| 759 |
+
y = 56
|
| 760 |
for line in header_lines:
|
| 761 |
draw.text((80, y), line, fill="white", font=font_header)
|
| 762 |
+
y += 40
|
| 763 |
|
| 764 |
draw_panel(draw, (40, 220, 930, 450), "1. Definición", definicion, font_title, font_body, colors)
|
| 765 |
draw_panel(draw, (40, 470, 930, 700), "2. Relevancia", relevancia, font_title, font_body, colors)
|
| 766 |
draw_panel(draw, (40, 720, 930, 940), "3. Conexión personal", conexion, font_title, font_body, colors)
|
| 767 |
draw_panel(draw, (990, 220, W - 40, 450), "4. Actores", actors_text, font_title, font_body, colors)
|
| 768 |
draw_panel(draw, (990, 470, W - 40, 940), "5. Gobernanza", gobernanza, font_title, font_body, colors)
|
| 769 |
+
|
| 770 |
+
iniciativas_box = (40, 960, W - 40, H - 120)
|
| 771 |
+
draw.rounded_rectangle(iniciativas_box, radius=18, fill=colors["panel_bg"], outline=colors["panel_border"], width=2)
|
| 772 |
+
draw.text((64, 978), "6. Iniciativas", fill=colors["text_color"], font=font_title)
|
| 773 |
+
ini_text = iniciativas if (iniciativas or "").strip() else "Sin contenido agregado todavía."
|
| 774 |
+
lines = textwrap.wrap(trim_text_to_fit(ini_text, 280), width=115)[:2]
|
| 775 |
+
y2 = 1018
|
| 776 |
+
for line in lines:
|
| 777 |
+
draw.text((64, y2), line, fill=colors["text_color"], font=font_body)
|
| 778 |
+
y2 += 24
|
| 779 |
|
| 780 |
footer_text = f"Generado el {datetime.now().strftime('%Y-%m-%d %H:%M')} • {APP_NAME}"
|
| 781 |
+
draw.text((60, H - 72), footer_text, fill=colors["text_color"], font=font_footer)
|
| 782 |
|
| 783 |
if LOGO_PATH.exists():
|
| 784 |
try:
|
| 785 |
logo = Image.open(LOGO_PATH).convert("RGBA")
|
| 786 |
+
logo.thumbnail((220, 56))
|
| 787 |
+
img.alpha_composite(logo, (W - logo.width - 60, H - logo.height - 42))
|
| 788 |
except Exception:
|
| 789 |
pass
|
| 790 |
|
|
|
|
| 808 |
session = session or {}
|
| 809 |
user_id = session.get("user_id", str(uuid4()))
|
| 810 |
actors_state = actors_state or []
|
| 811 |
+
actors_text = "\n".join([f"- {a.get('name','')} — {a.get('role','')}" if a.get("role") else f"- {a.get('name','')}" for a in actors_state]) or "Sin actores agregados todavía."
|
| 812 |
|
| 813 |
png = generate_canvas_image(reto, definicion, relevancia, conexion, actors_text, gobernanza, iniciativas, user_id)
|
| 814 |
canvas_dict = {
|
|
|
|
| 828 |
return """
|
| 829 |
<div class="info-card pop-in">
|
| 830 |
<h2>Cómo funciona este sistema</h2>
|
| 831 |
+
<p>Este prototipo combina una lectura conceptual de retos complejos con un asistente paso a paso para construir un board. El propósito es apoyar formulación, reflexión y documentación, no imponer una verdad absoluta. La lógica de evaluación se inspira en Cynefin y traduce siete rasgos cualitativos a una escala porcentual legible.</p>
|
| 832 |
+
|
| 833 |
+
<h3>Arquitectura de evaluación</h3>
|
| 834 |
+
<table style="width:100%;border-collapse:collapse;background:white;border:1px solid #e5e7eb;border-radius:18px;overflow:hidden;">
|
| 835 |
+
<tr style="background:#eff6ff;"><th style="padding:10px;text-align:left;">Capa</th><th style="padding:10px;text-align:left;">Qué hace</th><th style="padding:10px;text-align:left;">Salida</th></tr>
|
| 836 |
+
<tr><td style="padding:10px;">L0</td><td style="padding:10px;">Valida longitud, idioma, formulación interrogativa y contenido.</td><td style="padding:10px;">Apto o no apto para evaluar</td></tr>
|
| 837 |
+
<tr><td style="padding:10px;">Evaluación remota</td><td style="padding:10px;">Intenta analizar el reto con un modelo remoto de lenguaje usando un prompt estructurado y ejemplos guía.</td><td style="padding:10px;">Puntajes C1 a C7 y resumen</td></tr>
|
| 838 |
+
<tr><td style="padding:10px;">Evaluación local reforzada</td><td style="padding:10px;">Si el modelo remoto no responde, usa similitud semántica con ejemplos, señales conceptuales y conteo de actores.</td><td style="padding:10px;">Puntajes de contingencia</td></tr>
|
| 839 |
+
</table>
|
| 840 |
+
|
| 841 |
+
<h3>Qué significa cada porcentaje</h3>
|
| 842 |
+
<p>Cada criterio se traduce a una escala de 0 a 100. No representa probabilidad estadística. Representa intensidad relativa de presencia conceptual del rasgo en la formulación del reto.</p>
|
| 843 |
+
|
| 844 |
+
<table style="width:100%;border-collapse:collapse;background:white;border:1px solid #e5e7eb;border-radius:18px;overflow:hidden;">
|
| 845 |
+
<tr style="background:#eff6ff;"><th style="padding:10px;text-align:left;">Rango</th><th style="padding:10px;text-align:left;">Lectura</th></tr>
|
| 846 |
+
<tr><td style="padding:10px;">80–100</td><td style="padding:10px;">Presencia fuerte del rasgo</td></tr>
|
| 847 |
+
<tr><td style="padding:10px;">60–79</td><td style="padding:10px;">Presencia suficientemente clara</td></tr>
|
| 848 |
+
<tr><td style="padding:10px;">40–59</td><td style="padding:10px;">Presencia parcial o implícita</td></tr>
|
| 849 |
+
<tr><td style="padding:10px;">0–39</td><td style="padding:10px;">Presencia débil o no observable</td></tr>
|
| 850 |
+
</table>
|
| 851 |
+
|
| 852 |
+
<h3>Fórmulas</h3>
|
| 853 |
<div style="background:white;border:1px solid #e5e7eb;border-radius:20px;padding:16px;margin:14px 0;">
|
| 854 |
+
<div style="font-weight:700;margin-bottom:8px;">Puntaje global</div>
|
| 855 |
<div style="font-family:monospace;background:#f8fafc;border-radius:12px;padding:12px;">
|
| 856 |
Puntaje global = (C1 + C2 + C3 + C4 + C5 + C6 + C7) / 7
|
| 857 |
</div>
|
| 858 |
</div>
|
| 859 |
+
<div style="background:white;border:1px solid #e5e7eb;border-radius:20px;padding:16px;margin:14px 0;">
|
| 860 |
+
<div style="font-weight:700;margin-bottom:8px;">Lógica de contingencia local</div>
|
| 861 |
+
<div style="font-family:monospace;background:#f8fafc;border-radius:12px;padding:12px;">
|
| 862 |
+
base_criterio = 28 + (13 × señales_detectadas) + ajustes_por_similitud + ajustes_por_actores
|
| 863 |
+
</div>
|
| 864 |
+
</div>
|
| 865 |
+
|
| 866 |
+
<h3>Cómo interpreta cada criterio</h3>
|
| 867 |
<ul>
|
| 868 |
+
<li><b>C1 Incertidumbre alta</b> se apoya en literatura de complejidad que distingue entre problemas obvios y contextos donde no existe una ruta lineal única.</li>
|
| 869 |
+
<li><b>C2 Multiplicidad de actores</b> toma la idea de que los retos complejos se despliegan entre múltiples partes con intereses y capacidades distintas.</li>
|
| 870 |
+
<li><b>C3 Interdependencia</b> examina si el reto presenta relaciones cruzadas, afectación mutua o lógica sistémica.</li>
|
| 871 |
+
<li><b>C4 Emergencia sobre imposición</b> recoge el principio de que en complejidad las respuestas suelen emerger de interacción, ajuste y aprendizaje.</li>
|
| 872 |
+
<li><b>C5 Gestión por restricciones</b> considera límites institucionales, éticos, territoriales o de recursos que moldean la intervención.</li>
|
| 873 |
+
<li><b>C6 Experimentación</b> incorpora la idea de probe–sense–respond y de pruebas pequeñas para aprender antes de escalar.</li>
|
| 874 |
+
<li><b>C7 Aprendizaje y adaptación</b> valora si el reto exige observar, corregir y reconfigurar continuamente.</li>
|
| 875 |
</ul>
|
| 876 |
+
|
| 877 |
+
<h3>Cómo leer la fuente del resultado</h3>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 878 |
<ul>
|
| 879 |
+
<li><b>LLM remoto</b> significa que hubo respuesta válida del modelo.</li>
|
| 880 |
+
<li><b>Evaluación local reforzada</b> significa que el sistema no consiguió respuesta remota y activó el modo de contingencia.</li>
|
|
|
|
|
|
|
| 881 |
</ul>
|
| 882 |
+
|
| 883 |
+
<h3>Referencias conceptuales</h3>
|
| 884 |
<ul>
|
| 885 |
<li>Snowden, D. J., & Boone, M. E. 2007. A Leader’s Framework for Decision Making. Harvard Business Review.</li>
|
| 886 |
<li>Kurtz, C. F., & Snowden, D. J. 2003. The new dynamics of strategy. IBM Systems Journal.</li>
|
| 887 |
<li>Snowden, D. J. 2010. The Cynefin framework and naturalizing sense-making.</li>
|
| 888 |
+
<li>Stacey, R. D. trabajos sobre complejidad organizacional y dinámica no lineal.</li>
|
| 889 |
</ul>
|
| 890 |
</div>
|
| 891 |
"""
|
|
|
|
| 898 |
[],
|
| 899 |
idx,
|
| 900 |
stepper_html(idx),
|
| 901 |
+
"", "", "<div></div>", "", "", "", "", "Sin actores agregados todavía.", None, "", "", None, None, "🔴 Estado remoto no verificado",
|
| 902 |
*render_step_visibility(idx),
|
| 903 |
gr.update(interactive=False),
|
| 904 |
gr.update(interactive=False)
|
| 905 |
)
|
| 906 |
|
| 907 |
|
| 908 |
+
def remote_status_text():
|
| 909 |
+
ok, msg = ping_remote_eval()
|
| 910 |
+
return ("🟢 " if ok else "🔴 ") + msg
|
| 911 |
+
|
| 912 |
+
|
| 913 |
def build_app():
|
| 914 |
examples = [[ex["text"]] for ex in DEFAULT_EXAMPLES]
|
| 915 |
theme = gr.themes.Soft(primary_hue="blue", secondary_hue="slate", neutral_hue="slate")
|
|
|
|
| 939 |
.animate-fill {animation: fillin .6s ease;}
|
| 940 |
.nav-row {display:flex; gap:12px;}
|
| 941 |
.pop-in {animation: popin .28s ease;}
|
| 942 |
+
.status-pill {display:inline-block;padding:8px 12px;border-radius:999px;background:white;border:1px solid #e5e7eb;font-weight:700;}
|
| 943 |
@keyframes fillin {from {width:0;} to {width:100%;}}
|
| 944 |
@keyframes popin {from {opacity:0; transform:translateY(6px);} to {opacity:1; transform:translateY(0);}}
|
| 945 |
"""
|
|
|
|
| 962 |
stepper = gr.HTML(stepper_html(0))
|
| 963 |
|
| 964 |
with gr.Group(visible=True) as step0:
|
| 965 |
+
remote_status = gr.Markdown("🔴 Estado remoto no verificado")
|
| 966 |
+
remote_ping_btn = gr.Button("Probar disponibilidad del LLM")
|
| 967 |
reto_input = gr.Textbox(label="Paso 1 • Escribe el reto", lines=6, placeholder="Escribe una pregunta de al menos 100 caracteres.")
|
| 968 |
gr.Examples(examples=examples, inputs=[reto_input], label="Ejemplos guía")
|
| 969 |
with gr.Row():
|
|
|
|
| 995 |
actor_role = gr.Textbox(label="Rol", scale=3)
|
| 996 |
with gr.Row():
|
| 997 |
actor_add_btn = gr.Button("Agregar actor")
|
|
|
|
| 998 |
actor_md = gr.Markdown("Sin actores agregados todavía.")
|
| 999 |
+
actor_select_remove = gr.Dropdown(label="Selecciona un actor para eliminar", choices=[], value=None)
|
| 1000 |
+
actor_remove_btn = gr.Button("Eliminar actor seleccionado")
|
| 1001 |
|
| 1002 |
with gr.Group(visible=False) as step5:
|
| 1003 |
gr.Markdown("## Paso 6 • Gobernanza")
|
|
|
|
| 1023 |
with gr.Tab("Cómo funciona"):
|
| 1024 |
info = gr.HTML(info_html())
|
| 1025 |
|
| 1026 |
+
remote_ping_btn.click(fn=remote_status_text, outputs=[remote_status])
|
| 1027 |
+
|
| 1028 |
eval_btn.click(
|
| 1029 |
fn=evaluate_step,
|
| 1030 |
inputs=[reto_input, session],
|
|
|
|
| 1061 |
outputs=[conexion]
|
| 1062 |
)
|
| 1063 |
|
| 1064 |
+
actor_add_btn.click(
|
| 1065 |
+
fn=add_actor,
|
| 1066 |
+
inputs=[actor_name, actor_role, actors_state],
|
| 1067 |
+
outputs=[actors_state, actor_md, actor_name, actor_role, actor_select_remove]
|
| 1068 |
+
)
|
| 1069 |
+
|
| 1070 |
+
actor_remove_btn.click(
|
| 1071 |
+
fn=remove_selected_actor,
|
| 1072 |
+
inputs=[actor_select_remove, actors_state],
|
| 1073 |
+
outputs=[actors_state, actor_md, actor_select_remove]
|
| 1074 |
+
)
|
| 1075 |
|
| 1076 |
ask_gob.click(
|
| 1077 |
fn=lambda reto, d, r, c, g, i, actors: suggest_section_answer(reto, "gobernanza", {"definicion": d, "relevancia": r, "conexion": c, "gobernanza": g, "iniciativas": i, "actors": actors}),
|
|
|
|
| 1096 |
outputs=[
|
| 1097 |
session, actors_state, wizard_idx, stepper,
|
| 1098 |
reto_input, eval_md, eval_chart, reto_hidden,
|
| 1099 |
+
definicion, relevancia, conexion, actor_md, actor_select_remove,
|
| 1100 |
+
gobernanza, iniciativas, board_preview, board_file, remote_status,
|
| 1101 |
step0, step1, step2, step3, step4, step5, step6, step7,
|
| 1102 |
prev_btn, next_btn
|
| 1103 |
]
|
|
|
|
| 1111 |
|
| 1112 |
if __name__ == "__main__":
|
| 1113 |
app.launch()
|
|
|