Update app.py
Browse files
app.py
CHANGED
|
@@ -323,7 +323,19 @@ def world_to_svg(world: World) -> str:
|
|
| 323 |
size = WORLD_SIZE_PX
|
| 324 |
cell = size // GRID_SIZE
|
| 325 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 326 |
svg = [
|
|
|
|
| 327 |
f'<svg width="{size}" height="{size}" viewBox="0 0 {size} {size}" '
|
| 328 |
f'style="background:radial-gradient(circle at top,#0f172a,#020617);'
|
| 329 |
f'border-radius:16px;border:1px solid #1f2937;box-shadow:0 18px 40px rgba(15,23,42,0.9);" '
|
|
@@ -558,8 +570,8 @@ def simulation_loop():
|
|
| 558 |
def serialize_world(world: World) -> dict:
|
| 559 |
return {
|
| 560 |
"model_id": world.model_id,
|
| 561 |
-
|
| 562 |
-
|
| 563 |
}
|
| 564 |
|
| 565 |
|
|
@@ -605,6 +617,7 @@ Un piccolo mondo simulato dove agenti LLM:
|
|
| 605 |
- possono "morire" e rinascere con nuove identità.
|
| 606 |
|
| 607 |
La simulazione gira in **background** in modo continuo.
|
|
|
|
| 608 |
"""
|
| 609 |
)
|
| 610 |
|
|
@@ -660,14 +673,6 @@ La simulazione gira in **background** in modo continuo.
|
|
| 660 |
outputs=[status_text],
|
| 661 |
)
|
| 662 |
|
| 663 |
-
# auto-refresh ogni secondo, senza clic
|
| 664 |
-
demo.load(
|
| 665 |
-
fn=ui_refresh,
|
| 666 |
-
inputs=[],
|
| 667 |
-
outputs=[svg_out, html_out, state_out],
|
| 668 |
-
every=1.0,
|
| 669 |
-
)
|
| 670 |
-
|
| 671 |
# avvio thread di simulazione in background
|
| 672 |
threading.Thread(target=simulation_loop, daemon=True).start()
|
| 673 |
|
|
|
|
| 323 |
size = WORLD_SIZE_PX
|
| 324 |
cell = size // GRID_SIZE
|
| 325 |
|
| 326 |
+
# auto-refresh HTML/JS: ricarica la pagina ogni secondo
|
| 327 |
+
refresh_js = """
|
| 328 |
+
<script>
|
| 329 |
+
if (typeof window !== 'undefined') {
|
| 330 |
+
setTimeout(function() {
|
| 331 |
+
window.location.reload();
|
| 332 |
+
}, 1000);
|
| 333 |
+
}
|
| 334 |
+
</script>
|
| 335 |
+
"""
|
| 336 |
+
|
| 337 |
svg = [
|
| 338 |
+
refresh_js,
|
| 339 |
f'<svg width="{size}" height="{size}" viewBox="0 0 {size} {size}" '
|
| 340 |
f'style="background:radial-gradient(circle at top,#0f172a,#020617);'
|
| 341 |
f'border-radius:16px;border:1px solid #1f2937;box-shadow:0 18px 40px rgba(15,23,42,0.9);" '
|
|
|
|
| 570 |
def serialize_world(world: World) -> dict:
|
| 571 |
return {
|
| 572 |
"model_id": world.model_id,
|
| 573 |
+
"step": world.step,
|
| 574 |
+
"agents": [a.to_dict() for a in world.agents],
|
| 575 |
}
|
| 576 |
|
| 577 |
|
|
|
|
| 617 |
- possono "morire" e rinascere con nuove identità.
|
| 618 |
|
| 619 |
La simulazione gira in **background** in modo continuo.
|
| 620 |
+
La vista si aggiorna automaticamente ogni ~1 secondo.
|
| 621 |
"""
|
| 622 |
)
|
| 623 |
|
|
|
|
| 673 |
outputs=[status_text],
|
| 674 |
)
|
| 675 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 676 |
# avvio thread di simulazione in background
|
| 677 |
threading.Thread(target=simulation_loop, daemon=True).start()
|
| 678 |
|