ale979 commited on
Commit
bf87946
·
verified ·
1 Parent(s): e04fd67

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -23
app.py CHANGED
@@ -27,7 +27,6 @@ driver = GraphDatabase.driver(neo4j_url, auth=AUTH)
27
 
28
 
29
 
30
- user_id = None
31
 
32
 
33
 
@@ -267,9 +266,8 @@ def coordinate_simcalculation(storyline_output_storypoint_name_list):
267
 
268
  return HTMLoutput, highest_similarities, query
269
 
270
- def track_user_interaction(user_input, action):
271
- global user_id
272
-
273
 
274
  user_id = str(user_id)
275
 
@@ -319,16 +317,16 @@ VALUES (%s, %s, %s, %s)
319
 
320
  def profile_user(request: gr.Request):
321
 
322
- global user_id
323
  query_params = dict(request.query_params)
324
  try:
325
  username = dict(request.query_params)["username"]
326
  user_id = username
327
- track_user_interaction("", "login")
328
- if dict(request.query_params)["password"] == os.getenv("APP_PASSWORD"):
329
- return user_id
330
- else:
331
- return None
332
  except:
333
  return None
334
 
@@ -762,26 +760,26 @@ Outcome: Fellow consultant will develop a comprehensive understanding of AI's po
762
  #storyline_output_pretty = gr.Textbox(label="Your Storyline:", lines=13, scale=3, interactive=False)
763
  submit_button = gr.Button("⚡ Find Slides ⚡", elem_id="visGraph")
764
  submit_button.click(fn= coordinate_simcalculation, inputs=[storyline_output_storypoint_name_list], outputs=[graphVisual, highest_similarities_gradio_list, queryPlaceholder]
765
- ).then(track_user_interaction, inputs=[storyline_output_storypoint_name_list, gr.Textbox("findslidesStorypoints", visible=False)]
766
  ).then(get_neo4j_response, inputs=[queryPlaceholder], outputs=[responsePlaceholder]
767
- ).then(track_user_interaction, inputs=[queryPlaceholder, gr.Textbox("findslidesQuery", visible=False)]
768
- ).then(track_user_interaction, inputs=[responsePlaceholder, gr.Textbox("findslidesNeo4jResponse", visible=False)]).then(js = js_call_draw)
769
 
770
 
771
 
772
  btn_buildstoryline.click(slide_deck_storyline,
773
  inputs = [storyline_prompt, nr_storypoints_to_build],
774
  outputs = [storyline_output_JSON, storyline_output_storypoint_name_list]
775
- ).then(track_user_interaction, inputs=[storyline_prompt, gr.Textbox("buildstorylinePrompt", visible=False)]
776
- ).then(track_user_interaction, inputs=[storyline_output_storypoint_name_list, gr.Textbox("buildstorylineGPTOutput", visible=False)]
777
- ).then(track_user_interaction, inputs=[nr_storypoints_to_build, gr.Textbox("buildstorylineNumberOfPoints", visible=False)])
778
 
779
  storyline_prompt.submit(slide_deck_storyline,
780
  inputs = [storyline_prompt, nr_storypoints_to_build],
781
  outputs = [storyline_output_JSON, storyline_output_storypoint_name_list]
782
- ).then(track_user_interaction, inputs=[storyline_prompt, gr.Textbox("buildstorylinePrompt", visible=False)]
783
- ).then(track_user_interaction, inputs=[storyline_output_storypoint_name_list, gr.Textbox("buildstorylineGPTOutput", visible=False)]
784
- ).then(track_user_interaction, inputs=[nr_storypoints_to_build, gr.Textbox("buildstorylineNumberOfPoints", visible=False)])
785
 
