Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -36,6 +36,27 @@ def generate_colors(n):
|
|
| 36 |
HSV_tuples = [(x * 1.0 / n, 0.5, 0.9) for x in range(n)]
|
| 37 |
return ['#%02x%02x%02x' % tuple(int(x*255) for x in colorsys.hsv_to_rgb(*hsv)) for hsv in HSV_tuples]
|
| 38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
def create_custom_network_html(G):
|
| 40 |
nodes = [{"id": n, "label": n} for n in G.nodes()]
|
| 41 |
edges = [{"from": u, "to": v} for u, v in G.edges()]
|
|
@@ -62,6 +83,7 @@ def create_custom_network_html(G):
|
|
| 62 |
"""
|
| 63 |
return html_content
|
| 64 |
|
|
|
|
| 65 |
def visualize_network(G):
|
| 66 |
if G is None or G.number_of_nodes() == 0:
|
| 67 |
st.error("Graph is empty or not properly initialized.")
|
|
|
|
| 36 |
HSV_tuples = [(x * 1.0 / n, 0.5, 0.9) for x in range(n)]
|
| 37 |
return ['#%02x%02x%02x' % tuple(int(x*255) for x in colorsys.hsv_to_rgb(*hsv)) for hsv in HSV_tuples]
|
| 38 |
|
| 39 |
+
# 네트워크 그래프 생성 함수
|
| 40 |
+
def create_network_graph(topic_results, num_words=30):
|
| 41 |
+
G = nx.Graph()
|
| 42 |
+
colors = generate_colors(len(topic_results))
|
| 43 |
+
|
| 44 |
+
for idx, topic in enumerate(topic_results):
|
| 45 |
+
words = topic['lda_words'][:num_words]
|
| 46 |
+
color = colors[idx]
|
| 47 |
+
|
| 48 |
+
for word in words:
|
| 49 |
+
if not G.has_node(word):
|
| 50 |
+
G.add_node(word, color=color, size=10)
|
| 51 |
+
|
| 52 |
+
for i in range(len(words)):
|
| 53 |
+
for j in range(i+1, len(words)):
|
| 54 |
+
if not G.has_edge(words[i], words[j]):
|
| 55 |
+
G.add_edge(words[i], words[j], weight=1)
|
| 56 |
+
|
| 57 |
+
return G
|
| 58 |
+
|
| 59 |
+
# HTML 네트워크 그래프 생성 함수
|
| 60 |
def create_custom_network_html(G):
|
| 61 |
nodes = [{"id": n, "label": n} for n in G.nodes()]
|
| 62 |
edges = [{"from": u, "to": v} for u, v in G.edges()]
|
|
|
|
| 83 |
"""
|
| 84 |
return html_content
|
| 85 |
|
| 86 |
+
|
| 87 |
def visualize_network(G):
|
| 88 |
if G is None or G.number_of_nodes() == 0:
|
| 89 |
st.error("Graph is empty or not properly initialized.")
|