Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -83,7 +83,6 @@ type `read query`
|
|
| 83 |
return "", history + [[user_message, None]]
|
| 84 |
|
| 85 |
def bot(history, url_params):
|
| 86 |
-
global session_index
|
| 87 |
if "read query" in history[-1][0]:
|
| 88 |
session_index = url_params.get('session_index')
|
| 89 |
bot_message = f"""
|
|
@@ -100,7 +99,74 @@ type `read query`
|
|
| 100 |
bot_message = random.choice(["Yes", "No"])
|
| 101 |
history[-1][1] = bot_message
|
| 102 |
time.sleep(1)
|
| 103 |
-
return history
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
|
| 105 |
''' def bot(history, url_params):
|
| 106 |
global session_index
|
|
@@ -125,6 +191,7 @@ type `read query`
|
|
| 125 |
fn=bot, inputs=[chatbot, url_params], outputs=[chatbot]
|
| 126 |
)
|
| 127 |
clear.click(lambda: None, None, chatbot, queue=False)
|
|
|
|
| 128 |
demo.load(
|
| 129 |
fn=lambda x: x,
|
| 130 |
inputs=[url_params],
|
|
@@ -133,116 +200,4 @@ type `read query`
|
|
| 133 |
queue=False
|
| 134 |
)
|
| 135 |
|
| 136 |
-
|
| 137 |
-
def fetch_personalized_data():
|
| 138 |
-
global session_index
|
| 139 |
-
# Connect to the database
|
| 140 |
-
conn = mysql.connector.connect(
|
| 141 |
-
host="18.153.94.89",
|
| 142 |
-
user="root",
|
| 143 |
-
password="N12RXMKtKxRj",
|
| 144 |
-
database="lionessdb"
|
| 145 |
-
)
|
| 146 |
-
|
| 147 |
-
# Create a cursor object
|
| 148 |
-
cursor = conn.cursor()
|
| 149 |
-
|
| 150 |
-
# Replace the placeholders with your actual database and table names
|
| 151 |
-
core_table = "e5390g37096_core"
|
| 152 |
-
decisions_table = "e5390g37096_decisions"
|
| 153 |
-
#session_index = "your_session_index_value"
|
| 154 |
-
playerNr = "1"
|
| 155 |
-
|
| 156 |
-
# Query to fetch relevant data from both tables based on session_index
|
| 157 |
-
query = f"""
|
| 158 |
-
SELECT
|
| 159 |
-
{core_table}.playerNr,
|
| 160 |
-
{core_table}.subjectNr,
|
| 161 |
-
{core_table}.onPage,
|
| 162 |
-
{decisions_table}.transfer1,
|
| 163 |
-
{decisions_table}.tripledAmount1,
|
| 164 |
-
{decisions_table}.keptForSelf1,
|
| 165 |
-
{decisions_table}.returned1,
|
| 166 |
-
{decisions_table}.newCreditRound2,
|
| 167 |
-
{decisions_table}.transfer2,
|
| 168 |
-
{decisions_table}.tripledAmount2,
|
| 169 |
-
{decisions_table}.keptForSelf2,
|
| 170 |
-
{decisions_table}.returned2,
|
| 171 |
-
{decisions_table}.resultsWithoutAI
|
| 172 |
-
FROM {core_table}
|
| 173 |
-
JOIN {decisions_table} ON
|
| 174 |
-
{core_table}.playerNr = {decisions_table}.playerNr AND
|
| 175 |
-
{core_table}.groupNr = {decisions_table}.groupNr AND
|
| 176 |
-
{core_table}.subjectNr = {decisions_table}.subjectNr
|
| 177 |
-
WHERE {decisions_table}.session_index = '{session_index}'
|
| 178 |
-
"""
|
| 179 |
-
cursor.execute(query)
|
| 180 |
-
|
| 181 |
-
# Fetch all rows and convert to a list of dictionaries
|
| 182 |
-
rows = cursor.fetchall()
|
| 183 |
-
result = []
|
| 184 |
-
for row in rows:
|
| 185 |
-
d = {}
|
| 186 |
-
for i, col in enumerate(cursor.description):
|
| 187 |
-
d[col[0]] = row[i]
|
| 188 |
-
result.append(d)
|
| 189 |
-
|
| 190 |
-
# Convert the list of dictionaries to JSON
|
| 191 |
-
personalized_result = json.dumps(result)
|
| 192 |
-
|
| 193 |
-
# Close the database connection
|
| 194 |
-
conn.close()
|
| 195 |
-
|
| 196 |
-
# Return the JSON result
|
| 197 |
-
return personalized_result
|
| 198 |
-
|
| 199 |
-
# Call the function to fetch data as JSON
|
| 200 |
-
personalized_data = fetch_personalized_data()
|
| 201 |
-
|
| 202 |
-
# Print or use the json_result variable as needed
|
| 203 |
-
print(personalized_data)
|
| 204 |
-
|
| 205 |
-
demo.launch()
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
'''
|
| 218 |
-
def bot(history, url_params):
|
| 219 |
-
global session_index
|
| 220 |
-
if "read query" in history[-1][0]:
|
| 221 |
-
session_index = url_params.get('session_index')
|
| 222 |
-
bot_message = f"""
|
| 223 |
-
here your URL params:
|
| 224 |
-
{json.dumps(url_params, indent=4)}
|
| 225 |
-
"""
|
| 226 |
-
print(url_params)
|
| 227 |
-
else:
|
| 228 |
-
bot_message = random.choice(["Yes", "No"])
|
| 229 |
-
history[-1][1] = bot_message
|
| 230 |
-
time.sleep(1)
|
| 231 |
-
return history'''
|
| 232 |
-
|
| 233 |
-
'''
|
| 234 |
-
WHERE {decisions_table}.session_index = '{session_index}'
|
| 235 |
-
|
| 236 |
-
# Fetch the results
|
| 237 |
-
results = cursor.fetchall()
|
| 238 |
-
|
| 239 |
-
# Process the results as needed
|
| 240 |
-
for row in results:
|
| 241 |
-
print(row)
|
| 242 |
-
|
| 243 |
-
# Close the cursor and connection when done
|
| 244 |
-
cursor.close()
|
| 245 |
-
conn.close()
|
| 246 |
-
|
| 247 |
-
return results
|
| 248 |
-
'''
|
|
|
|
| 83 |
return "", history + [[user_message, None]]
|
| 84 |
|
| 85 |
def bot(history, url_params):
|
|
|
|
| 86 |
if "read query" in history[-1][0]:
|
| 87 |
session_index = url_params.get('session_index')
|
| 88 |
bot_message = f"""
|
|
|
|
| 99 |
bot_message = random.choice(["Yes", "No"])
|
| 100 |
history[-1][1] = bot_message
|
| 101 |
time.sleep(1)
|
| 102 |
+
return history, session_index
|
| 103 |
+
|
| 104 |
+
def fetch_personalized_data():
|
| 105 |
+
# Connect to the database
|
| 106 |
+
conn = mysql.connector.connect(
|
| 107 |
+
host="18.153.94.89",
|
| 108 |
+
user="root",
|
| 109 |
+
password="N12RXMKtKxRj",
|
| 110 |
+
database="lionessdb"
|
| 111 |
+
)
|
| 112 |
+
|
| 113 |
+
# Create a cursor object
|
| 114 |
+
cursor = conn.cursor()
|
| 115 |
+
|
| 116 |
+
# Replace the placeholders with your actual database and table names
|
| 117 |
+
core_table = "e5390g37096_core"
|
| 118 |
+
decisions_table = "e5390g37096_decisions"
|
| 119 |
+
session_index = url_params.get('session_index')
|
| 120 |
+
playerNr = "1"
|
| 121 |
+
|
| 122 |
+
# Query to fetch relevant data from both tables based on session_index
|
| 123 |
+
query = f"""
|
| 124 |
+
SELECT
|
| 125 |
+
{core_table}.playerNr,
|
| 126 |
+
{core_table}.subjectNr,
|
| 127 |
+
{core_table}.onPage,
|
| 128 |
+
{decisions_table}.transfer1,
|
| 129 |
+
{decisions_table}.tripledAmount1,
|
| 130 |
+
{decisions_table}.keptForSelf1,
|
| 131 |
+
{decisions_table}.returned1,
|
| 132 |
+
{decisions_table}.newCreditRound2,
|
| 133 |
+
{decisions_table}.transfer2,
|
| 134 |
+
{decisions_table}.tripledAmount2,
|
| 135 |
+
{decisions_table}.keptForSelf2,
|
| 136 |
+
{decisions_table}.returned2,
|
| 137 |
+
{decisions_table}.resultsWithoutAI
|
| 138 |
+
FROM {core_table}
|
| 139 |
+
JOIN {decisions_table} ON
|
| 140 |
+
{core_table}.playerNr = {decisions_table}.playerNr AND
|
| 141 |
+
{core_table}.groupNr = {decisions_table}.groupNr AND
|
| 142 |
+
{core_table}.subjectNr = {decisions_table}.subjectNr
|
| 143 |
+
WHERE {decisions_table}.session_index = '{session_index}'
|
| 144 |
+
"""
|
| 145 |
+
cursor.execute(query)
|
| 146 |
+
|
| 147 |
+
# Fetch all rows and convert to a list of dictionaries
|
| 148 |
+
rows = cursor.fetchall()
|
| 149 |
+
result = []
|
| 150 |
+
for row in rows:
|
| 151 |
+
d = {}
|
| 152 |
+
for i, col in enumerate(cursor.description):
|
| 153 |
+
d[col[0]] = row[i]
|
| 154 |
+
result.append(d)
|
| 155 |
+
|
| 156 |
+
# Convert the list of dictionaries to JSON
|
| 157 |
+
personalized_result = json.dumps(result)
|
| 158 |
+
|
| 159 |
+
# Close the database connection
|
| 160 |
+
conn.close()
|
| 161 |
+
|
| 162 |
+
# Return the JSON result
|
| 163 |
+
return personalized_result
|
| 164 |
+
|
| 165 |
+
# Call the function to fetch data as JSON
|
| 166 |
+
personalized_data = fetch_personalized_data()
|
| 167 |
+
|
| 168 |
+
# Print or use the json_result variable as needed
|
| 169 |
+
print(personalized_data)
|
| 170 |
|
| 171 |
''' def bot(history, url_params):
|
| 172 |
global session_index
|
|
|
|
| 191 |
fn=bot, inputs=[chatbot, url_params], outputs=[chatbot]
|
| 192 |
)
|
| 193 |
clear.click(lambda: None, None, chatbot, queue=False)
|
| 194 |
+
|
| 195 |
demo.load(
|
| 196 |
fn=lambda x: x,
|
| 197 |
inputs=[url_params],
|
|
|
|
| 200 |
queue=False
|
| 201 |
)
|
| 202 |
|
| 203 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|