Utsav2001 commited on
Commit
0174719
Β·
verified Β·
1 Parent(s): d37c510

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -25
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("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()
 
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()