Spaces:
Runtime error
Runtime error
Download app_json.py from r12kycyber/Storage_Cybery: direct link, hf CLI and curl.
- Browser
- Download file 1.14 kB
-
https://huggingface.co/spaces/r12kycyber/Storage_Cybery/resolve/e987d7bd7edbd84b1394106ca074c69f7b89354a/app_json.py
- Command line
-
hf download hf://spaces/r12kycyber/Storage_Cybery@e987d7bd7edbd84b1394106ca074c69f7b89354a/app_json.py
-
curl -L -o app_json.py https://huggingface.co/spaces/r12kycyber/Storage_Cybery/resolve/e987d7bd7edbd84b1394106ca074c69f7b89354a/app_json.py
1.14 kB
| import json | |
| from datetime import datetime | |
| from pathlib import Path | |
| from uuid import uuid4 | |
| import gradio as gr | |
| from huggingface_hub import CommitScheduler | |
| JSON_DATASET_DIR = Path("json_dataset") | |
| JSON_DATASET_DIR.mkdir(parents=True, exist_ok=True) | |
| JSON_DATASET_PATH = JSON_DATASET_DIR / f"train-{uuid4()}.json" | |
| scheduler = CommitScheduler( | |
| repo_id="example-commit-scheduler-json", | |
| repo_type="dataset", | |
| folder_path=JSON_DATASET_DIR, | |
| path_in_repo="data", | |
| ) | |
| def greet(name: str) -> str: | |
| return "Hello " + name + "!" | |
| def save_json(name: str, greetings: str) -> None: | |
| with scheduler.lock: | |
| with JSON_DATASET_PATH.open("a") as f: | |
| json.dump({"name": name, "greetings": greetings, "datetime": datetime.now().isoformat()}, f) | |
| f.write("\n") | |
| def get_demo(): | |
| with gr.Row(): | |
| greet_name = gr.Textbox(label="Name") | |
| greet_output = gr.Textbox(label="Greetings") | |
| greet_btn = gr.Button("Greet") | |
| greet_btn.click(fn=greet, inputs=greet_name, outputs=greet_output).success( | |
| fn=save_json, | |
| inputs=[greet_name, greet_output], | |
| outputs=None, | |
| ) | |