Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -79,8 +79,64 @@ with gr.Blocks() as demo:
|
|
| 79 |
here your URL params:
|
| 80 |
{json.dumps(url_params, indent=4)}
|
| 81 |
"""
|
| 82 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
elif "print data" in history[-1][0]:
|
| 85 |
personalized_data = fetch_personalized_data()
|
| 86 |
print(personalized_data)
|
|
@@ -89,77 +145,7 @@ with gr.Blocks() as demo:
|
|
| 89 |
bot_message = random.choice(["Yes", "No"])
|
| 90 |
history[-1][1] = bot_message
|
| 91 |
time.sleep(1)
|
| 92 |
-
return history
|
| 93 |
-
|
| 94 |
-
def fetch_personalized_data():
|
| 95 |
-
# Connect to the database
|
| 96 |
-
conn = mysql.connector.connect(
|
| 97 |
-
host="18.153.94.89",
|
| 98 |
-
user="root",
|
| 99 |
-
password="N12RXMKtKxRj",
|
| 100 |
-
database="lionessdb"
|
| 101 |
-
)
|
| 102 |
-
|
| 103 |
-
# Create a cursor object
|
| 104 |
-
cursor = conn.cursor()
|
| 105 |
-
|
| 106 |
-
# Replace the placeholders with your actual database and table names
|
| 107 |
-
core_table = "e5390g37096_core"
|
| 108 |
-
decisions_table = "e5390g37096_decisions"
|
| 109 |
-
session_index = url_params.get('session_index')
|
| 110 |
-
print(session_index)
|
| 111 |
-
playerNr = "1"
|
| 112 |
-
|
| 113 |
-
# Query to fetch relevant data from both tables based on session_index
|
| 114 |
-
query = f"""
|
| 115 |
-
SELECT
|
| 116 |
-
{core_table}.playerNr,
|
| 117 |
-
{core_table}.subjectNr,
|
| 118 |
-
{core_table}.onPage,
|
| 119 |
-
{decisions_table}.transfer1,
|
| 120 |
-
{decisions_table}.tripledAmount1,
|
| 121 |
-
{decisions_table}.keptForSelf1,
|
| 122 |
-
{decisions_table}.returned1,
|
| 123 |
-
{decisions_table}.newCreditRound2,
|
| 124 |
-
{decisions_table}.transfer2,
|
| 125 |
-
{decisions_table}.tripledAmount2,
|
| 126 |
-
{decisions_table}.keptForSelf2,
|
| 127 |
-
{decisions_table}.returned2,
|
| 128 |
-
{decisions_table}.resultsWithoutAI
|
| 129 |
-
FROM {core_table}
|
| 130 |
-
JOIN {decisions_table} ON
|
| 131 |
-
{core_table}.playerNr = {decisions_table}.playerNr AND
|
| 132 |
-
{core_table}.groupNr = {decisions_table}.groupNr AND
|
| 133 |
-
{core_table}.subjectNr = {decisions_table}.subjectNr
|
| 134 |
-
WHERE {decisions_table}.session_index = '{session_index}'
|
| 135 |
-
"""
|
| 136 |
-
cursor.execute(query)
|
| 137 |
-
|
| 138 |
-
# Fetch all rows and convert to a list of dictionaries
|
| 139 |
-
rows = cursor.fetchall()
|
| 140 |
-
result = []
|
| 141 |
-
for row in rows:
|
| 142 |
-
d = {}
|
| 143 |
-
for i, col in enumerate(cursor.description):
|
| 144 |
-
d[col[0]] = row[i]
|
| 145 |
-
result.append(d)
|
| 146 |
-
|
| 147 |
-
# Convert the list of dictionaries to JSON
|
| 148 |
-
personalized_result = json.dumps(result)
|
| 149 |
-
|
| 150 |
-
# Close the database connection
|
| 151 |
-
conn.close()
|
| 152 |
-
|
| 153 |
-
print(personalized_result)
|
| 154 |
-
|
| 155 |
-
# Return the JSON result
|
| 156 |
-
return personalized_result
|
| 157 |
-
|
| 158 |
-
# Call the function to fetch data as JSON
|
| 159 |
-
personalized_data = fetch_personalized_data()
|
| 160 |
-
|
| 161 |
-
# Print or use the json_result variable as needed
|
| 162 |
-
print(personalized_data)
|
| 163 |
|
| 164 |
msg.submit(user, inputs=[msg, url_params, chatbot], outputs=[msg, chatbot], queue=False).then(
|
| 165 |
fn=bot, inputs=[chatbot, url_params], outputs=[chatbot]
|
|
|
|
| 79 |
here your URL params:
|
| 80 |
{json.dumps(url_params, indent=4)}
|
| 81 |
"""
|
| 82 |
+
# Connect to the database
|
| 83 |
+
conn = mysql.connector.connect(
|
| 84 |
+
host="18.153.94.89",
|
| 85 |
+
user="root",
|
| 86 |
+
password="N12RXMKtKxRj",
|
| 87 |
+
database="lionessdb"
|
| 88 |
+
)
|
| 89 |
+
|
| 90 |
+
# Create a cursor object
|
| 91 |
+
cursor = conn.cursor()
|
| 92 |
+
|
| 93 |
+
# Replace the placeholders with your actual database and table names
|
| 94 |
+
core_table = "e5390g37096_core"
|
| 95 |
+
decisions_table = "e5390g37096_decisions"
|
| 96 |
+
playerNr = "1"
|
| 97 |
+
|
| 98 |
+
# Query to fetch relevant data from both tables based on session_index
|
| 99 |
+
query = f"""
|
| 100 |
+
SELECT
|
| 101 |
+
{core_table}.playerNr,
|
| 102 |
+
{core_table}.subjectNr,
|
| 103 |
+
{core_table}.onPage,
|
| 104 |
+
{decisions_table}.transfer1,
|
| 105 |
+
{decisions_table}.tripledAmount1,
|
| 106 |
+
{decisions_table}.keptForSelf1,
|
| 107 |
+
{decisions_table}.returned1,
|
| 108 |
+
{decisions_table}.newCreditRound2,
|
| 109 |
+
{decisions_table}.transfer2,
|
| 110 |
+
{decisions_table}.tripledAmount2,
|
| 111 |
+
{decisions_table}.keptForSelf2,
|
| 112 |
+
{decisions_table}.returned2,
|
| 113 |
+
{decisions_table}.resultsWithoutAI
|
| 114 |
+
FROM {core_table}
|
| 115 |
+
JOIN {decisions_table} ON
|
| 116 |
+
{core_table}.playerNr = {decisions_table}.playerNr AND
|
| 117 |
+
{core_table}.groupNr = {decisions_table}.groupNr AND
|
| 118 |
+
{core_table}.subjectNr = {decisions_table}.subjectNr
|
| 119 |
+
WHERE {decisions_table}.session_index = '{session_index}'
|
| 120 |
+
"""
|
| 121 |
+
cursor.execute(query)
|
| 122 |
+
|
| 123 |
+
# Fetch all rows and convert to a list of dictionaries
|
| 124 |
+
rows = cursor.fetchall()
|
| 125 |
+
result = []
|
| 126 |
+
for row in rows:
|
| 127 |
+
d = {}
|
| 128 |
+
for i, col in enumerate(cursor.description):
|
| 129 |
+
d[col[0]] = row[i]
|
| 130 |
+
result.append(d)
|
| 131 |
+
|
| 132 |
+
# Convert the list of dictionaries to JSON
|
| 133 |
+
personalized_result = json.dumps(result)
|
| 134 |
|
| 135 |
+
# Close the database connection
|
| 136 |
+
conn.close()
|
| 137 |
+
|
| 138 |
+
print(personalized_result)
|
| 139 |
+
|
| 140 |
elif "print data" in history[-1][0]:
|
| 141 |
personalized_data = fetch_personalized_data()
|
| 142 |
print(personalized_data)
|
|
|
|
| 145 |
bot_message = random.choice(["Yes", "No"])
|
| 146 |
history[-1][1] = bot_message
|
| 147 |
time.sleep(1)
|
| 148 |
+
return history
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 149 |
|
| 150 |
msg.submit(user, inputs=[msg, url_params, chatbot], outputs=[msg, chatbot], queue=False).then(
|
| 151 |
fn=bot, inputs=[chatbot, url_params], outputs=[chatbot]
|