Spaces:
Sleeping
Sleeping
umm-maybe commited on
Commit ·
1baddb8
1
Parent(s): 1055f79
Tour diagram
Browse files
app.py
CHANGED
|
@@ -7,13 +7,15 @@ from transformers import pipeline
|
|
| 7 |
tourModel = pipeline(model="manhan/GPT-Tour")
|
| 8 |
|
| 9 |
def vizTour(activityList):
|
| 10 |
-
net = Network(directed=True)
|
| 11 |
net.add_node(activityList[0])
|
|
|
|
| 12 |
for activity in activityList[1:]:
|
| 13 |
if activity not in net.get_nodes():
|
| 14 |
net.add_node(activity)
|
| 15 |
-
net.add_edge(
|
| 16 |
-
|
|
|
|
| 17 |
return True
|
| 18 |
|
| 19 |
def getTour(income,size,years,sex,edu,wrk):
|
|
|
|
| 7 |
tourModel = pipeline(model="manhan/GPT-Tour")
|
| 8 |
|
| 9 |
def vizTour(activityList):
|
| 10 |
+
net = Network(directed=True,notebook=False)
|
| 11 |
net.add_node(activityList[0])
|
| 12 |
+
lastActivity = activityList[0]
|
| 13 |
for activity in activityList[1:]:
|
| 14 |
if activity not in net.get_nodes():
|
| 15 |
net.add_node(activity)
|
| 16 |
+
net.add_edge(lastActivity, activity)
|
| 17 |
+
lastActivity = activity
|
| 18 |
+
net.save_graph('tour.html')
|
| 19 |
return True
|
| 20 |
|
| 21 |
def getTour(income,size,years,sex,edu,wrk):
|
tour.html
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<html>
|
| 2 |
+
<head>
|
| 3 |
+
<meta charset="utf-8">
|
| 4 |
+
|
| 5 |
+
<script src="lib/bindings/utils.js"></script>
|
| 6 |
+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/vis-network/9.1.2/dist/dist/vis-network.min.css" integrity="sha512-WgxfT5LWjfszlPHXRmBWHkV2eceiWTOBvrKCNbdgDYTHrT2AeLCGbF4sZlZw3UMN3WtL0tGUoIAKsu8mllg/XA==" crossorigin="anonymous" referrerpolicy="no-referrer" />
|
| 7 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/vis-network/9.1.2/dist/vis-network.min.js" integrity="sha512-LnvoEWDFrqGHlHmDD2101OrLcbsfkrzoSpvtSQtxK3RMnRV0eOkhhBN2dXHKRrUU8p2DGRTk35n4O8nWSVe1mQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
<center>
|
| 11 |
+
<h1></h1>
|
| 12 |
+
</center>
|
| 13 |
+
|
| 14 |
+
<!-- <link rel="stylesheet" href="../node_modules/vis/dist/vis.min.css" type="text/css" />
|
| 15 |
+
<script type="text/javascript" src="../node_modules/vis/dist/vis.js"> </script>-->
|
| 16 |
+
<link
|
| 17 |
+
href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta3/dist/css/bootstrap.min.css"
|
| 18 |
+
rel="stylesheet"
|
| 19 |
+
integrity="sha384-eOJMYsd53ii+scO/bJGFsiCZc+5NDVN2yr8+0RDqr0Ql0h+rP48ckxlpbzKgwra6"
|
| 20 |
+
crossorigin="anonymous"
|
| 21 |
+
/>
|
| 22 |
+
<script
|
| 23 |
+
src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta3/dist/js/bootstrap.bundle.min.js"
|
| 24 |
+
integrity="sha384-JEW9xMcG8R+pH31jmWH6WWP0WintQrMb4s7ZOdauHnUtxwoG2vI5DkLtS3qm9Ekf"
|
| 25 |
+
crossorigin="anonymous"
|
| 26 |
+
></script>
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
<center>
|
| 30 |
+
<h1></h1>
|
| 31 |
+
</center>
|
| 32 |
+
<style type="text/css">
|
| 33 |
+
|
| 34 |
+
#mynetwork {
|
| 35 |
+
width: 100%;
|
| 36 |
+
height: 600px;
|
| 37 |
+
background-color: #ffffff;
|
| 38 |
+
border: 1px solid lightgray;
|
| 39 |
+
position: relative;
|
| 40 |
+
float: left;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
</style>
|
| 49 |
+
</head>
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
<body>
|
| 53 |
+
<div class="card" style="width: 100%">
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
<div id="mynetwork" class="card-body"></div>
|
| 57 |
+
</div>
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
<script type="text/javascript">
|
| 63 |
+
|
| 64 |
+
// initialize global variables.
|
| 65 |
+
var edges;
|
| 66 |
+
var nodes;
|
| 67 |
+
var allNodes;
|
| 68 |
+
var allEdges;
|
| 69 |
+
var nodeColors;
|
| 70 |
+
var originalNodes;
|
| 71 |
+
var network;
|
| 72 |
+
var container;
|
| 73 |
+
var options, data;
|
| 74 |
+
var filter = {
|
| 75 |
+
item : '',
|
| 76 |
+
property : '',
|
| 77 |
+
value : []
|
| 78 |
+
};
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
// This method is responsible for drawing the graph, returns the drawn network
|
| 85 |
+
function drawGraph() {
|
| 86 |
+
var container = document.getElementById('mynetwork');
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
// parsing and collecting nodes and edges from the python
|
| 91 |
+
nodes = new vis.DataSet([{"color": "#97c2fc", "id": "Home", "label": "Home", "shape": "dot"}, {"color": "#97c2fc", "id": "Driver", "label": "Driver", "shape": "dot"}, {"color": "#97c2fc", "id": "Work", "label": "Work", "shape": "dot"}, {"color": "#97c2fc", "id": "Social", "label": "Social", "shape": "dot"}, {"color": "#97c2fc", "id": "Shopping", "label": "Shopping", "shape": "dot"}]);
|
| 92 |
+
edges = new vis.DataSet([{"arrows": "to", "from": "Home", "to": "Driver"}, {"arrows": "to", "from": "Driver", "to": "Work"}, {"arrows": "to", "from": "Work", "to": "Social"}, {"arrows": "to", "from": "Social", "to": "Shopping"}, {"arrows": "to", "from": "Shopping", "to": "Home"}]);
|
| 93 |
+
|
| 94 |
+
nodeColors = {};
|
| 95 |
+
allNodes = nodes.get({ returnType: "Object" });
|
| 96 |
+
for (nodeId in allNodes) {
|
| 97 |
+
nodeColors[nodeId] = allNodes[nodeId].color;
|
| 98 |
+
}
|
| 99 |
+
allEdges = edges.get({ returnType: "Object" });
|
| 100 |
+
// adding nodes and edges to the graph
|
| 101 |
+
data = {nodes: nodes, edges: edges};
|
| 102 |
+
|
| 103 |
+
var options = {
|
| 104 |
+
"configure": {
|
| 105 |
+
"enabled": false
|
| 106 |
+
},
|
| 107 |
+
"edges": {
|
| 108 |
+
"color": {
|
| 109 |
+
"inherit": true
|
| 110 |
+
},
|
| 111 |
+
"smooth": {
|
| 112 |
+
"enabled": true,
|
| 113 |
+
"type": "dynamic"
|
| 114 |
+
}
|
| 115 |
+
},
|
| 116 |
+
"interaction": {
|
| 117 |
+
"dragNodes": true,
|
| 118 |
+
"hideEdgesOnDrag": false,
|
| 119 |
+
"hideNodesOnDrag": false
|
| 120 |
+
},
|
| 121 |
+
"physics": {
|
| 122 |
+
"enabled": true,
|
| 123 |
+
"stabilization": {
|
| 124 |
+
"enabled": true,
|
| 125 |
+
"fit": true,
|
| 126 |
+
"iterations": 1000,
|
| 127 |
+
"onlyDynamicEdges": false,
|
| 128 |
+
"updateInterval": 50
|
| 129 |
+
}
|
| 130 |
+
}
|
| 131 |
+
};
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
|
| 136 |
+
|
| 137 |
+
|
| 138 |
+
network = new vis.Network(container, data, options);
|
| 139 |
+
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
|
| 143 |
+
|
| 144 |
+
|
| 145 |
+
|
| 146 |
+
|
| 147 |
+
|
| 148 |
+
|
| 149 |
+
return network;
|
| 150 |
+
|
| 151 |
+
}
|
| 152 |
+
drawGraph();
|
| 153 |
+
</script>
|
| 154 |
+
</body>
|
| 155 |
+
</html>
|