Skip to content

Commit 41540ee

Browse files
committed
add a predefined example in Renard ui
1 parent 3563dc0 commit 41540ee

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

renard/ui.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
)
1515
from renard.pipeline.graph_extraction import CoOccurrencesGraphExtractor
1616
from renard.graph_utils import graph_with_names
17+
from renard.resources.novels import load_novel
1718
import matplotlib.pyplot as plt
1819
import matplotlib.colors
1920
import networkx as nx
@@ -195,6 +196,18 @@ def run_pipeline(
195196

196197
net = Network(width="100%")
197198
net.from_nx(G)
199+
# NOTE: layout found to have good default with "Pride and
200+
# Prejudice" with default parameters
201+
net.options.physics.use_barnes_hut(
202+
{
203+
"gravity": -22000,
204+
"central_gravity": 4.9,
205+
"spring_length": 95,
206+
"spring_strength": 0.04,
207+
"damping": 0.09,
208+
"overlap": 0,
209+
}
210+
)
198211
for u in net.nodes:
199212
u["font"] = {"size": max(12, 2 * G.degree[u["id"]])}
200213
net.show_buttons(filter_=["physics"])
@@ -325,16 +338,22 @@ def render_ge_kwargs(ge_step: str):
325338
# TODO: pipeline level parameter like 'lang'
326339
input_text = gr.State()
327340
input_text_radio = gr.Radio(
328-
choices=["Raw text", "Upload file"],
341+
choices=["Predefined Example", "Raw text", "Upload .txt file"],
329342
label="Input type",
330-
value="Raw text",
343+
value="Predefined Example",
331344
)
332345

333346
# NOTE: for some reason, tabs have an issue where the
334347
# component in the second tab is invisible.
335348
@gr.render(inputs=input_text_radio)
336349
def render_input_text(input_type: str):
337-
if input_type == "Upload file":
350+
if input_type == "Predefined Example":
351+
pp = load_novel("pride_and_prejudice")
352+
text_area = gr.TextArea(
353+
label="Pride and Prejudice", value=pp, interactive=False
354+
)
355+
input_text.value = pp
356+
elif input_type == "Upload file":
338357
upload_area = gr.File(
339358
label="Input text file", file_types=["text"]
340359
)

0 commit comments

Comments
 (0)