Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,39 +8,72 @@ import csv
|
|
| 8 |
from datetime import datetime
|
| 9 |
from huggingface_hub import Repository, hf_hub_download
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
|
| 46 |
get_window_url_params = """
|
|
@@ -160,64 +193,5 @@ with gr.Blocks() as demo:
|
|
| 160 |
_js=get_window_url_params,
|
| 161 |
queue=False
|
| 162 |
)
|
| 163 |
-
|
| 164 |
-
# Connect to the database
|
| 165 |
-
conn = mysql.connector.connect(
|
| 166 |
-
host="18.153.94.89",
|
| 167 |
-
user="root",
|
| 168 |
-
password="N12RXMKtKxRj",
|
| 169 |
-
database="lionessdb"
|
| 170 |
-
)
|
| 171 |
-
|
| 172 |
-
# Create a cursor object
|
| 173 |
-
cursor = conn.cursor()
|
| 174 |
-
|
| 175 |
-
# Replace the placeholders with your actual database and table names
|
| 176 |
-
core_table = "e5390g37096_core"
|
| 177 |
-
decisions_table = "e5390g37096_decisions"
|
| 178 |
-
session_index = "eb3636167d3a63fbeee32934610e5b2f"
|
| 179 |
-
print(session_index)
|
| 180 |
-
playerNr = "1"
|
| 181 |
-
|
| 182 |
-
# Query to fetch relevant data from both tables based on session_index
|
| 183 |
-
query = f"""
|
| 184 |
-
SELECT
|
| 185 |
-
{core_table}.playerNr,
|
| 186 |
-
{core_table}.subjectNr,
|
| 187 |
-
{core_table}.onPage,
|
| 188 |
-
{decisions_table}.transfer1,
|
| 189 |
-
{decisions_table}.tripledAmount1,
|
| 190 |
-
{decisions_table}.keptForSelf1,
|
| 191 |
-
{decisions_table}.returned1,
|
| 192 |
-
{decisions_table}.newCreditRound2,
|
| 193 |
-
{decisions_table}.transfer2,
|
| 194 |
-
{decisions_table}.tripledAmount2,
|
| 195 |
-
{decisions_table}.keptForSelf2,
|
| 196 |
-
{decisions_table}.returned2,
|
| 197 |
-
{decisions_table}.resultsWithoutAI
|
| 198 |
-
FROM {core_table}
|
| 199 |
-
JOIN {decisions_table} ON
|
| 200 |
-
{core_table}.playerNr = {decisions_table}.playerNr AND
|
| 201 |
-
{core_table}.groupNr = {decisions_table}.groupNr AND
|
| 202 |
-
{core_table}.subjectNr = {decisions_table}.subjectNr
|
| 203 |
-
WHERE {decisions_table}.session_index = '{session_index}'
|
| 204 |
-
"""
|
| 205 |
-
cursor.execute(query)
|
| 206 |
-
|
| 207 |
-
# Fetch all rows and convert to a list of dictionaries
|
| 208 |
-
rows = cursor.fetchall()
|
| 209 |
-
result = []
|
| 210 |
-
for row in rows:
|
| 211 |
-
d = {}
|
| 212 |
-
for i, col in enumerate(cursor.description):
|
| 213 |
-
d[col[0]] = row[i]
|
| 214 |
-
result.append(d)
|
| 215 |
-
|
| 216 |
-
# Convert the list of dictionaries to JSON
|
| 217 |
-
personalized_result = json.dumps(result)
|
| 218 |
-
print(personalized_result)
|
| 219 |
-
|
| 220 |
-
# Close the database connection
|
| 221 |
-
conn.close()
|
| 222 |
-
|
| 223 |
demo.launch()
|
|
|
|
| 8 |
from datetime import datetime
|
| 9 |
from huggingface_hub import Repository, hf_hub_download
|
| 10 |
|
| 11 |
+
def fetch_personalized_data()
|
| 12 |
+
# Connect to the database
|
| 13 |
+
conn = mysql.connector.connect(
|
| 14 |
+
host="18.153.94.89",
|
| 15 |
+
user="root",
|
| 16 |
+
password="N12RXMKtKxRj",
|
| 17 |
+
database="lionessdb"
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
# Create a cursor object
|
| 21 |
+
cursor = conn.cursor()
|
| 22 |
+
|
| 23 |
+
# Replace the placeholders with your actual database and table names
|
| 24 |
+
core_table = "e5390g37096_core"
|
| 25 |
+
decisions_table = "e5390g37096_decisions"
|
| 26 |
+
session_index = "eb3636167d3a63fbeee32934610e5b2f"
|
| 27 |
+
print(session_index)
|
| 28 |
+
playerNr = "1"
|
| 29 |
+
|
| 30 |
+
# Query to fetch relevant data from both tables based on session_index
|
| 31 |
+
query = f"""
|
| 32 |
+
SELECT
|
| 33 |
+
{core_table}.playerNr,
|
| 34 |
+
{core_table}.subjectNr,
|
| 35 |
+
{core_table}.onPage,
|
| 36 |
+
{decisions_table}.transfer1,
|
| 37 |
+
{decisions_table}.tripledAmount1,
|
| 38 |
+
{decisions_table}.keptForSelf1,
|
| 39 |
+
{decisions_table}.returned1,
|
| 40 |
+
{decisions_table}.newCreditRound2,
|
| 41 |
+
{decisions_table}.transfer2,
|
| 42 |
+
{decisions_table}.tripledAmount2,
|
| 43 |
+
{decisions_table}.keptForSelf2,
|
| 44 |
+
{decisions_table}.returned2,
|
| 45 |
+
{decisions_table}.resultsWithoutAI
|
| 46 |
+
FROM {core_table}
|
| 47 |
+
JOIN {decisions_table} ON
|
| 48 |
+
{core_table}.playerNr = {decisions_table}.playerNr AND
|
| 49 |
+
{core_table}.groupNr = {decisions_table}.groupNr AND
|
| 50 |
+
{core_table}.subjectNr = {decisions_table}.subjectNr
|
| 51 |
+
WHERE {decisions_table}.session_index = '{session_index}'
|
| 52 |
+
"""
|
| 53 |
+
cursor.execute(query)
|
| 54 |
+
|
| 55 |
+
# Fetch all rows and convert to a list of dictionaries
|
| 56 |
+
rows = cursor.fetchall()
|
| 57 |
+
result = []
|
| 58 |
+
for row in rows:
|
| 59 |
+
d = {}
|
| 60 |
+
for i, col in enumerate(cursor.description):
|
| 61 |
+
d[col[0]] = row[i]
|
| 62 |
+
result.append(d)
|
| 63 |
+
|
| 64 |
+
# Convert the list of dictionaries to JSON
|
| 65 |
+
personalized_result = json.dumps(result)
|
| 66 |
+
print(personalized_result)
|
| 67 |
+
|
| 68 |
+
# Close the database connection
|
| 69 |
+
conn.close()
|
| 70 |
+
return personalized(result)
|
| 71 |
|
| 72 |
+
# Call the function to fetch data as JSON
|
| 73 |
+
personalized_data = fetch_personalized_data()
|
| 74 |
+
|
| 75 |
+
# Print or use the json_result variable as needed
|
| 76 |
+
print(personalized_data)
|
| 77 |
|
| 78 |
|
| 79 |
get_window_url_params = """
|
|
|
|
| 193 |
_js=get_window_url_params,
|
| 194 |
queue=False
|
| 195 |
)
|
| 196 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 197 |
demo.launch()
|