alexanderHSG commited on
Commit
981ecda
Β·
1 Parent(s): c93a4c0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +58 -10
app.py CHANGED
@@ -84,10 +84,15 @@ def slide_deck_storyline(storyline_prompt, nr_of_storypoints=5):
84
  )
85
  res = response.choices[0].message.content
86
  map = json.loads(res)
87
- pretty_list = "\n".join([f"⚑ {key}: {value}" for key, value in map.items()])
88
  storypoint_name_list = [map[key] for key in map]
89
  storypoint_name_nested = [storypoint_name_list]
90
- return map, storypoint_name_nested, pretty_list
 
 
 
 
 
91
 
92
  #we need this function to turn the non iterable nested list that is gr.List into a simple list.
93
  def iterator_for_gr(nested_list, i):
@@ -114,8 +119,9 @@ client = OpenAI(api_key = os.getenv("OPENAI_API_KEY"))
114
 
115
 
116
  def get_embedding_inputstorypoints(storyline_output_storypoint_name_list, model="text-embedding-3-large"):
117
- #input has 5 colums, transform to 1 column
118
- storyline_output_storypoint_name_list = [item for sublist in storyline_output_storypoint_name_list for item in sublist]
 
119
 
120
  # transform storyline_output_storypoint_name_list to pandas dataframe
121
  input_storypoints = pd.DataFrame(storyline_output_storypoint_name_list, columns=['description'])
