import plotly.graph_objects as go def build_cluster_graph(results, clusters): xs, ys, labels = [], [], [] i = 0 for agency, docs in clusters.items(): for d in docs: xs.append(i) ys.append(len(docs)) labels.append(f"{agency}: {d['title']}") i += 1 fig = go.Figure( go.Scatter( x=xs, y=ys, mode="markers", text=labels, marker=dict(size=10), ) ) fig.update_layout( title="Semantic Cluster Graph (Click nodes to inspect documents)", xaxis_title="Document Index", yaxis_title="Cluster Density", ) return fig