Spaces:
Sleeping
Sleeping
add adjacency matrix
Browse files
app.py
CHANGED
@@ -130,9 +130,10 @@ def plot_graph_sentence(sentence, graph_type="both"):
|
|
130 |
elif graph_type == "both":
|
131 |
graphs = construct_both_graph(docs)
|
132 |
g = to_jraph(graphs[0])
|
|
|
133 |
nx_graph = convert_jraph_to_networkx_graph(g)
|
134 |
pos = half_circle_layout(len(graphs[0]["nodes"]))
|
135 |
-
plot = plt.figure(figsize=(
|
136 |
nx.draw(nx_graph, pos=pos,
|
137 |
labels={i: e for i,e in enumerate(graphs[0]["nodes"])},
|
138 |
with_labels = True, edge_color="blue",
|
@@ -142,17 +143,33 @@ def plot_graph_sentence(sentence, graph_type="both"):
|
|
142 |
nx_graph, pos=pos,
|
143 |
edge_labels=graphs[0]["edge_labels"],
|
144 |
font_color='red'
|
145 |
-
)
|
146 |
-
|
|
|
|
|
147 |
|
148 |
def get_list_sentences(id):
|
|
|
149 |
return gr.update(choices = dataset["train"][id]["transcript"].split("."))
|
150 |
|
151 |
with gr.Blocks() as demo:
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
157 |
|
158 |
demo.launch()
|
|
|
130 |
elif graph_type == "both":
|
131 |
graphs = construct_both_graph(docs)
|
132 |
g = to_jraph(graphs[0])
|
133 |
+
adj_mat = get_adjacency_matrix(g)
|
134 |
nx_graph = convert_jraph_to_networkx_graph(g)
|
135 |
pos = half_circle_layout(len(graphs[0]["nodes"]))
|
136 |
+
plot = plt.figure(figsize=(12, 6))
|
137 |
nx.draw(nx_graph, pos=pos,
|
138 |
labels={i: e for i,e in enumerate(graphs[0]["nodes"])},
|
139 |
with_labels = True, edge_color="blue",
|
|
|
143 |
nx_graph, pos=pos,
|
144 |
edge_labels=graphs[0]["edge_labels"],
|
145 |
font_color='red'
|
146 |
+
)
|
147 |
+
adj_mat_plot, ax = plt.subplots(figsize=(6, 6))
|
148 |
+
ax.matshow(adj_mat)
|
149 |
+
return [gr.update(value=plot), gr.update(value=adj_mat_plot)]
|
150 |
|
151 |
def get_list_sentences(id):
|
152 |
+
id = int(min(id, len(dataset["train"]) - 1))
|
153 |
return gr.update(choices = dataset["train"][id]["transcript"].split("."))
|
154 |
|
155 |
with gr.Blocks() as demo:
|
156 |
+
with gr.Tab("From transcript"):
|
157 |
+
with gr.Row():
|
158 |
+
with gr.Column():
|
159 |
+
id = gr.Number(label="Transcript")
|
160 |
+
with gr.Column(scale=3):
|
161 |
+
sentence_transcript = gr.Dropdown(label="Sentence", choices = dataset["train"][0]["transcript"].split("."), interactive = True)
|
162 |
+
with gr.Tab("Type sentence"):
|
163 |
+
with gr.Row():
|
164 |
+
sentence_typed = gr.Textbox(label="Sentence", interactive = True)
|
165 |
+
with gr.Row():
|
166 |
+
with gr.Column(scale=2):
|
167 |
+
plot_graph = gr.Plot(label="Word graph")
|
168 |
+
with gr.Column():
|
169 |
+
plot_adj = gr.Plot(label="Word graph adjacency matrix")
|
170 |
+
|
171 |
+
id.change(get_list_sentences, id, sentence)
|
172 |
+
sentence_transcript.change(plot_graph_sentence, sentence_transcript, [plot_graph, plot_adj])
|
173 |
+
sentence_typed.change(plot_graph_sentence, sentence_typed, [plot_graph, plot_adj])
|
174 |
|
175 |
demo.launch()
|