Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,44 +4,39 @@ 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("
|
| 12 |
JSON_DATASET_DIR.mkdir(parents=True, exist_ok=True)
|
| 13 |
|
| 14 |
-
|
|
|
|
| 15 |
|
|
|
|
| 16 |
scheduler = CommitScheduler(
|
| 17 |
-
repo_id="
|
| 18 |
repo_type="dataset",
|
| 19 |
-
folder_path=JSON_DATASET_DIR,
|
| 20 |
-
path_in_repo="data",
|
| 21 |
)
|
| 22 |
|
| 23 |
-
|
| 24 |
-
def
|
| 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(
|
|
|
|
|
|
|
| 32 |
f.write("\n")
|
|
|
|
| 33 |
|
| 34 |
-
|
| 35 |
with gr.Blocks() as demo:
|
| 36 |
with gr.Row():
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
fn=save_json,
|
| 42 |
-
inputs=[greet_name, greet_output],
|
| 43 |
-
outputs=None,
|
| 44 |
-
)
|
| 45 |
-
|
| 46 |
|
| 47 |
-
demo.launch()
|
|
|
|
| 4 |
from uuid import uuid4
|
| 5 |
|
| 6 |
import gradio as gr
|
|
|
|
| 7 |
from huggingface_hub import CommitScheduler
|
| 8 |
|
| 9 |
+
# Setup the directory for saving data
|
| 10 |
+
JSON_DATASET_DIR = Path("feedback_dataset")
|
| 11 |
JSON_DATASET_DIR.mkdir(parents=True, exist_ok=True)
|
| 12 |
|
| 13 |
+
# Define a unique file name
|
| 14 |
+
JSON_DATASET_PATH = JSON_DATASET_DIR / f"feedback-{uuid4()}.json"
|
| 15 |
|
| 16 |
+
# Scheduler configuration for your dataset repo
|
| 17 |
scheduler = CommitScheduler(
|
| 18 |
+
repo_id="Utsav2001/Feedback", # Your dataset repo
|
| 19 |
repo_type="dataset",
|
| 20 |
+
folder_path=JSON_DATASET_DIR, # Local directory to sync
|
| 21 |
+
path_in_repo="data", # Path in the dataset repository
|
| 22 |
)
|
| 23 |
|
| 24 |
+
# Function to save data
|
| 25 |
+
def save_feedback(name: str, feedback: str) -> None:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
with scheduler.lock:
|
| 27 |
with JSON_DATASET_PATH.open("a") as f:
|
| 28 |
+
json.dump(
|
| 29 |
+
{"name": name, "feedback": feedback, "datetime": datetime.now().isoformat()}, f
|
| 30 |
+
)
|
| 31 |
f.write("\n")
|
| 32 |
+
scheduler.push_to_hub(commit_message="Add new feedback")
|
| 33 |
|
| 34 |
+
# Gradio Interface
|
| 35 |
with gr.Blocks() as demo:
|
| 36 |
with gr.Row():
|
| 37 |
+
name_input = gr.Textbox(label="Name")
|
| 38 |
+
feedback_input = gr.Textbox(label="Feedback")
|
| 39 |
+
submit_button = gr.Button("Submit")
|
| 40 |
+
submit_button.click(fn=save_feedback, inputs=[name_input, feedback_input], outputs=None)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
+
demo.launch()
|