Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -104,12 +104,13 @@ class Visualizer:
|
|
| 104 |
if d <= thresh and (neighbor == entity2 or neighbor == entity1) and len(neighbors) < num_neighbors + 1:
|
| 105 |
neighbors.add(entity1)
|
| 106 |
neighbors.add(entity2)
|
| 107 |
-
spring_tension = (thresh - d) *
|
| 108 |
G.add_edge(entity1, entity2, weight=spring_tension)
|
| 109 |
neighbors.remove(neighbor)
|
|
|
|
| 110 |
for entity1, entity2, d in tqdm(normalized_distances):
|
| 111 |
if entity2 in neighbors and entity1 in neighbors:
|
| 112 |
-
spring_tension = (
|
| 113 |
G.add_edge(entity1, entity2, weight=spring_tension)
|
| 114 |
|
| 115 |
pos = nx.spring_layout(G, weight="weight", iterations=200, threshold=1e-6) # Positions for all nodes
|
|
@@ -117,11 +118,12 @@ class Visualizer:
|
|
| 117 |
nx.draw_networkx_nodes(G, pos, node_size=1, alpha=0.01)
|
| 118 |
edges_connected_to_specific_node = [(u, v) for u, v in G.edges() if u == neighbor or v == neighbor]
|
| 119 |
nx.draw_networkx_edges(G, pos, edgelist=edges_connected_to_specific_node, edge_color='orange', alpha=0.4, width=3)
|
| 120 |
-
|
| 121 |
-
|
|
|
|
| 122 |
for u, v, d in edges:
|
| 123 |
if u == neighbor or v == neighbor:
|
| 124 |
-
nx.draw_networkx_edge_labels(G, pos, edge_labels={(u, v): round((thresh - (d['weight'] /
|
| 125 |
nx.draw_networkx_labels(G, pos, font_size=14, font_family='sans-serif', font_color='green')
|
| 126 |
nx.draw_networkx_labels(G, pos, labels={neighbor: neighbor}, font_size=14, font_family='sans-serif', font_color='red')
|
| 127 |
plt.title(f'Graph of {distance_type}')
|
|
@@ -152,6 +154,5 @@ if __name__ == '__main__':
|
|
| 152 |
description="<br><br> This demo allows you to find the nearest neighbors of a language from the ISO 639-3 list according to several distance measurement functions. "
|
| 153 |
"For more information, check out our paper: https://arxiv.org/abs/2406.06403 and our text-to-speech tool, in which we make use of "
|
| 154 |
"this technique: https://github.com/DigitalPhonetics/IMS-Toucan <br><br>",
|
| 155 |
-
fill_width=True,
|
| 156 |
allow_flagging="never")
|
| 157 |
iface.launch()
|
|
|
|
| 104 |
if d <= thresh and (neighbor == entity2 or neighbor == entity1) and len(neighbors) < num_neighbors + 1:
|
| 105 |
neighbors.add(entity1)
|
| 106 |
neighbors.add(entity2)
|
| 107 |
+
spring_tension = ((thresh + 0.1) - d) * 100 # for vis purposes
|
| 108 |
G.add_edge(entity1, entity2, weight=spring_tension)
|
| 109 |
neighbors.remove(neighbor)
|
| 110 |
+
thresh_for_neighbors = max([x for _, _, x in normalized_distances])
|
| 111 |
for entity1, entity2, d in tqdm(normalized_distances):
|
| 112 |
if entity2 in neighbors and entity1 in neighbors:
|
| 113 |
+
spring_tension = (thresh_for_neighbors + 0.1) - d
|
| 114 |
G.add_edge(entity1, entity2, weight=spring_tension)
|
| 115 |
|
| 116 |
pos = nx.spring_layout(G, weight="weight", iterations=200, threshold=1e-6) # Positions for all nodes
|
|
|
|
| 118 |
nx.draw_networkx_nodes(G, pos, node_size=1, alpha=0.01)
|
| 119 |
edges_connected_to_specific_node = [(u, v) for u, v in G.edges() if u == neighbor or v == neighbor]
|
| 120 |
nx.draw_networkx_edges(G, pos, edgelist=edges_connected_to_specific_node, edge_color='orange', alpha=0.4, width=3)
|
| 121 |
+
if num_neighbors < 6:
|
| 122 |
+
edges_not_connected_to_specific_node = [(u, v) for u, v in G.edges() if u != neighbor and v != neighbor]
|
| 123 |
+
nx.draw_networkx_edges(G, pos, edgelist=edges_not_connected_to_specific_node, edge_color='gray', alpha=0.05, width=1)
|
| 124 |
for u, v, d in edges:
|
| 125 |
if u == neighbor or v == neighbor:
|
| 126 |
+
nx.draw_networkx_edge_labels(G, pos, edge_labels={(u, v): round(((thresh + 0.1) - (d['weight'] / 100)) * 100, 2)}, font_color="red", alpha=0.4) # reverse modifications
|
| 127 |
nx.draw_networkx_labels(G, pos, font_size=14, font_family='sans-serif', font_color='green')
|
| 128 |
nx.draw_networkx_labels(G, pos, labels={neighbor: neighbor}, font_size=14, font_family='sans-serif', font_color='red')
|
| 129 |
plt.title(f'Graph of {distance_type}')
|
|
|
|
| 154 |
description="<br><br> This demo allows you to find the nearest neighbors of a language from the ISO 639-3 list according to several distance measurement functions. "
|
| 155 |
"For more information, check out our paper: https://arxiv.org/abs/2406.06403 and our text-to-speech tool, in which we make use of "
|
| 156 |
"this technique: https://github.com/DigitalPhonetics/IMS-Toucan <br><br>",
|
|
|
|
| 157 |
allow_flagging="never")
|
| 158 |
iface.launch()
|