@@ -225,6 +231,7 @@ def construct_hmtl(highest_similarities, nodes_to_show=["SLIDE_DECK", "SLIDE", "
225
 
226
 
227
  graphVisualHTML = f"""
 
228
  <head>
229
  <title>DataViz</title>
230
  <style type="text/css">
@@ -252,9 +259,19 @@ def construct_hmtl(highest_similarities, nodes_to_show=["SLIDE_DECK", "SLIDE", "
252
  </style>
253
  </head>
254
  <body>
 
 
 
255
  <div id="viz">
256
  <p id="queryCypher">{query}</p>
257
  </div>
 
 
 
 
 
 
 
258
  </body>
259
  """
260
  return graphVisualHTML
@@ -413,6 +430,21 @@ async () => {
413
  try {
414
  viz = new NeoVis.default(config);
415
  viz.render();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
416
 
417
  } catch (error) {
418
  console.error('Error rendering NeoVis:', error);
@@ -473,6 +505,22 @@ console.log("Observer is set to monitor changes in the document body.");
473
  </script>
474
  """
475
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
476
 
477
  ## GRADIO UI LAYOUT & FUNCTIONALITY
478
  ## ---------------------------------------------------------------------------------------------------------------------
@@ -481,7 +529,7 @@ highest_similarities_gradio_list = gr.List(type="array", interactive=False, visi
481
  nodeSelector = gr.Dropdown(label="Filter nodes", choices=["SLIDE_DECK", "SLIDE", "STORYPOINT"], value=["SLIDE_DECK", "SLIDE", "STORYPOINT"], multiselect=True, scale=1)
482
  filterBTN = gr.Button("Apply Filter")
483
 
484
- with gr.Blocks(title='Slide Inspo', theme='Soft', js=scripts, head = js_click).queue(default_concurrency_limit=1) as demo:
485
 
486
  highest_similarities_gradio_list.render()
487
  with gr.Row():
@@ -495,13 +543,13 @@ with gr.Blocks(title='Slide Inspo', theme='Soft', js=scripts, head = js_click).q
495
  label="How many storypoints?",
496
  scale =1)
497
  storyline_output_JSON = gr.JSON(visible=False)
498
- storyline_output_storypoint_name_list = gr.List(visible=False, type="array", interactive=False, row_count = [1,"fixed"], label="Edit you Storypoints: πŸ“", scale=1)
499
  btn = gr.Button("Build Storyline πŸ¦„")
500
 
501
  with gr.Column(scale=1):
502
  gr.Markdown("# 2. Storyline: πŸ¦„")
503
-
504
- storyline_output_pretty = gr.Textbox(label="Your Storyline:", lines=13, scale=3, interactive=False)
505
  submit_button = gr.Button("⚑ Find Slides ⚑", elem_id="visGraph")
506
  submit_button.click(fn= coordinate_simcalculation, inputs=[storyline_output_storypoint_name_list], outputs=[graphVisual, highest_similarities_gradio_list]).then(js = js_click)
507
 
@@ -509,11 +557,11 @@ with gr.Blocks(title='Slide Inspo', theme='Soft', js=scripts, head = js_click).q
509
 
510
  btn.click(slide_deck_storyline,
511
  inputs = [storyline_prompt, nr_storypoints_to_build],
512
- outputs = [storyline_output_JSON, storyline_output_storypoint_name_list, storyline_output_pretty])
513
 
514
  storyline_prompt.submit(slide_deck_storyline,
515
  inputs = [storyline_prompt, nr_storypoints_to_build],
516
- outputs = [storyline_output_JSON, storyline_output_storypoint_name_list, storyline_output_pretty])
517
 
518
 
519
  with gr.Row():
 
84
  )
85
  res = response.choices[0].message.content
86
  map = json.loads(res)
87
+ #pretty_list = "\n".join([f"⚑ {key}: {value}" for key, value in map.items()])
88
  storypoint_name_list = [map[key] for key in map]
89
  storypoint_name_nested = [storypoint_name_list]
90
+ storypoint_name_nested = list(zip(*storypoint_name_nested))
91
+ #add one column to the list with the name of the storypoint
92
+
93
+ storypoint_name_nested = [[f"SP {i}", item] for i, item in enumerate(storypoint_name_nested, 1)]
94
+
95
+ return map, storypoint_name_nested
96
 
97
  #we need this function to turn the non iterable nested list that is gr.List into a simple list.
98
  def iterator_for_gr(nested_list, i):
 
119
 
120
 
121
  def get_embedding_inputstorypoints(storyline_output_storypoint_name_list, model="text-embedding-3-large"):
122
+
123
+ #input has 2 colums, pick the second column
124
+ storyline_output_storypoint_name_list = [[item[1]] if type(item[1]) is not list else item[1] for item in storyline_output_storypoint_name_list if len(item) > 1]
125
 
126
  # transform storyline_output_storypoint_name_list to pandas dataframe
127
  input_storypoints = pd.DataFrame(storyline_output_storypoint_name_list, columns=['description'])
 
231
 
232
 
233
  graphVisualHTML = f"""
234
+
235
  <head>
236
  <title>DataViz</title>
237
  <style type="text/css">
 
259
  </style>
260
  </head>
261
  <body>
262
+
263
+
264
+
265
  <div id="viz">
266
  <p id="queryCypher">{query}</p>
267
  </div>
268
+
269
+ <div class="custom-menu" style="display: none; position: absolute; z-index: 1000; background: white; border: 1px solid #ccc; padding: 5px; box-shadow: 2px 2px 5px #888;">
270
+ <ul>
271
+ <li onclick="alert('Action 1')">Action 1</li>
272
+ <li onclick="alert('Action 2')">Action 2</li>
273
+ </ul>
274
+ </div>
275
  </body>
276
  """
277
  return graphVisualHTML
 
430
  try {
431
  viz = new NeoVis.default(config);
432
  viz.render();
433
+ viz.registerOnEvent("completed", () => {
434
+ viz.network.on("oncontext", function (params) {
435
+ params.event.preventDefault();
436
+ const customMenu = document.querySelector('.custom-menu');
437
+
438
+ if (customMenu) {
439
+ console.log("Displaying custom menu.");
440
+ const containerRect = document.getElementById('viz').getBoundingClientRect();
441
+ customMenu.style.display = 'block';
442
+ customMenu.style.top = `${params.event.pageY - containerRect.top + window.scrollY}px`;
443
+ customMenu.style.left = `${params.event.pageX - containerRect.left + window.scrollX}px`;
444
+ }
445
+ });
446
+ });
447
+
448
 
449
  } catch (error) {
450
  console.error('Error rendering NeoVis:', error);
 
505
  </script>
506
  """
507
 
508
+ css = """
509
+ #SPList {
510
+ font-family: 'Arial', sans-serif;
511
+ background-color: #f8f9fa;
512
+ color: #333;
513
+ background-color: #ffffff;
514
+ color: #333;
515
+ border: 1px solid #ccc;
516
+ border-radius: 8px;
517
+ padding: 10px;
518
+ margin: 5px;
519
+ }
520
+ #SPList .gr-array-container {
521
+ gap: 10px;
522
+ }"""
523
+
524
 
525
  ## GRADIO UI LAYOUT & FUNCTIONALITY
526
  ## ---------------------------------------------------------------------------------------------------------------------
 
529
  nodeSelector = gr.Dropdown(label="Filter nodes", choices=["SLIDE_DECK", "SLIDE", "STORYPOINT"], value=["SLIDE_DECK", "SLIDE", "STORYPOINT"], multiselect=True, scale=1)
530
  filterBTN = gr.Button("Apply Filter")
531
 
532
+ with gr.Blocks(title='Slide Inspo', js=scripts, head = js_click, theme = gr.themes.Monochrome(), css= css).queue(default_concurrency_limit=1) as demo:
533
 
534
  highest_similarities_gradio_list.render()
535
  with gr.Row():
 
543
  label="How many storypoints?",
544
  scale =1)
545
  storyline_output_JSON = gr.JSON(visible=False)
546
+
547
  btn = gr.Button("Build Storyline πŸ¦„")
548
 
549
  with gr.Column(scale=1):
550
  gr.Markdown("# 2. Storyline: πŸ¦„")
551
+ storyline_output_storypoint_name_list = gr.List(visible=True, type="array", interactive=True, label="Adapt and add Storypoints, if needed: πŸ“", scale=1, wrap=True, col_count=[2, "fixed"], elem_id="SPList", headers=["#SP", "Description"])
552
+ #storyline_output_pretty = gr.Textbox(label="Your Storyline:", lines=13, scale=3, interactive=False)
553
  submit_button = gr.Button("⚑ Find Slides ⚑", elem_id="visGraph")
554
  submit_button.click(fn= coordinate_simcalculation, inputs=[storyline_output_storypoint_name_list], outputs=[graphVisual, highest_similarities_gradio_list]).then(js = js_click)
555
 
 
557
 
558
  btn.click(slide_deck_storyline,
559
  inputs = [storyline_prompt, nr_storypoints_to_build],
560
+ outputs = [storyline_output_JSON, storyline_output_storypoint_name_list])
561
 
562
  storyline_prompt.submit(slide_deck_storyline,
563
  inputs = [storyline_prompt, nr_storypoints_to_build],
564
+ outputs = [storyline_output_JSON, storyline_output_storypoint_name_list])
565
 
566
 
567
  with gr.Row():