Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,6 +3,56 @@ import time
|
|
| 3 |
import random
|
| 4 |
import json
|
| 5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
get_window_url_params = """
|
| 7 |
function() {
|
| 8 |
const params = new URLSearchParams(window.location.search);
|
|
|
|
| 3 |
import random
|
| 4 |
import json
|
| 5 |
|
| 6 |
+
# To test open trust-game-llama2-7b in terminal,
|
| 7 |
+
# open conda environment via conda activate
|
| 8 |
+
# and run this file via python3 data_fetcher.py
|
| 9 |
+
|
| 10 |
+
# Example from here: https://www.techgropse.com/blog/how-to-return-sql-data-in-json-format-python/
|
| 11 |
+
# Use the built-in json module and the pymysql package if using MySQL as database:
|
| 12 |
+
import mysql.connector
|
| 13 |
+
import json
|
| 14 |
+
import requests
|
| 15 |
+
import urllib.parse
|
| 16 |
+
import urllib.request
|
| 17 |
+
|
| 18 |
+
# fetch data from the decisions database
|
| 19 |
+
def fetch_data_as_json():
|
| 20 |
+
# Connect to the database
|
| 21 |
+
conn = mysql.connector.connect(
|
| 22 |
+
host="18.153.94.89",
|
| 23 |
+
user="root",
|
| 24 |
+
password="N12RXMKtKxRj",
|
| 25 |
+
database="lionessdb"
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
# Create a cursor object
|
| 29 |
+
cursor = conn.cursor()
|
| 30 |
+
|
| 31 |
+
# Execute the SQL query
|
| 32 |
+
query = "SELECT playerNr, subjectNr, initialCredit, transfer1, tripledAmount1, keptForSelf1, returned1, " \
|
| 33 |
+
"newCreditRound2, transfer2, tripledAmount2, keptForSelf2, returned2, results2rounds, " \
|
| 34 |
+
"newCreditRound3, transfer3, tripledAmount3, keptForSelf3, returned3, results3rounds FROM e5390g36814_decisions"
|
| 35 |
+
cursor.execute(query)
|
| 36 |
+
|
| 37 |
+
# Fetch all rows and convert to a list of dictionaries
|
| 38 |
+
rows = cursor.fetchall()
|
| 39 |
+
result = []
|
| 40 |
+
for row in rows:
|
| 41 |
+
d = {}
|
| 42 |
+
for i, col in enumerate(cursor.description):
|
| 43 |
+
d[col[0]] = row[i]
|
| 44 |
+
result.append(d)
|
| 45 |
+
|
| 46 |
+
# Convert the list of dictionaries to JSON
|
| 47 |
+
json_result = json.dumps(result)
|
| 48 |
+
|
| 49 |
+
# Close the database connection
|
| 50 |
+
conn.close()
|
| 51 |
+
|
| 52 |
+
# Return the JSON result
|
| 53 |
+
return json_result
|
| 54 |
+
|
| 55 |
+
|
| 56 |
get_window_url_params = """
|
| 57 |
function() {
|
| 58 |
const params = new URLSearchParams(window.location.search);
|