Update app.py
Browse files
app.py
CHANGED
|
@@ -161,14 +161,16 @@ def activate_agent(name: str, prompt: str, in_coll: bool):
|
|
| 161 |
# ββ Load from collection signal (JS β Python) βββββββββββββββββββββββββββββββββ
|
| 162 |
|
| 163 |
def _load_signal(signal: str):
|
| 164 |
-
"""Parse the JSON signal emitted by agentForgeLoad() in JS."""
|
| 165 |
if not signal or signal.strip() == "":
|
| 166 |
-
return gr.update(), gr.update()
|
| 167 |
try:
|
| 168 |
data = json.loads(signal)
|
| 169 |
-
|
|
|
|
|
|
|
| 170 |
except Exception:
|
| 171 |
-
return gr.update(), gr.update()
|
| 172 |
|
| 173 |
# ββ Status HTML βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 174 |
|
|
@@ -220,7 +222,7 @@ def _render_collection() -> str:
|
|
| 220 |
for i, agent in enumerate(reversed(agents)):
|
| 221 |
name = agent.get("name", "Unnamed Agent")
|
| 222 |
prompt = agent.get("system_prompt", "")
|
| 223 |
-
preview = (prompt[:
|
| 224 |
date = agent.get("timestamp", "")[:10]
|
| 225 |
color = _agent_color(i)
|
| 226 |
chars = len(prompt)
|
|
@@ -252,8 +254,8 @@ def _render_collection() -> str:
|
|
| 252 |
</span>
|
| 253 |
<span style="font-size:.68rem;color:#6b6b88;white-space:nowrap;">{date}</span>
|
| 254 |
</div>
|
| 255 |
-
<div style="font-size:.74rem;color:#
|
| 256 |
-
white-space:pre-wrap;max-height:
|
| 257 |
{preview.replace('<','<').replace('>','>')}
|
| 258 |
</div>
|
| 259 |
<div style="margin-top:10px;display:flex;align-items:center;gap:8px;">
|
|
@@ -561,25 +563,15 @@ button.secondary:hover {
|
|
| 561 |
.chatbot-wrap { border-color: var(--border2) !important; }
|
| 562 |
.message-bubble-border { border-color: var(--border2) !important; }
|
| 563 |
|
| 564 |
-
/* Gradio 6:
|
| 565 |
-
|
| 566 |
-
|
| 567 |
-
|
| 568 |
-
|
| 569 |
-
|
| 570 |
-
word-break: break-word !important;
|
| 571 |
white-space: pre-wrap !important;
|
|
|
|
| 572 |
overflow-wrap: break-word !important;
|
| 573 |
-
min-width: 0 !important;
|
| 574 |
-
width: auto !important;
|
| 575 |
-
writing-mode: horizontal-tb !important;
|
| 576 |
-
text-orientation: mixed !important;
|
| 577 |
-
}
|
| 578 |
-
/* Ensure message container has proper width */
|
| 579 |
-
.message-wrap, [class*="message-wrap"], [class*="bubble"] {
|
| 580 |
-
max-width: 85% !important;
|
| 581 |
-
min-width: 60px !important;
|
| 582 |
-
width: auto !important;
|
| 583 |
}
|
| 584 |
|
| 585 |
/* ββ Accordion ββ */
|
|
@@ -835,11 +827,15 @@ from community-forged prompts.
|
|
| 835 |
# 4. Clear chat
|
| 836 |
clear_btn.click(fn=lambda: [], outputs=[chatbot])
|
| 837 |
|
| 838 |
-
# 5. Load agent from JS signal (collection card click)
|
| 839 |
agent_load_signal.change(
|
| 840 |
fn=_load_signal,
|
| 841 |
inputs=[agent_load_signal],
|
| 842 |
-
outputs=[agent_name_box, prompt_box],
|
|
|
|
|
|
|
|
|
|
|
|
|
| 843 |
)
|
| 844 |
|
| 845 |
# 6. Refresh collection (triggered by hidden button from JS)
|
|
|
|
| 161 |
# ββ Load from collection signal (JS β Python) βββββββββββββββββββββββββββββββββ
|
| 162 |
|
| 163 |
def _load_signal(signal: str):
|
| 164 |
+
"""Parse the JSON signal emitted by agentForgeLoad() in JS and activate the agent."""
|
| 165 |
if not signal or signal.strip() == "":
|
| 166 |
+
return gr.update(), gr.update(), gr.update(), gr.update()
|
| 167 |
try:
|
| 168 |
data = json.loads(signal)
|
| 169 |
+
name = data.get("name", "")
|
| 170 |
+
prompt = data.get("prompt", "")
|
| 171 |
+
return name, prompt, prompt, name
|
| 172 |
except Exception:
|
| 173 |
+
return gr.update(), gr.update(), gr.update(), gr.update()
|
| 174 |
|
| 175 |
# ββ Status HTML βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 176 |
|
|
|
|
| 222 |
for i, agent in enumerate(reversed(agents)):
|
| 223 |
name = agent.get("name", "Unnamed Agent")
|
| 224 |
prompt = agent.get("system_prompt", "")
|
| 225 |
+
preview = (prompt[:100] + "β¦") if len(prompt) > 100 else prompt
|
| 226 |
date = agent.get("timestamp", "")[:10]
|
| 227 |
color = _agent_color(i)
|
| 228 |
chars = len(prompt)
|
|
|
|
| 254 |
</span>
|
| 255 |
<span style="font-size:.68rem;color:#6b6b88;white-space:nowrap;">{date}</span>
|
| 256 |
</div>
|
| 257 |
+
<div style="font-size:.74rem;color:#aaa;line-height:1.5;font-family:'JetBrains Mono',monospace;
|
| 258 |
+
white-space:pre-wrap;max-height:42px;overflow:hidden;">
|
| 259 |
{preview.replace('<','<').replace('>','>')}
|
| 260 |
</div>
|
| 261 |
<div style="margin-top:10px;display:flex;align-items:center;gap:8px;">
|
|
|
|
| 563 |
.chatbot-wrap { border-color: var(--border2) !important; }
|
| 564 |
.message-bubble-border { border-color: var(--border2) !important; }
|
| 565 |
|
| 566 |
+
/* Gradio 6: ensure chat messages use full available width */
|
| 567 |
+
.chatbot .message-wrap {
|
| 568 |
+
max-width: 85% !important;
|
| 569 |
+
min-width: 120px !important;
|
| 570 |
+
}
|
| 571 |
+
.chatbot .message-wrap p {
|
|
|
|
| 572 |
white-space: pre-wrap !important;
|
| 573 |
+
word-break: break-word !important;
|
| 574 |
overflow-wrap: break-word !important;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 575 |
}
|
| 576 |
|
| 577 |
/* ββ Accordion ββ */
|
|
|
|
| 827 |
# 4. Clear chat
|
| 828 |
clear_btn.click(fn=lambda: [], outputs=[chatbot])
|
| 829 |
|
| 830 |
+
# 5. Load agent from JS signal (collection card click) β also activates
|
| 831 |
agent_load_signal.change(
|
| 832 |
fn=_load_signal,
|
| 833 |
inputs=[agent_load_signal],
|
| 834 |
+
outputs=[agent_name_box, prompt_box, system_prompt_state, active_name_state],
|
| 835 |
+
).then(
|
| 836 |
+
fn=_render_active_badge,
|
| 837 |
+
inputs=[active_name_state],
|
| 838 |
+
outputs=[active_badge_html],
|
| 839 |
)
|
| 840 |
|
| 841 |
# 6. Refresh collection (triggered by hidden button from JS)
|