botsi commited on
Commit
9086d88
·
verified ·
1 Parent(s): 1566146

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +51 -53
app.py CHANGED
@@ -67,6 +67,52 @@ if torch.cuda.is_available():
67
  tokenizer = AutoTokenizer.from_pretrained(model_id)
68
  tokenizer.use_default_system_prompt = False
69
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
  def get_window_url_params():
71
  return """
72
  function() {
@@ -180,62 +226,14 @@ examples=[
180
 
181
  with gr.Blocks(css="style.css") as demo:
182
  ## gradio-chatbot-read-query-param
 
183
  url_params = gr.JSON({}, visible=False, label="URL Params")
184
  def get_session_index(url_params):
185
  session_index = url_params.get('session_index')
186
- return session_index
187
-
188
- session_index = get_session_index(url_params.value)
189
- print(session_index)
190
-
191
- def fetch_personalized_data(session_index):
192
- # Connect to the database
193
- conn = mysql.connector.connect(
194
- host="18.153.94.89",
195
- user="root",
196
- password="N12RXMKtKxRj",
197
- database="lionessdb"
198
- )
199
-
200
- # Create a cursor object
201
- cursor = conn.cursor()
202
-
203
- # Replace the placeholders with your actual database and table names
204
- core_table = "e5390g37096_core"
205
- decisions_table = "e5390g37096_decisions"
206
-
207
- # Query to fetch relevant data from both tables based on session_index
208
- query = f"""
209
- SELECT e5390g37096_core.playerNr,
210
- e5390g37096_core.groupNr,
211
- e5390g37096_core.subjectNr
212
- FROM e5390g37096_core
213
- JOIN e5390g37096_decisions ON
214
- e5390g37096_core.playerNr = e5390g37096_decisions.playerNr
215
- WHERE e5390g37096_decisions.session_index = '{session_index}'
216
- """
217
-
218
- try:
219
- cursor.execute(query)
220
-
221
- # Fetch all rows as lists of tuples
222
- rows = cursor.fetchall()
223
-
224
- # Close the database connection
225
- conn.close()
226
-
227
- # return [[str(row[0]), str(row[1]), str(row[2])] for row in rows] # Convert each row to a list
228
- # Convert the rows to a list of dictionaries
229
- data = [{'playerNr': row[0], 'groupNr': row[1], 'subjectNr': row[2]} for row in rows]
230
- print(data)
231
- return data
232
-
233
- except mysql.connector.Error as err:
234
- print(f"Error: {err}")
235
- return None
236
-
237
- personalized_data = fetch_personalized_data(session_index)
238
- print(personalized_data)
239
 
240
  ## trust-game-llama-2-7b-chat
241
  # app.py
 
67
  tokenizer = AutoTokenizer.from_pretrained(model_id)
68
  tokenizer.use_default_system_prompt = False
69
 
70
+ def fetch_personalized_data(session_index):
71
+ # Connect to the database
72
+ conn = mysql.connector.connect(
73
+ host="18.153.94.89",
74
+ user="root",
75
+ password="N12RXMKtKxRj",
76
+ database="lionessdb"
77
+ )
78
+
79
+ # Create a cursor object
80
+ cursor = conn.cursor()
81
+
82
+ # Replace the placeholders with your actual database and table names
83
+ core_table = "e5390g37096_core"
84
+ decisions_table = "e5390g37096_decisions"
85
+
86
+ # Query to fetch relevant data from both tables based on session_index
87
+ query = f"""
88
+ SELECT e5390g37096_core.playerNr,
89
+ e5390g37096_core.groupNr,
90
+ e5390g37096_core.subjectNr
91
+ FROM e5390g37096_core
92
+ JOIN e5390g37096_decisions ON
93
+ e5390g37096_core.playerNr = e5390g37096_decisions.playerNr
94
+ WHERE e5390g37096_decisions.session_index = '{session_index}'
95
+ """
96
+
97
+ try:
98
+ cursor.execute(query)
99
+
100
+ # Fetch all rows as lists of tuples
101
+ rows = cursor.fetchall()
102
+
103
+ # Close the database connection
104
+ conn.close()
105
+
106
+ # return [[str(row[0]), str(row[1]), str(row[2])] for row in rows] # Convert each row to a list
107
+ # Convert the rows to a list of dictionaries
108
+ data = [{'playerNr': row[0], 'groupNr': row[1], 'subjectNr': row[2]} for row in rows]
109
+ print(data)
110
+ return data
111
+
112
+ except mysql.connector.Error as err:
113
+ print(f"Error: {err}")
114
+ return None
115
+
116
  def get_window_url_params():
117
  return """
118
  function() {
 
226
 
227
  with gr.Blocks(css="style.css") as demo:
228
  ## gradio-chatbot-read-query-param
229
+ # session_index = 'eb3636167d3a63fbeee32934610e5b2f'
230
  url_params = gr.JSON({}, visible=False, label="URL Params")
231
  def get_session_index(url_params):
232
  session_index = url_params.get('session_index')
233
+ print(session_index)
234
+ personalized_data = fetch_personalized_data(session_index)
235
+ print(personalized_data)
236
+ return personalized_data
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
237
 
238
  ## trust-game-llama-2-7b-chat
239
  # app.py