Spaces:
Running
on
A10G
Running
on
A10G
tested huggingface dataset
Browse files- .gitignore +1 -1
- app.py +34 -0
- example.py +47 -0
- feedback_dataset/feedback-20250217_212246.json +0 -0
- feedback_dataset/feedback-20250217_212401.json +10 -0
.gitignore
CHANGED
@@ -174,5 +174,5 @@ tool_cache/
|
|
174 |
detected_objects/
|
175 |
|
176 |
# [Gradio]
|
177 |
-
|
178 |
backups/
|
|
|
174 |
detected_objects/
|
175 |
|
176 |
# [Gradio]
|
177 |
+
demo_solver_cache/
|
178 |
backups/
|
app.py
CHANGED
@@ -25,6 +25,40 @@ from octotools.models.utils import make_json_serializable
|
|
25 |
from utils import save_feedback
|
26 |
|
27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
class Solver:
|
29 |
def __init__(
|
30 |
self,
|
|
|
25 |
from utils import save_feedback
|
26 |
|
27 |
|
28 |
+
########### Test Huggingface Dataset ###########
|
29 |
+
from pathlib import Path
|
30 |
+
from huggingface_hub import CommitScheduler
|
31 |
+
|
32 |
+
# Add these near the top of the file with other constants
|
33 |
+
DATASET_DIR = Path("feedback_dataset")
|
34 |
+
DATASET_DIR.mkdir(parents=True, exist_ok=True)
|
35 |
+
DATASET_PATH = DATASET_DIR / f"feedback-{time.strftime('%Y%m%d_%H%M%S')}.json"
|
36 |
+
|
37 |
+
# Get Huggingface token from environment variable
|
38 |
+
HF_TOKEN = os.getenv("HUGGINGFACE_TOKEN")
|
39 |
+
|
40 |
+
scheduler = CommitScheduler(
|
41 |
+
repo_id="lupantech/OctoTools-Gradio-Demo-User-Data",
|
42 |
+
repo_type="dataset",
|
43 |
+
folder_path=DATASET_DIR,
|
44 |
+
path_in_repo="data",
|
45 |
+
token=HF_TOKEN
|
46 |
+
)
|
47 |
+
|
48 |
+
def save_feedback(root_cache_dir: str, feedback_type: str, comment: str = None) -> None:
|
49 |
+
"""Save user feedback to Huggingface dataset"""
|
50 |
+
with scheduler.lock:
|
51 |
+
with DATASET_PATH.open("a") as f:
|
52 |
+
feedback_data = {
|
53 |
+
"query_id": os.path.basename(root_cache_dir),
|
54 |
+
"feedback_type": feedback_type,
|
55 |
+
"comment": comment,
|
56 |
+
"datetime": time.strftime("%Y%m%d_%H%M%S")
|
57 |
+
}
|
58 |
+
json.dump(feedback_data, f)
|
59 |
+
f.write("\n")
|
60 |
+
########### End of Test Huggingface Dataset ###########
|
61 |
+
|
62 |
class Solver:
|
63 |
def __init__(
|
64 |
self,
|
example.py
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
from datetime import datetime
|
3 |
+
from pathlib import Path
|
4 |
+
from uuid import uuid4
|
5 |
+
|
6 |
+
import gradio as gr
|
7 |
+
|
8 |
+
from huggingface_hub import CommitScheduler
|
9 |
+
|
10 |
+
|
11 |
+
JSON_DATASET_DIR = Path("json_dataset")
|
12 |
+
JSON_DATASET_DIR.mkdir(parents=True, exist_ok=True)
|
13 |
+
|
14 |
+
JSON_DATASET_PATH = JSON_DATASET_DIR / f"train-{uuid4()}.json"
|
15 |
+
|
16 |
+
scheduler = CommitScheduler(
|
17 |
+
repo_id="example-space-to-dataset-json",
|
18 |
+
repo_type="dataset",
|
19 |
+
folder_path=JSON_DATASET_DIR,
|
20 |
+
path_in_repo="data",
|
21 |
+
)
|
22 |
+
|
23 |
+
|
24 |
+
def greet(name: str) -> str:
|
25 |
+
return "Hello " + name + "!"
|
26 |
+
|
27 |
+
|
28 |
+
def save_json(name: str, greetings: str) -> None:
|
29 |
+
with scheduler.lock:
|
30 |
+
with JSON_DATASET_PATH.open("a") as f:
|
31 |
+
json.dump({"name": name, "greetings": greetings, "datetime": datetime.now().isoformat()}, f)
|
32 |
+
f.write("\n")
|
33 |
+
|
34 |
+
|
35 |
+
with gr.Blocks() as demo:
|
36 |
+
with gr.Row():
|
37 |
+
greet_name = gr.Textbox(label="Name")
|
38 |
+
greet_output = gr.Textbox(label="Greetings")
|
39 |
+
greet_btn = gr.Button("Greet")
|
40 |
+
greet_btn.click(fn=greet, inputs=greet_name, outputs=greet_output).success(
|
41 |
+
fn=save_json,
|
42 |
+
inputs=[greet_name, greet_output],
|
43 |
+
outputs=None,
|
44 |
+
)
|
45 |
+
|
46 |
+
|
47 |
+
demo.launch()
|
feedback_dataset/feedback-20250217_212246.json
ADDED
File without changes
|
feedback_dataset/feedback-20250217_212401.json
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{"query_id": "20250217_212439_f48ed6ff", "feedback_type": "upvote", "comment": null, "datetime": "20250217_212450"}
|
2 |
+
{"query_id": "20250217_212439_f48ed6ff", "feedback_type": "upvote", "comment": null, "datetime": "20250217_212452"}
|
3 |
+
{"query_id": "20250217_212439_f48ed6ff", "feedback_type": "It is good!", "comment": null, "datetime": "20250217_212459"}
|
4 |
+
{"query_id": "20250217_212439_f48ed6ff", "feedback_type": "upvote", "comment": null, "datetime": "20250217_212523"}
|
5 |
+
{"query_id": "20250217_212439_f48ed6ff", "feedback_type": "upvote", "comment": null, "datetime": "20250217_212524"}
|
6 |
+
{"query_id": "20250217_212439_f48ed6ff", "feedback_type": "upvote", "comment": null, "datetime": "20250217_212524"}
|
7 |
+
{"query_id": "20250217_212439_f48ed6ff", "feedback_type": "downvote", "comment": null, "datetime": "20250217_212524"}
|
8 |
+
{"query_id": "20250217_212439_f48ed6ff", "feedback_type": "It is good!", "comment": null, "datetime": "20250217_212526"}
|
9 |
+
{"query_id": "20250217_212439_f48ed6ff", "feedback_type": "upvote", "comment": null, "datetime": "20250217_212619"}
|
10 |
+
{"query_id": "20250217_212439_f48ed6ff", "feedback_type": "It is good!", "comment": null, "datetime": "20250217_212650"}
|