Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -65,21 +65,28 @@ import urllib.request
|
|
65 |
import gradio as gr
|
66 |
from gradio import inputs, outputs
|
67 |
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
)
|
81 |
|
82 |
-
|
83 |
def main():
|
84 |
|
85 |
st.title("Text to Causal Knowledge Graph")
|
@@ -481,13 +488,22 @@ def main():
|
|
481 |
'target': col,
|
482 |
'value': int(df_tab.loc[row, col])
|
483 |
})
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
491 |
# Write JSON to file
|
492 |
#with open(DATA_FILE, 'w') as f: #w+
|
493 |
# with urllib.request.urlopen('https://huggingface.co/datasets/Seetha/visual_files/raw/main/level2.json') as response:
|
@@ -512,11 +528,12 @@ def main():
|
|
512 |
# st.write(commit_url)
|
513 |
|
514 |
# #return generate_html()
|
515 |
-
#
|
516 |
-
|
517 |
-
|
|
|
518 |
|
519 |
-
|
520 |
|
521 |
#f.truncate()
|
522 |
|
|
|
65 |
import gradio as gr
|
66 |
from gradio import inputs, outputs
|
67 |
|
68 |
+
feedback_file = Path("Seetha/Visualization") / f"level2.json"
|
69 |
+
feedback_folder = feedback_file.parent
|
70 |
+
# DATASET_REPO_URL = "https://huggingface.co/datasets/Seetha/Visualization"
|
71 |
+
# DATA_FILENAME = "level2.json"
|
72 |
+
# DATA_FILE = os.path.join("level2", DATA_FILENAME)
|
73 |
+
|
74 |
+
# HF_TOKEN = os.environ.get("HF_TOKEN")
|
75 |
+
# st.write("is none?", HF_TOKEN)
|
76 |
+
|
77 |
+
# st.write("hfh", huggingface_hub.__version__)
|
78 |
+
|
79 |
+
# repo = Repository(
|
80 |
+
# local_dir="level2", clone_from=DATASET_REPO_URL, use_auth_token=HF_TOKEN
|
81 |
+
# )
|
82 |
+
scheduler = CommitScheduler(
|
83 |
+
repo_id="Visualization",
|
84 |
+
repo_type="dataset",
|
85 |
+
folder_path=feedback_folder,
|
86 |
+
path_in_repo="level2",
|
87 |
+
every=10,
|
88 |
)
|
89 |
|
|
|
90 |
def main():
|
91 |
|
92 |
st.title("Text to Causal Knowledge Graph")
|
|
|
488 |
'target': col,
|
489 |
'value': int(df_tab.loc[row, col])
|
490 |
})
|
491 |
+
|
492 |
+
def save_feedback():
|
493 |
+
"""
|
494 |
+
Append input/outputs and user feedback to a JSON Lines file using a thread lock to avoid concurrent writes from different users.
|
495 |
+
"""
|
496 |
+
with scheduler.lock:
|
497 |
+
with feedback_file.open("w") as f:
|
498 |
+
json.dump(json_data, f)
|
499 |
+
#f.write(json.dumps({"input": input_text, "output_1": output_1, "output_2": output_2, "user_choice": user_choice}))
|
500 |
+
# f.write("\n")
|
501 |
+
|
502 |
+
# dataset = load_dataset("Seetha/Visualization")
|
503 |
+
# st.write(dataset)
|
504 |
+
# with open(DATA_FILE,'w') as f:
|
505 |
+
# json.dump(json_data, f)
|
506 |
+
#repo.push_to_hub()
|
507 |
# Write JSON to file
|
508 |
#with open(DATA_FILE, 'w') as f: #w+
|
509 |
# with urllib.request.urlopen('https://huggingface.co/datasets/Seetha/visual_files/raw/main/level2.json') as response:
|
|
|
528 |
# st.write(commit_url)
|
529 |
|
530 |
# #return generate_html()
|
531 |
+
#with gr.Blocks() as demo:
|
532 |
+
iface = gr.Interface(
|
533 |
+
save_feedback()
|
534 |
+
)
|
535 |
|
536 |
+
iface.launch()
|
537 |
|
538 |
#f.truncate()
|
539 |
|