Spaces:
Sleeping
Sleeping
Chunhua Liao
commited on
Commit
·
96b11b9
1
Parent(s):
4ebc5c4
Remove interactive graph display from Gradio app
Browse files- Removed HTML and JavaScript code responsible for rendering the vis.js graph in .
- Deleted the external JavaScript file .
- The backend logic for generating graph data (in and ) is retained as per user request, but the frontend visualization is now removed.
- app.py +2 -23
- static/js/graph_renderer.js +0 -99
app.py
CHANGED
@@ -266,27 +266,6 @@ def format_cycle_results(cycle_details: Dict) -> str:
|
|
266 |
html += f"<p>Average similarity: {avg_sim:.3f}</p>"
|
267 |
html += f"<p>Total connections analyzed: {len(all_similarities)}</p>"
|
268 |
|
269 |
-
# Interactive Graph Visualization
|
270 |
-
import json as _json
|
271 |
-
nodes_json = _json.dumps(nodes)
|
272 |
-
edges_json = _json.dumps(edges)
|
273 |
-
|
274 |
-
logger.info(f"Nodes JSON: {nodes_json[:200]}...") # Log first 200 chars
|
275 |
-
logger.info(f"Edges JSON: {edges_json[:200]}...") # Log first 200 chars
|
276 |
-
|
277 |
-
graph_id = f"graph_{int(time.time() * 1000)}" # Unique ID for this graph
|
278 |
-
html += f"""
|
279 |
-
<h6>Interactive Similarity Graph:</h6>
|
280 |
-
<div style="margin: 15px 0;">
|
281 |
-
<p><em>Each node represents a hypothesis. Lines show similarity scores (only > 0.2 shown). Click and drag to explore!</em></p>
|
282 |
-
<div id="{graph_id}" style="width: 100%; height: 400px; border: 1px solid #ccc; background-color: #fafafa;"></div>
|
283 |
-
</div>
|
284 |
-
|
285 |
-
<script src="https://unpkg.com/vis-network/standalone/umd/vis-network.min.js"></script>
|
286 |
-
<div id="{graph_id}" class="vis-graph-container" style="width: 100%; height: 400px; border: 1px solid #ccc; background-color: #fafafa;" data-nodes='{nodes_json}' data-edges='{edges_json}'></div>
|
287 |
-
<script src="/file=static/js/graph_renderer.js"></script>
|
288 |
-
"""
|
289 |
-
|
290 |
# Show top similar pairs
|
291 |
similarity_pairs = []
|
292 |
for hypo_id, connections in adjacency_graph.items():
|
@@ -300,8 +279,8 @@ def format_cycle_results(cycle_details: Dict) -> str:
|
|
300 |
for i, (id1, id2, sim) in enumerate(similarity_pairs[:5]):
|
301 |
html += f"<li>{id1} ↔ {id2}: {sim:.3f}</li>"
|
302 |
html += "</ul>"
|
303 |
-
|
304 |
-
|
305 |
|
306 |
elif step_name == 'meta_review':
|
307 |
meta_review = step_data.get('meta_review', {})
|
|
|
266 |
html += f"<p>Average similarity: {avg_sim:.3f}</p>"
|
267 |
html += f"<p>Total connections analyzed: {len(all_similarities)}</p>"
|
268 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
269 |
# Show top similar pairs
|
270 |
similarity_pairs = []
|
271 |
for hypo_id, connections in adjacency_graph.items():
|
|
|
279 |
for i, (id1, id2, sim) in enumerate(similarity_pairs[:5]):
|
280 |
html += f"<li>{id1} ↔ {id2}: {sim:.3f}</li>"
|
281 |
html += "</ul>"
|
282 |
+
else:
|
283 |
+
html += "<p>No proximity data available.</p>"
|
284 |
|
285 |
elif step_name == 'meta_review':
|
286 |
meta_review = step_data.get('meta_review', {})
|
static/js/graph_renderer.js
DELETED
@@ -1,99 +0,0 @@
|
|
1 |
-
// graph_renderer.js
|
2 |
-
document.addEventListener('DOMContentLoaded', function() {
|
3 |
-
console.log("graph_renderer.js loaded and DOMContentLoaded.");
|
4 |
-
|
5 |
-
// Find all graph containers
|
6 |
-
var graphContainers = document.querySelectorAll('.vis-graph-container');
|
7 |
-
|
8 |
-
graphContainers.forEach(function(container) {
|
9 |
-
var graphId = container.id;
|
10 |
-
var nodesJson = container.getAttribute('data-nodes');
|
11 |
-
var edgesJson = container.getAttribute('data-edges');
|
12 |
-
|
13 |
-
console.log(`Initializing graph for container: ${graphId}`);
|
14 |
-
console.log("Nodes JSON (from data-attribute):", nodesJson);
|
15 |
-
console.log("Edges JSON (from data-attribute):", edgesJson);
|
16 |
-
|
17 |
-
if (!nodesJson || !edgesJson) {
|
18 |
-
console.warn(`No graph data found for container ${graphId}. Skipping.`);
|
19 |
-
return;
|
20 |
-
}
|
21 |
-
|
22 |
-
try {
|
23 |
-
var nodesData = JSON.parse(nodesJson);
|
24 |
-
var edgesData = JSON.parse(edgesJson);
|
25 |
-
|
26 |
-
if (typeof vis === 'undefined' || !vis.DataSet) {
|
27 |
-
console.error("vis.js library not loaded. Cannot render graph.");
|
28 |
-
container.innerHTML = '<p style="padding: 20px; text-align: center; color: #666;">Error: vis.js library not loaded.</p>';
|
29 |
-
return;
|
30 |
-
}
|
31 |
-
|
32 |
-
var nodes = new vis.DataSet(nodesData);
|
33 |
-
var edges = new vis.DataSet(edgesData);
|
34 |
-
|
35 |
-
var data = {
|
36 |
-
nodes: nodes,
|
37 |
-
edges: edges
|
38 |
-
};
|
39 |
-
|
40 |
-
var options = {
|
41 |
-
nodes: {
|
42 |
-
shape: 'circle',
|
43 |
-
font: {
|
44 |
-
size: 14
|
45 |
-
},
|
46 |
-
color: {
|
47 |
-
background: '#97C2FC',
|
48 |
-
border: '#2B7CE9',
|
49 |
-
highlight: {
|
50 |
-
background: '#D2E5FF',
|
51 |
-
border: '#2B7CE9'
|
52 |
-
}
|
53 |
-
}
|
54 |
-
},
|
55 |
-
edges: {
|
56 |
-
font: {
|
57 |
-
size: 12,
|
58 |
-
align: 'middle'
|
59 |
-
},
|
60 |
-
color: {
|
61 |
-
color: '#848484'
|
62 |
-
},
|
63 |
-
smooth: {
|
64 |
-
enabled: true,
|
65 |
-
type: "dynamic"
|
66 |
-
}
|
67 |
-
},
|
68 |
-
physics: {
|
69 |
-
stabilization: true,
|
70 |
-
barnesHut: {
|
71 |
-
gravitationalConstant: -2000,
|
72 |
-
centralGravity: 0.3,
|
73 |
-
springLength: 150,
|
74 |
-
springConstant: 0.04
|
75 |
-
}
|
76 |
-
},
|
77 |
-
interaction: {
|
78 |
-
hover: true,
|
79 |
-
tooltipDelay: 200
|
80 |
-
}
|
81 |
-
};
|
82 |
-
|
83 |
-
console.log(`Creating vis.Network instance for ${graphId}...`);
|
84 |
-
var network = new vis.Network(container, data, options);
|
85 |
-
console.log(`vis.Network instance created successfully for ${graphId}.`);
|
86 |
-
|
87 |
-
network.on("click", function(params) {
|
88 |
-
if (params.nodes.length > 0) {
|
89 |
-
var nodeId = params.nodes[0];
|
90 |
-
console.log('Clicked node:', nodeId);
|
91 |
-
}
|
92 |
-
});
|
93 |
-
|
94 |
-
} catch (error) {
|
95 |
-
console.error(`Error creating network graph for ${graphId}:`, error);
|
96 |
-
container.innerHTML = '<p style="padding: 20px; text-align: center; color: #666;">Error loading graph visualization: ' + error.message + '</p>';
|
97 |
-
}
|
98 |
-
});
|
99 |
-
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|