Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -51,8 +51,26 @@ json_result = fetch_data_as_json()
|
|
| 51 |
# Print or use the json_result variable as needed
|
| 52 |
print(json_result)
|
| 53 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
# Connect to the database
|
| 57 |
conn = mysql.connector.connect(
|
| 58 |
host="18.153.94.89",
|
|
@@ -91,7 +109,7 @@ def fetch_personalized_data():
|
|
| 91 |
{core_table}.playerNr = {decisions_table}.playerNr AND
|
| 92 |
{core_table}.groupNr = {decisions_table}.groupNr AND
|
| 93 |
{core_table}.subjectNr = {decisions_table}.subjectNr
|
| 94 |
-
WHERE {
|
| 95 |
"""
|
| 96 |
cursor.execute(query)
|
| 97 |
|
|
@@ -120,44 +138,16 @@ personalized_data = fetch_personalized_data()
|
|
| 120 |
print(personalized_data)
|
| 121 |
|
| 122 |
|
| 123 |
-
'''
|
| 124 |
-
# Fetch the results
|
| 125 |
-
results = cursor.fetchall()
|
| 126 |
-
|
| 127 |
-
# Process the results as needed
|
| 128 |
-
for row in results:
|
| 129 |
-
print(row)
|
| 130 |
-
|
| 131 |
-
# Close the cursor and connection when done
|
| 132 |
-
cursor.close()
|
| 133 |
-
conn.close()
|
| 134 |
-
|
| 135 |
-
return results
|
| 136 |
-
'''
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
get_window_url_params = """
|
| 150 |
-
function() {
|
| 151 |
-
const params = new URLSearchParams(window.location.search);
|
| 152 |
-
const url_params = Object.fromEntries(params);
|
| 153 |
-
return url_params;
|
| 154 |
-
}
|
| 155 |
-
"""
|
| 156 |
-
|
| 157 |
with gr.Blocks() as demo:
|
| 158 |
gr.Markdown("""## Gradio send queryparam to chatbot
|
| 159 |
type `read query`
|
| 160 |
""")
|
|
|
|
|
|
|
| 161 |
url_params = gr.JSON({}, visible=False, label="URL Params")
|
| 162 |
chatbot = gr.Chatbot().style(height=500)
|
| 163 |
msg = gr.Textbox()
|
|
@@ -191,4 +181,29 @@ type `read query`
|
|
| 191 |
queue=False
|
| 192 |
)
|
| 193 |
|
| 194 |
-
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
# Print or use the json_result variable as needed
|
| 52 |
print(json_result)
|
| 53 |
|
| 54 |
+
get_window_url_params = """
|
| 55 |
+
function() {
|
| 56 |
+
const params = new URLSearchParams(window.location.search);
|
| 57 |
+
const url_params = Object.fromEntries(params);
|
| 58 |
+
return url_params;
|
| 59 |
+
}
|
| 60 |
+
"""
|
| 61 |
|
| 62 |
+
get_window_session_index = """
|
| 63 |
+
function() {
|
| 64 |
+
const urlParams = new URLSearchParams(window.location.search);
|
| 65 |
+
const session_index = urlParams.get('session_index');
|
| 66 |
+
return session_index;
|
| 67 |
+
}
|
| 68 |
+
"""
|
| 69 |
+
|
| 70 |
+
# get url params out of JavaScript function as variables and pass the session_index to fetch_personalized_data() function
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
def fetch_personalized_data(session_index):
|
| 74 |
# Connect to the database
|
| 75 |
conn = mysql.connector.connect(
|
| 76 |
host="18.153.94.89",
|
|
|
|
| 109 |
{core_table}.playerNr = {decisions_table}.playerNr AND
|
| 110 |
{core_table}.groupNr = {decisions_table}.groupNr AND
|
| 111 |
{core_table}.subjectNr = {decisions_table}.subjectNr
|
| 112 |
+
WHERE {core_table}.session_index = '{session_index}'
|
| 113 |
"""
|
| 114 |
cursor.execute(query)
|
| 115 |
|
|
|
|
| 138 |
print(personalized_data)
|
| 139 |
|
| 140 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 145 |
with gr.Blocks() as demo:
|
| 146 |
gr.Markdown("""## Gradio send queryparam to chatbot
|
| 147 |
type `read query`
|
| 148 |
""")
|
| 149 |
+
session_index = url_params.get('session_index')
|
| 150 |
+
personalized_data = fetch_personalized_data(session_index)
|
| 151 |
url_params = gr.JSON({}, visible=False, label="URL Params")
|
| 152 |
chatbot = gr.Chatbot().style(height=500)
|
| 153 |
msg = gr.Textbox()
|
|
|
|
| 181 |
queue=False
|
| 182 |
)
|
| 183 |
|
| 184 |
+
demo.launch()
|
| 185 |
+
|
| 186 |
+
|
| 187 |
+
|
| 188 |
+
|
| 189 |
+
|
| 190 |
+
|
| 191 |
+
|
| 192 |
+
|
| 193 |
+
|
| 194 |
+
'''
|
| 195 |
+
WHERE {decisions_table}.session_index = '{session_index}'
|
| 196 |
+
|
| 197 |
+
# Fetch the results
|
| 198 |
+
results = cursor.fetchall()
|
| 199 |
+
|
| 200 |
+
# Process the results as needed
|
| 201 |
+
for row in results:
|
| 202 |
+
print(row)
|
| 203 |
+
|
| 204 |
+
# Close the cursor and connection when done
|
| 205 |
+
cursor.close()
|
| 206 |
+
conn.close()
|
| 207 |
+
|
| 208 |
+
return results
|
| 209 |
+
'''
|