Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- app.py +70 -2
- run_logs_v3.txt +8 -0
app.py
CHANGED
|
@@ -44,7 +44,75 @@ def get_persona_details(sim_id, persona_name):
|
|
| 44 |
persona = simulation_manager.get_persona(sim_id, persona_name)
|
| 45 |
return json.dumps(persona, indent=2) if persona else "Not found"
|
| 46 |
|
| 47 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
with gr.Blocks(css=".big-input textarea { height: 300px !important; } #mesh-network-container { height: 600px; background: #101622; border-radius: 12px; }", title="Tiny Factory") as demo:
|
| 49 |
gr.HTML('<script src="https://unpkg.com/vis-network/standalone/umd/vis-network.min.js"></script>')
|
| 50 |
gr.Markdown("# 🌐 Tiny Factory: Social Simulation Dashboard")
|
|
@@ -85,7 +153,7 @@ with gr.Blocks(css=".big-input textarea { height: 300px !important; } #mesh-netw
|
|
| 85 |
nodes_state = gr.State([])
|
| 86 |
edges_state = gr.State([])
|
| 87 |
|
| 88 |
-
# Hidden
|
| 89 |
js_trigger = gr.Textbox(visible=False, elem_id="js_trigger_textbox")
|
| 90 |
js_trigger_btn = gr.Button("trigger", visible=False, elem_id="js_trigger_btn")
|
| 91 |
|
|
|
|
| 44 |
persona = simulation_manager.get_persona(sim_id, persona_name)
|
| 45 |
return json.dumps(persona, indent=2) if persona else "Not found"
|
| 46 |
|
| 47 |
+
# API functions for backward compatibility
|
| 48 |
+
def generate_social_network_api(name, persona_count, network_type, focus_group_name=None):
|
| 49 |
+
config = SimulationConfig(name=name, persona_count=int(persona_count), network_type=network_type)
|
| 50 |
+
sim = simulation_manager.create_simulation(config, focus_group_name)
|
| 51 |
+
return {"simulation_id": sim.id, "persona_count": len(sim.personas)}
|
| 52 |
+
|
| 53 |
+
def predict_engagement_api(simulation_id, content_text, format_type):
|
| 54 |
+
sim = simulation_manager.get_simulation(simulation_id)
|
| 55 |
+
if not sim: return {"error": "Simulation not found"}
|
| 56 |
+
content = Content(text=content_text, format=format_type)
|
| 57 |
+
results = []
|
| 58 |
+
for p in sim.personas:
|
| 59 |
+
reaction = p.predict_reaction(content)
|
| 60 |
+
results.append({"persona": p.name, "will_engage": reaction.will_engage, "probability": reaction.probability})
|
| 61 |
+
return results
|
| 62 |
+
|
| 63 |
+
def start_simulation_async_api(simulation_id, content_text, format_type):
|
| 64 |
+
content = Content(text=content_text, format=format_type)
|
| 65 |
+
simulation_manager.run_simulation(simulation_id, content, background=True)
|
| 66 |
+
return {"status": "started", "simulation_id": simulation_id}
|
| 67 |
+
|
| 68 |
+
def get_simulation_status_api(simulation_id):
|
| 69 |
+
sim = simulation_manager.get_simulation(simulation_id)
|
| 70 |
+
if not sim: return {"error": "Simulation not found"}
|
| 71 |
+
return {"status": sim.status, "progress": sim.progress}
|
| 72 |
+
|
| 73 |
+
def send_chat_message_api(simulation_id, sender, message):
|
| 74 |
+
return simulation_manager.send_chat_message(simulation_id, sender, message)
|
| 75 |
+
|
| 76 |
+
def get_chat_history_api(simulation_id):
|
| 77 |
+
return simulation_manager.get_chat_history(simulation_id)
|
| 78 |
+
|
| 79 |
+
def generate_variants_api(original_content, num_variants):
|
| 80 |
+
variants = simulation_manager.variant_generator.generate_variants(original_content, int(num_variants))
|
| 81 |
+
return [v.text for v in variants]
|
| 82 |
+
|
| 83 |
+
def list_simulations_api():
|
| 84 |
+
return simulation_manager.list_simulations()
|
| 85 |
+
|
| 86 |
+
def list_personas_api(simulation_id):
|
| 87 |
+
return simulation_manager.list_personas(simulation_id)
|
| 88 |
+
|
| 89 |
+
def get_persona_api(simulation_id, persona_name):
|
| 90 |
+
return simulation_manager.get_persona(simulation_id, persona_name)
|
| 91 |
+
|
| 92 |
+
def delete_simulation_api(simulation_id):
|
| 93 |
+
success = simulation_manager.delete_simulation(simulation_id)
|
| 94 |
+
return {"success": success}
|
| 95 |
+
|
| 96 |
+
def export_simulation_api(simulation_id):
|
| 97 |
+
return simulation_manager.export_simulation(simulation_id)
|
| 98 |
+
|
| 99 |
+
def get_network_graph_api(simulation_id):
|
| 100 |
+
sim = simulation_manager.get_simulation(simulation_id)
|
| 101 |
+
if not sim: return {"error": "Simulation not found"}
|
| 102 |
+
nodes = [{"id": p.name, "label": p.name, "role": p._persona.get("occupation")} for p in sim.personas]
|
| 103 |
+
edges = [{"source": e.connection_id.split('_')[0], "target": e.connection_id.split('_')[1]} for e in sim.network.edges]
|
| 104 |
+
return {"nodes": nodes, "edges": edges}
|
| 105 |
+
|
| 106 |
+
def list_focus_groups_api():
|
| 107 |
+
return simulation_manager.list_focus_groups()
|
| 108 |
+
|
| 109 |
+
def save_focus_group_api(name, simulation_id):
|
| 110 |
+
sim = simulation_manager.get_simulation(simulation_id)
|
| 111 |
+
if not sim: return {"error": "Simulation not found"}
|
| 112 |
+
simulation_manager.save_focus_group(name, sim.personas)
|
| 113 |
+
return {"status": "success", "name": name}
|
| 114 |
+
|
| 115 |
+
# UI Layout
|
| 116 |
with gr.Blocks(css=".big-input textarea { height: 300px !important; } #mesh-network-container { height: 600px; background: #101622; border-radius: 12px; }", title="Tiny Factory") as demo:
|
| 117 |
gr.HTML('<script src="https://unpkg.com/vis-network/standalone/umd/vis-network.min.js"></script>')
|
| 118 |
gr.Markdown("# 🌐 Tiny Factory: Social Simulation Dashboard")
|
|
|
|
| 153 |
nodes_state = gr.State([])
|
| 154 |
edges_state = gr.State([])
|
| 155 |
|
| 156 |
+
# Hidden components for JS interaction
|
| 157 |
js_trigger = gr.Textbox(visible=False, elem_id="js_trigger_textbox")
|
| 158 |
js_trigger_btn = gr.Button("trigger", visible=False, elem_id="js_trigger_btn")
|
| 159 |
|
run_logs_v3.txt
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
| 0 |
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
|
| 1 |
0 0 0 0 0 0 0 0 --:--:-- 0:00:01 --:--:-- 0
|
| 2 |
0 0 0 0 0 0 0 0 --:--:-- 0:00:02 --:--:-- 0
|
| 3 |
0 0 0 0 0 0 0 0 --:--:-- 0:00:03 --:--:-- 0
|
| 4 |
0 0 0 0 0 0 0 0 --:--:-- 0:00:04 --:--:-- 0
|
| 5 |
0 0 0 0 0 0 0 0 --:--:-- 0:00:05 --:--:-- 0
|
| 6 |
0 0 0 0 0 0 0 0 --:--:-- 0:00:06 --:--:-- 0
|
| 7 |
0 0 0 0 0 0 0 0 --:--:-- 0:00:07 --:--:-- 0
|
| 8 |
0 0 0 0 0 0 0 0 --:--:-- 0:00:08 --:--:-- 0
|
| 9 |
0 0 0 0 0 0 0 0 --:--:-- 0:00:09 --:--:-- 0data: {"data":"===== Application Startup at 2026-02-18 20:12:43 =====\n","timestamp":"2026-02-18T20:12:43Z"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
% Total % Received % Xferd Average Speed Time Time Time Current
|
| 2 |
+
Dload Upload Total Spent Left Speed
|
| 3 |
+
|
| 4 |
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
|
| 5 |
0 0 0 0 0 0 0 0 --:--:-- 0:00:01 --:--:-- 0
|
| 6 |
0 0 0 0 0 0 0 0 --:--:-- 0:00:02 --:--:-- 0
|
| 7 |
0 0 0 0 0 0 0 0 --:--:-- 0:00:03 --:--:-- 0
|
| 8 |
0 0 0 0 0 0 0 0 --:--:-- 0:00:04 --:--:-- 0
|
| 9 |
0 0 0 0 0 0 0 0 --:--:-- 0:00:05 --:--:-- 0
|
| 10 |
0 0 0 0 0 0 0 0 --:--:-- 0:00:06 --:--:-- 0
|
| 11 |
0 0 0 0 0 0 0 0 --:--:-- 0:00:07 --:--:-- 0
|
| 12 |
0 0 0 0 0 0 0 0 --:--:-- 0:00:08 --:--:-- 0
|
| 13 |
0 0 0 0 0 0 0 0 --:--:-- 0:00:09 --:--:-- 0data: {"data":"===== Application Startup at 2026-02-18 20:12:43 =====\n","timestamp":"2026-02-18T20:12:43Z"}
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
curl: (56) Recv failure: Connection reset by peer
|