Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,6 +3,18 @@ import time
|
|
| 3 |
import random
|
| 4 |
import json
|
| 5 |
import mysql.connector
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
def fetch_personalized_data(session_index):
|
| 8 |
# Connect to the database
|
|
@@ -40,12 +52,21 @@ def fetch_personalized_data(session_index):
|
|
| 40 |
# Close the database connection
|
| 41 |
conn.close()
|
| 42 |
|
| 43 |
-
return [
|
| 44 |
|
| 45 |
except mysql.connector.Error as err:
|
| 46 |
print(f"Error: {err}")
|
| 47 |
return None
|
| 48 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
with gr.Blocks() as demo:
|
| 50 |
gr.Markdown("""## Gradio send queryparam to chatbot
|
| 51 |
type `read query`
|
|
@@ -96,7 +117,7 @@ with gr.Blocks() as demo:
|
|
| 96 |
fn=lambda x: x,
|
| 97 |
inputs=[url_params],
|
| 98 |
outputs=[url_params],
|
| 99 |
-
_js=get_window_url_params,
|
| 100 |
queue=False
|
| 101 |
)
|
| 102 |
|
|
|
|
| 3 |
import random
|
| 4 |
import json
|
| 5 |
import mysql.connector
|
| 6 |
+
import os
|
| 7 |
+
import csv
|
| 8 |
+
from datetime import datetime
|
| 9 |
+
from huggingface_hub import Repository, hf_hub_download
|
| 10 |
+
|
| 11 |
+
get_window_session_index = """
|
| 12 |
+
function() {
|
| 13 |
+
const urlParams = new URLSearchParams(window.location.search);
|
| 14 |
+
const session_index = urlParams.get('session_index');
|
| 15 |
+
return session_index;
|
| 16 |
+
}
|
| 17 |
+
"""
|
| 18 |
|
| 19 |
def fetch_personalized_data(session_index):
|
| 20 |
# Connect to the database
|
|
|
|
| 52 |
# Close the database connection
|
| 53 |
conn.close()
|
| 54 |
|
| 55 |
+
return [[str(row[0]), str(row[1]), str(row[2])] for row in rows] # Convert each row to a list
|
| 56 |
|
| 57 |
except mysql.connector.Error as err:
|
| 58 |
print(f"Error: {err}")
|
| 59 |
return None
|
| 60 |
|
| 61 |
+
def get_window_url_params():
|
| 62 |
+
return """
|
| 63 |
+
function() {
|
| 64 |
+
const params = new URLSearchParams(window.location.search);
|
| 65 |
+
const url_params = Object.fromEntries(params);
|
| 66 |
+
return url_params;
|
| 67 |
+
}
|
| 68 |
+
"""
|
| 69 |
+
|
| 70 |
with gr.Blocks() as demo:
|
| 71 |
gr.Markdown("""## Gradio send queryparam to chatbot
|
| 72 |
type `read query`
|
|
|
|
| 117 |
fn=lambda x: x,
|
| 118 |
inputs=[url_params],
|
| 119 |
outputs=[url_params],
|
| 120 |
+
_js=get_window_url_params(),
|
| 121 |
queue=False
|
| 122 |
)
|
| 123 |
|