786
  gr.Markdown("""## 3. Visualize and Filter: 🔍
787
 
@@ -799,15 +797,15 @@ Outcome: Fellow consultant will develop a comprehensive understanding of AI's po
799
  with gr.Column(scale=2):
800
  nodeSelector.render()
801
  filterBTN.render()
802
- filterBTN.click(fn= construct_hmtl, inputs=[highest_similarities_gradio_list, nodeSelector], outputs=[graphVisual]).then(track_user_interaction, inputs=[nodeSelector, gr.Textbox("filterDropdown", visible=False)]
803
  ).then(js = js_call_draw)
804
 
805
  with gr.Column(scale=2):
806
  custom_filtering_output = gr.Textbox(lines=2, scale=3, interactive=True, label = "Describe what you would like to filter for?", placeholder = """For example: 'Filter to only show slides and their respective slide decks that are assigned to the third STORYPOINT'""")
807
  customfilter_btn = gr.Button("Apply custom filter")
808
  customfilter_btn.click(custom_filtering, inputs=[custom_filtering_output, queryPlaceholder, responsePlaceholder], outputs=[graphVisual, customFilterQuery]
809
- ).then(track_user_interaction, inputs=[custom_filtering_output, gr.Textbox("customFilterPrompt", visible=False)]
810
- ).then(track_user_interaction, inputs=[customFilterQuery, gr.Textbox("customFilterQuery", visible=False)]).then(js = js_call_draw)
811
 
812
  with gr.Group():
813
  with gr.Row():
@@ -819,4 +817,4 @@ Outcome: Fellow consultant will develop a comprehensive understanding of AI's po
819
 
820
 
821
  gr.close_all()
822
- demo.launch(show_api=False, auth_message = "Hello there! Please log in to access the NarrativeNet Weaver using your Prolific ID as username. Use the password supplied in Qualtrics.", auth_dependency=profile_user)
 
27
 
28
 
29
 
 
30
 
31
 
32
 
 
266
 
267
  return HTMLoutput, highest_similarities, query
268
 
269
+ def track_user_interaction(user_input, action, user_id):
270
+
 
271
 
272
  user_id = str(user_id)
273
 
 
317
 
318
  def profile_user(request: gr.Request):
319
 
320
+
321
  query_params = dict(request.query_params)
322
  try:
323
  username = dict(request.query_params)["username"]
324
  user_id = username
325
+ track_user_interaction("", "login", user_id)
326
+ #if dict(request.query_params)["password"] == os.getenv("APP_PASSWORD"):
327
+ # return user_id
328
+ #else:
329
+ return user_id
330
  except:
331
  return None
332
 
 
760
  #storyline_output_pretty = gr.Textbox(label="Your Storyline:", lines=13, scale=3, interactive=False)
761
  submit_button = gr.Button("⚡ Find Slides ⚡", elem_id="visGraph")
762
  submit_button.click(fn= coordinate_simcalculation, inputs=[storyline_output_storypoint_name_list], outputs=[graphVisual, highest_similarities_gradio_list, queryPlaceholder]
763
+ ).then(track_user_interaction, inputs=[storyline_output_storypoint_name_list, gr.Textbox("findslidesStorypoints", visible=False), user_id]
764
  ).then(get_neo4j_response, inputs=[queryPlaceholder], outputs=[responsePlaceholder]
765
+ ).then(track_user_interaction, inputs=[queryPlaceholder, gr.Textbox("findslidesQuery", visible=False), user_id]
766
+ ).then(track_user_interaction, inputs=[responsePlaceholder, gr.Textbox("findslidesNeo4jResponse", visible=False), user_id]).then(js = js_call_draw)
767
 
768
 
769
 
770
  btn_buildstoryline.click(slide_deck_storyline,
771
  inputs = [storyline_prompt, nr_storypoints_to_build],
772
  outputs = [storyline_output_JSON, storyline_output_storypoint_name_list]
773
+ ).then(track_user_interaction, inputs=[storyline_prompt, gr.Textbox("buildstorylinePrompt", visible=False), user_id]
774
+ ).then(track_user_interaction, inputs=[storyline_output_storypoint_name_list, gr.Textbox("buildstorylineGPTOutput", visible=False), user_id]
775
+ ).then(track_user_interaction, inputs=[nr_storypoints_to_build, gr.Textbox("buildstorylineNumberOfPoints", visible=False), user_id])
776
 
777
  storyline_prompt.submit(slide_deck_storyline,
778
  inputs = [storyline_prompt, nr_storypoints_to_build],
779
  outputs = [storyline_output_JSON, storyline_output_storypoint_name_list]
780
+ ).then(track_user_interaction, inputs=[storyline_prompt, gr.Textbox("buildstorylinePrompt", visible=False), user_id]
781
+ ).then(track_user_interaction, inputs=[storyline_output_storypoint_name_list, gr.Textbox("buildstorylineGPTOutput", visible=False), user_id]
782
+ ).then(track_user_interaction, inputs=[nr_storypoints_to_build, gr.Textbox("buildstorylineNumberOfPoints", visible=False), user_id])
783
 
784
  gr.Markdown("""## 3. Visualize and Filter: 🔍
785
 
 
797
  with gr.Column(scale=2):
798
  nodeSelector.render()
799
  filterBTN.render()
800
+ filterBTN.click(fn= construct_hmtl, inputs=[highest_similarities_gradio_list, nodeSelector], outputs=[graphVisual]).then(track_user_interaction, inputs=[nodeSelector, gr.Textbox("filterDropdown", visible=False), user_id]
801
  ).then(js = js_call_draw)
802
 
803
  with gr.Column(scale=2):
804
  custom_filtering_output = gr.Textbox(lines=2, scale=3, interactive=True, label = "Describe what you would like to filter for?", placeholder = """For example: 'Filter to only show slides and their respective slide decks that are assigned to the third STORYPOINT'""")
805
  customfilter_btn = gr.Button("Apply custom filter")
806
  customfilter_btn.click(custom_filtering, inputs=[custom_filtering_output, queryPlaceholder, responsePlaceholder], outputs=[graphVisual, customFilterQuery]
807
+ ).then(track_user_interaction, inputs=[custom_filtering_output, gr.Textbox("customFilterPrompt", visible=False), user_id]
808
+ ).then(track_user_interaction, inputs=[customFilterQuery, gr.Textbox("customFilterQuery", visible=False), user_id]).then(js = js_call_draw)
809
 
810
  with gr.Group():
811
  with gr.Row():
 
817
 
818
 
819
  gr.close_all()
820
+ demo.launch(show_api=False, auth_message = "Hello there! Please log in to access the NarrativeNet Weaver using your Prolific ID as username. Use the password supplied in Qualtrics.", fn=profile_user, outputs = user_id)