Spaces:
Sleeping
Sleeping
alexanderHSG commited on
Commit ·
b0699d4
1
Parent(s): 869ab8d
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,7 +7,6 @@ import pandas as pd
|
|
| 7 |
import numpy as np
|
| 8 |
from sklearn.metrics.pairwise import cosine_similarity
|
| 9 |
from dotenv import load_dotenv
|
| 10 |
-
import sqlite3
|
| 11 |
from datetime import datetime
|
| 12 |
import re
|
| 13 |
import mysql.connector
|
|
@@ -284,26 +283,32 @@ def track_user_interaction(user_input, action):
|
|
| 284 |
cursor = connection.cursor()
|
| 285 |
|
| 286 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 287 |
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
| 288 |
user_input_str = str(user_input)
|
| 289 |
action_str = str(action)
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
user_id TEXT NOT NULL
|
| 299 |
-
);
|
| 300 |
-
''')
|
| 301 |
-
insert_query = "INSERT INTO user_interactions (user_input, action, timestamp, user_id) VALUES ('" + user_input_str + "', '" + action_str + "', '" + timestamp + "', '" + user_id + "')"
|
| 302 |
-
|
| 303 |
-
cursor.execute(insert_query)
|
| 304 |
connection.commit()
|
| 305 |
connection.close()
|
| 306 |
|
|
|
|
|
|
|
| 307 |
def profile_user(username, password):
|
| 308 |
global user_id
|
| 309 |
user_id = username
|
|
@@ -718,24 +723,26 @@ Outcome: Fellow consultant will develop a comprehensive understanding of AI's po
|
|
| 718 |
#storyline_output_pretty = gr.Textbox(label="Your Storyline:", lines=13, scale=3, interactive=False)
|
| 719 |
submit_button = gr.Button("⚡ Find Slides ⚡", elem_id="visGraph")
|
| 720 |
submit_button.click(fn= coordinate_simcalculation, inputs=[storyline_output_storypoint_name_list], outputs=[graphVisual, highest_similarities_gradio_list, queryPlaceholder]
|
| 721 |
-
).then(track_user_interaction, inputs=[storyline_output_storypoint_name_list, gr.Textbox("
|
| 722 |
-
).then(
|
|
|
|
|
|
|
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
btn_buildstoryline.click(slide_deck_storyline,
|
| 727 |
inputs = [storyline_prompt, nr_storypoints_to_build],
|
| 728 |
outputs = [storyline_output_JSON, storyline_output_storypoint_name_list]
|
| 729 |
-
)
|
| 730 |
-
|
| 731 |
-
|
| 732 |
|
| 733 |
storyline_prompt.submit(slide_deck_storyline,
|
| 734 |
inputs = [storyline_prompt, nr_storypoints_to_build],
|
| 735 |
outputs = [storyline_output_JSON, storyline_output_storypoint_name_list]
|
| 736 |
-
).then(track_user_interaction, inputs=[storyline_prompt, gr.Textbox("
|
| 737 |
-
).then(track_user_interaction, inputs=[storyline_output_storypoint_name_list, gr.Textbox("
|
| 738 |
-
).then(track_user_interaction, inputs=[nr_storypoints_to_build, gr.Textbox("
|
| 739 |
|
| 740 |
gr.Markdown("""## 3. Visualize and Filter: 🔍
|
| 741 |
|
|
|
|
| 7 |
import numpy as np
|
| 8 |
from sklearn.metrics.pairwise import cosine_similarity
|
| 9 |
from dotenv import load_dotenv
|
|
|
|
| 10 |
from datetime import datetime
|
| 11 |
import re
|
| 12 |
import mysql.connector
|
|
|
|
| 283 |
cursor = connection.cursor()
|
| 284 |
|
| 285 |
|
| 286 |
+
# Create table if it doesn't exist
|
| 287 |
+
cursor.execute('''
|
| 288 |
+
CREATE TABLE IF NOT EXISTS user_interactions (
|
| 289 |
+
user_input LONGTEXT NOT NULL,
|
| 290 |
+
action TEXT NOT NULL,
|
| 291 |
+
timestamp TEXT NOT NULL,
|
| 292 |
+
user_id TEXT NOT NULL
|
| 293 |
+
);
|
| 294 |
+
''')
|
| 295 |
+
# Prepare data
|
| 296 |
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
| 297 |
user_input_str = str(user_input)
|
| 298 |
action_str = str(action)
|
| 299 |
+
|
| 300 |
+
# Use a parameterized query to insert data
|
| 301 |
+
insert_query = """
|
| 302 |
+
INSERT INTO user_interactions (user_input, action, timestamp, user_id)
|
| 303 |
+
VALUES (%s, %s, %s, %s)
|
| 304 |
+
"""
|
| 305 |
+
cursor.execute(insert_query, (user_input_str, action_str, timestamp, user_id))
|
| 306 |
+
# Commit changes and close connection
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 307 |
connection.commit()
|
| 308 |
connection.close()
|
| 309 |
|
| 310 |
+
|
| 311 |
+
|
| 312 |
def profile_user(username, password):
|
| 313 |
global user_id
|
| 314 |
user_id = username
|
|
|
|
| 723 |
#storyline_output_pretty = gr.Textbox(label="Your Storyline:", lines=13, scale=3, interactive=False)
|
| 724 |
submit_button = gr.Button("⚡ Find Slides ⚡", elem_id="visGraph")
|
| 725 |
submit_button.click(fn= coordinate_simcalculation, inputs=[storyline_output_storypoint_name_list], outputs=[graphVisual, highest_similarities_gradio_list, queryPlaceholder]
|
| 726 |
+
).then(track_user_interaction, inputs=[storyline_output_storypoint_name_list, gr.Textbox("findslidesStorypoints", visible=False)]
|
| 727 |
+
).then(get_neo4j_response, inputs=[queryPlaceholder], outputs=[responsePlaceholder]
|
| 728 |
+
).then(track_user_interaction, inputs=[queryPlaceholder, gr.Textbox("findslidesQuery", visible=False)]
|
| 729 |
+
).then(track_user_interaction, inputs=[responsePlaceholder, gr.Textbox("findslidesNeo4jResponse", visible=False)]).then(js = js_call_draw)
|
| 730 |
|
| 731 |
|
| 732 |
|
| 733 |
btn_buildstoryline.click(slide_deck_storyline,
|
| 734 |
inputs = [storyline_prompt, nr_storypoints_to_build],
|
| 735 |
outputs = [storyline_output_JSON, storyline_output_storypoint_name_list]
|
| 736 |
+
).then(track_user_interaction, inputs=[storyline_prompt, gr.Textbox("buildstorylinePrompt", visible=False)]
|
| 737 |
+
).then(track_user_interaction, inputs=[storyline_output_storypoint_name_list, gr.Textbox("buildstorylineGPTOutput", visible=False)]
|
| 738 |
+
).then(track_user_interaction, inputs=[nr_storypoints_to_build, gr.Textbox("buildstorylineNumberOfPoints", visible=False)])
|
| 739 |
|
| 740 |
storyline_prompt.submit(slide_deck_storyline,
|
| 741 |
inputs = [storyline_prompt, nr_storypoints_to_build],
|
| 742 |
outputs = [storyline_output_JSON, storyline_output_storypoint_name_list]
|
| 743 |
+
).then(track_user_interaction, inputs=[storyline_prompt, gr.Textbox("buildstorylinePrompt", visible=False)]
|
| 744 |
+
).then(track_user_interaction, inputs=[storyline_output_storypoint_name_list, gr.Textbox("buildstorylineGPTOutput", visible=False)]
|
| 745 |
+
).then(track_user_interaction, inputs=[nr_storypoints_to_build, gr.Textbox("buildstorylineNumberOfPoints", visible=False)])
|
| 746 |
|
| 747 |
gr.Markdown("""## 3. Visualize and Filter: 🔍
|
| 748 |
|