Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,17 +8,6 @@ import csv
|
|
| 8 |
from datetime import datetime
|
| 9 |
from huggingface_hub import Repository, hf_hub_download
|
| 10 |
|
| 11 |
-
'''
|
| 12 |
-
#Upload File to HF Datasets from https://huggingface.co/docs/huggingface_hub/v0.16.3/en/guides/upload
|
| 13 |
-
from huggingface_hub import HfApi
|
| 14 |
-
api = HfApi()
|
| 15 |
-
api.upload_file(
|
| 16 |
-
path_or_fileobj="/path/to/local/folder/README.md",
|
| 17 |
-
path_in_repo="README.md",
|
| 18 |
-
repo_id="username/test-dataset",
|
| 19 |
-
repo_type="dataset",
|
| 20 |
-
)
|
| 21 |
-
'''
|
| 22 |
DATASET_REPO_URL = "https://huggingface.co/datasets/botsi/trust-game-llama-2-7b-chat"
|
| 23 |
DATASET_REPO_ID = "botsi/trust-game-llama-2-7b-chat"
|
| 24 |
DATA_FILENAME = "history_trust-game-llama-2-7b-chat.csv"
|
|
@@ -183,99 +172,4 @@ with gr.Blocks() as demo:
|
|
| 183 |
queue=False
|
| 184 |
)
|
| 185 |
|
| 186 |
-
demo.launch()
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
'''def fetch_personalized_data():
|
| 196 |
-
# Connect to the database
|
| 197 |
-
conn = mysql.connector.connect(
|
| 198 |
-
host="18.153.94.89",
|
| 199 |
-
user="root",
|
| 200 |
-
password="N12RXMKtKxRj",
|
| 201 |
-
database="lionessdb"
|
| 202 |
-
)
|
| 203 |
-
|
| 204 |
-
# Create a cursor object
|
| 205 |
-
cursor = conn.cursor()
|
| 206 |
-
|
| 207 |
-
# Replace the placeholders with your actual database and table names
|
| 208 |
-
core_table = "e5390g37096_core"
|
| 209 |
-
decisions_table = "e5390g37096_decisions"
|
| 210 |
-
playerNr = "1"
|
| 211 |
-
|
| 212 |
-
# Query to fetch relevant data from both tables based on session_index
|
| 213 |
-
query = f"""
|
| 214 |
-
SELECT
|
| 215 |
-
{core_table}.playerNr,
|
| 216 |
-
{core_table}.subjectNr,
|
| 217 |
-
{core_table}.onPage,
|
| 218 |
-
{decisions_table}.transfer1,
|
| 219 |
-
{decisions_table}.tripledAmount1,
|
| 220 |
-
{decisions_table}.keptForSelf1,
|
| 221 |
-
{decisions_table}.returned1,
|
| 222 |
-
{decisions_table}.newCreditRound2,
|
| 223 |
-
{decisions_table}.transfer2,
|
| 224 |
-
{decisions_table}.tripledAmount2,
|
| 225 |
-
{decisions_table}.keptForSelf2,
|
| 226 |
-
{decisions_table}.returned2,
|
| 227 |
-
{decisions_table}.resultsWithoutAI
|
| 228 |
-
FROM {core_table}
|
| 229 |
-
JOIN {decisions_table} ON
|
| 230 |
-
{core_table}.playerNr = {decisions_table}.playerNr AND
|
| 231 |
-
{core_table}.groupNr = {decisions_table}.groupNr AND
|
| 232 |
-
{core_table}.subjectNr = {decisions_table}.subjectNr
|
| 233 |
-
WHERE {decisions_table}.session_index = '{session_index}'
|
| 234 |
-
"""
|
| 235 |
-
cursor.execute(query)
|
| 236 |
-
|
| 237 |
-
# Fetch all rows and convert to a list of dictionaries
|
| 238 |
-
rows = cursor.fetchall()
|
| 239 |
-
result = []
|
| 240 |
-
for row in rows:
|
| 241 |
-
d = {}
|
| 242 |
-
for i, col in enumerate(cursor.description):
|
| 243 |
-
d[col[0]] = row[i]
|
| 244 |
-
result.append(d)
|
| 245 |
-
|
| 246 |
-
# Convert the list of dictionaries to JSON
|
| 247 |
-
personalized_result = json.dumps(result)
|
| 248 |
-
|
| 249 |
-
# Close the database connection
|
| 250 |
-
conn.close()
|
| 251 |
-
|
| 252 |
-
print(personalized_result)
|
| 253 |
-
|
| 254 |
-
# Return the JSON result
|
| 255 |
-
return personalized_result
|
| 256 |
-
|
| 257 |
-
# Call the function to fetch data as JSON
|
| 258 |
-
# personalized_data = fetch_personalized_data()
|
| 259 |
-
|
| 260 |
-
# Print or use the json_result variable as needed
|
| 261 |
-
# print(personalized_data)
|
| 262 |
-
'''
|
| 263 |
-
|
| 264 |
-
''' def bot(history, url_params):
|
| 265 |
-
global session_index
|
| 266 |
-
if "read query" in history[-1][0]:
|
| 267 |
-
session_index = url_params.get('session_index')
|
| 268 |
-
bot_message = f"""
|
| 269 |
-
here your URL params:
|
| 270 |
-
{json.dumps(url_params, indent=4)}
|
| 271 |
-
"""
|
| 272 |
-
elif "print data" in history[-1][0]:
|
| 273 |
-
personalized_data = fetch_personalized_data()
|
| 274 |
-
print(personalized_data)
|
| 275 |
-
bot_message = "Data printed."
|
| 276 |
-
else:
|
| 277 |
-
bot_message = random.choice(["Yes", "No"])
|
| 278 |
-
history[-1][1] = bot_message
|
| 279 |
-
time.sleep(1)
|
| 280 |
-
return history
|
| 281 |
-
'''
|
|
|
|
| 8 |
from datetime import datetime
|
| 9 |
from huggingface_hub import Repository, hf_hub_download
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
DATASET_REPO_URL = "https://huggingface.co/datasets/botsi/trust-game-llama-2-7b-chat"
|
| 12 |
DATASET_REPO_ID = "botsi/trust-game-llama-2-7b-chat"
|
| 13 |
DATA_FILENAME = "history_trust-game-llama-2-7b-chat.csv"
|
|
|
|
| 172 |
queue=False
|
| 173 |
)
|
| 174 |
|
| 175 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|