Spaces:
Running
Running
Upload folder using huggingface_hub
Browse files
app.py
CHANGED
|
@@ -281,6 +281,36 @@ def export_simulation_api(simulation_id):
|
|
| 281 |
return {"error": str(e)}
|
| 282 |
|
| 283 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 284 |
def list_focus_groups_api():
|
| 285 |
"""
|
| 286 |
Gradio API endpoint for listing focus groups.
|
|
@@ -425,6 +455,12 @@ with gr.Blocks() as demo:
|
|
| 425 |
api_exp_out = gr.JSON()
|
| 426 |
api_exp_btn.click(export_simulation_api, inputs=[api_exp_sim_id], outputs=api_exp_out, api_name="export_simulation")
|
| 427 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 428 |
with gr.Tab("Focus Group API", visible=False):
|
| 429 |
api_list_fg_btn = gr.Button("List Focus Groups")
|
| 430 |
api_list_fg_out = gr.JSON()
|
|
|
|
| 281 |
return {"error": str(e)}
|
| 282 |
|
| 283 |
|
| 284 |
+
def get_network_graph_api(simulation_id):
|
| 285 |
+
"""
|
| 286 |
+
Gradio API endpoint for getting network graph data.
|
| 287 |
+
"""
|
| 288 |
+
try:
|
| 289 |
+
sim = simulation_manager.get_simulation(simulation_id)
|
| 290 |
+
if not sim: return {"error": "Simulation not found"}
|
| 291 |
+
|
| 292 |
+
nodes = []
|
| 293 |
+
for p in sim.personas:
|
| 294 |
+
nodes.append({
|
| 295 |
+
"id": p.name,
|
| 296 |
+
"label": p.name,
|
| 297 |
+
"role": p._persona.get("occupation"),
|
| 298 |
+
"location": p._persona.get("residence")
|
| 299 |
+
})
|
| 300 |
+
|
| 301 |
+
edges = []
|
| 302 |
+
for edge in sim.network.edges:
|
| 303 |
+
edges.append({
|
| 304 |
+
"source": edge.connection_id.split('_')[0],
|
| 305 |
+
"target": edge.connection_id.split('_')[1],
|
| 306 |
+
"strength": edge.strength
|
| 307 |
+
})
|
| 308 |
+
|
| 309 |
+
return {"nodes": nodes, "edges": edges}
|
| 310 |
+
except Exception as e:
|
| 311 |
+
return {"error": str(e)}
|
| 312 |
+
|
| 313 |
+
|
| 314 |
def list_focus_groups_api():
|
| 315 |
"""
|
| 316 |
Gradio API endpoint for listing focus groups.
|
|
|
|
| 455 |
api_exp_out = gr.JSON()
|
| 456 |
api_exp_btn.click(export_simulation_api, inputs=[api_exp_sim_id], outputs=api_exp_out, api_name="export_simulation")
|
| 457 |
|
| 458 |
+
with gr.Tab("Network Graph API", visible=False):
|
| 459 |
+
api_graph_sim_id = gr.Textbox(label="Simulation ID")
|
| 460 |
+
api_graph_btn = gr.Button("Get Graph Data")
|
| 461 |
+
api_graph_out = gr.JSON()
|
| 462 |
+
api_graph_btn.click(get_network_graph_api, inputs=[api_graph_sim_id], outputs=api_graph_out, api_name="get_network_graph")
|
| 463 |
+
|
| 464 |
with gr.Tab("Focus Group API", visible=False):
|
| 465 |
api_list_fg_btn = gr.Button("List Focus Groups")
|
| 466 |
api_list_fg_out = gr.JSON()
|