Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,7 +2,6 @@ import streamlit as st
|
|
2 |
import matplotlib.pyplot as plt
|
3 |
import networkx as nx
|
4 |
import bz2
|
5 |
-
import numpy as np
|
6 |
|
7 |
# Sidebar for selecting an option
|
8 |
sidebar_option = st.sidebar.radio("Select an option",
|
@@ -12,13 +11,19 @@ sidebar_option = st.sidebar.radio("Select an option",
|
|
12 |
"Drawing: Chess Masters"])
|
13 |
|
14 |
# Helper function to draw and display graph
|
15 |
-
def draw_graph(G, pos=None, title="Graph Visualization"):
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
plt.figure(figsize=(12, 12))
|
17 |
nx.draw_networkx_edges(G, pos, alpha=0.3, width=edgewidth, edge_color="m")
|
18 |
nx.draw_networkx_nodes(G, pos, node_size=nodesize, node_color="#210070", alpha=0.9)
|
19 |
label_options = {"ec": "k", "fc": "white", "alpha": 0.7}
|
20 |
nx.draw_networkx_labels(G, pos, font_size=14, bbox=label_options)
|
21 |
-
|
22 |
# Title/legend
|
23 |
font = {"fontname": "Helvetica", "color": "k", "fontweight": "bold", "fontsize": 14}
|
24 |
ax = plt.gca()
|
@@ -128,7 +133,7 @@ def display_chess_masters_graph():
|
|
128 |
pos["Smyslov, Vassily V"] += (0.05, -0.03)
|
129 |
|
130 |
# Draw the graph
|
131 |
-
draw_graph(H, pos, title="World Chess Championship Games: 1886 - 1985")
|
132 |
|
133 |
elif option == "Create your own":
|
134 |
uploaded_file = st.file_uploader("Upload your own PGN file", type="pgn")
|
@@ -149,7 +154,7 @@ def display_chess_masters_graph():
|
|
149 |
wins[v] += 1.0
|
150 |
nodesize = [wins[v] * 50 for v in H_custom]
|
151 |
pos_custom = nx.kamada_kawai_layout(H_custom)
|
152 |
-
draw_graph(H_custom, pos_custom, title="Custom Chess Game Graph")
|
153 |
|
154 |
# Display other sections
|
155 |
def display_basic_properties():
|
|
|
2 |
import matplotlib.pyplot as plt
|
3 |
import networkx as nx
|
4 |
import bz2
|
|
|
5 |
|
6 |
# Sidebar for selecting an option
|
7 |
sidebar_option = st.sidebar.radio("Select an option",
|
|
|
11 |
"Drawing: Chess Masters"])
|
12 |
|
13 |
# Helper function to draw and display graph
|
14 |
+
def draw_graph(G, pos=None, title="Graph Visualization", edgewidth=None, nodesize=None):
|
15 |
+
if edgewidth is None:
|
16 |
+
edgewidth = [1] * len(G.edges()) # Default edge width if not provided
|
17 |
+
|
18 |
+
if nodesize is None:
|
19 |
+
nodesize = [300] * len(G.nodes()) # Default node size if not provided
|
20 |
+
|
21 |
plt.figure(figsize=(12, 12))
|
22 |
nx.draw_networkx_edges(G, pos, alpha=0.3, width=edgewidth, edge_color="m")
|
23 |
nx.draw_networkx_nodes(G, pos, node_size=nodesize, node_color="#210070", alpha=0.9)
|
24 |
label_options = {"ec": "k", "fc": "white", "alpha": 0.7}
|
25 |
nx.draw_networkx_labels(G, pos, font_size=14, bbox=label_options)
|
26 |
+
|
27 |
# Title/legend
|
28 |
font = {"fontname": "Helvetica", "color": "k", "fontweight": "bold", "fontsize": 14}
|
29 |
ax = plt.gca()
|
|
|
133 |
pos["Smyslov, Vassily V"] += (0.05, -0.03)
|
134 |
|
135 |
# Draw the graph
|
136 |
+
draw_graph(H, pos, title="World Chess Championship Games: 1886 - 1985", edgewidth=edgewidth, nodesize=nodesize)
|
137 |
|
138 |
elif option == "Create your own":
|
139 |
uploaded_file = st.file_uploader("Upload your own PGN file", type="pgn")
|
|
|
154 |
wins[v] += 1.0
|
155 |
nodesize = [wins[v] * 50 for v in H_custom]
|
156 |
pos_custom = nx.kamada_kawai_layout(H_custom)
|
157 |
+
draw_graph(H_custom, pos_custom, title="Custom Chess Game Graph", edgewidth=edgewidth, nodesize=nodesize)
|
158 |
|
159 |
# Display other sections
|
160 |
def display_basic_properties():
|