Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,34 +8,23 @@ import csv
|
|
| 8 |
from datetime import datetime
|
| 9 |
from huggingface_hub import Repository, hf_hub_download
|
| 10 |
|
| 11 |
-
session_index = None
|
| 12 |
-
|
| 13 |
-
get_window_url_params = """
|
| 14 |
-
function() {
|
| 15 |
-
const params = new URLSearchParams(window.location.search);
|
| 16 |
-
const url_params = Object.fromEntries(params);
|
| 17 |
-
return url_params;
|
| 18 |
-
}
|
| 19 |
-
"""
|
| 20 |
-
|
| 21 |
-
get_window_session_index = """
|
| 22 |
-
function() {
|
| 23 |
-
const urlParams = new URLSearchParams(window.location.search);
|
| 24 |
-
const session_index = urlParams.get('session_index');
|
| 25 |
-
return session_index;
|
| 26 |
-
}
|
| 27 |
-
"""
|
| 28 |
-
|
| 29 |
-
session_index = gr.JSON({}, visible=False, label="Session Index")
|
| 30 |
-
print_session_index = {json.dumps(session_index, indent=4)}
|
| 31 |
-
print(print_session_index)
|
| 32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
DATASET_REPO_URL = "https://huggingface.co/datasets/botsi/trust-game-llama-2-7b-chat"
|
| 34 |
DATASET_REPO_ID = "botsi/trust-game-llama-2-7b-chat"
|
| 35 |
DATA_FILENAME = "history_trust-game-llama-2-7b-chat.csv"
|
| 36 |
DATA_FILE = os.path.join("data", DATA_FILENAME)
|
| 37 |
HF_TOKEN = os.environ.get("HF_TOKEN")
|
| 38 |
|
|
|
|
| 39 |
# Initialize Hugging Face Dataset Repository
|
| 40 |
try:
|
| 41 |
hf_hub_download(
|
|
@@ -60,9 +49,34 @@ def store_message(name: str, message: str):
|
|
| 60 |
)
|
| 61 |
commit_url = repo.push_to_hub()
|
| 62 |
return generate_html()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
|
| 64 |
|
| 65 |
# get url params out of JavaScript function as variables and pass the session_index to fetch_personalized_data() function
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
|
| 67 |
with gr.Blocks() as demo:
|
| 68 |
gr.Markdown("""## Gradio send queryparam to chatbot
|
|
|
|
| 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 |
DATASET_REPO_URL = "https://huggingface.co/datasets/botsi/trust-game-llama-2-7b-chat"
|
| 22 |
DATASET_REPO_ID = "botsi/trust-game-llama-2-7b-chat"
|
| 23 |
DATA_FILENAME = "history_trust-game-llama-2-7b-chat.csv"
|
| 24 |
DATA_FILE = os.path.join("data", DATA_FILENAME)
|
| 25 |
HF_TOKEN = os.environ.get("HF_TOKEN")
|
| 26 |
|
| 27 |
+
|
| 28 |
# Initialize Hugging Face Dataset Repository
|
| 29 |
try:
|
| 30 |
hf_hub_download(
|
|
|
|
| 49 |
)
|
| 50 |
commit_url = repo.push_to_hub()
|
| 51 |
return generate_html()
|
| 52 |
+
session_index = None
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
get_window_url_params = """
|
| 57 |
+
function() {
|
| 58 |
+
const params = new URLSearchParams(window.location.search);
|
| 59 |
+
const url_params = Object.fromEntries(params);
|
| 60 |
+
return url_params;
|
| 61 |
+
}
|
| 62 |
+
"""
|
| 63 |
+
|
| 64 |
+
get_window_session_index = """
|
| 65 |
+
function() {
|
| 66 |
+
const urlParams = new URLSearchParams(window.location.search);
|
| 67 |
+
const session_index = urlParams.get('session_index');
|
| 68 |
+
return session_index;
|
| 69 |
+
}
|
| 70 |
+
"""
|
| 71 |
|
| 72 |
|
| 73 |
# get url params out of JavaScript function as variables and pass the session_index to fetch_personalized_data() function
|
| 74 |
+
session_index = gr.JSON({}, visible=False, label="Session Index")
|
| 75 |
+
bot_message = f"""
|
| 76 |
+
{json.dumps(session_index, indent=4)}
|
| 77 |
+
"""
|
| 78 |
+
print(bot_message)
|
| 79 |
+
|
| 80 |
|
| 81 |
with gr.Blocks() as demo:
|
| 82 |
gr.Markdown("""## Gradio send queryparam to chatbot
|