corrections save annotations
Browse files- annotations_export.csv +1 -0
- app.py +30 -2
annotations_export.csv
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
user_id,gender,audio_file,score
|
app.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import pandas as pd
|
| 3 |
import os
|
|
@@ -9,6 +10,7 @@ from huggingface_hub import login
|
|
| 9 |
# CONFIGURATION
|
| 10 |
# ============================
|
| 11 |
|
|
|
|
| 12 |
AUDIO_FOLDER = "audio_files"
|
| 13 |
audio_files = sorted(os.listdir(AUDIO_FOLDER))
|
| 14 |
|
|
@@ -18,8 +20,8 @@ ADMIN_PASSWORD_HASH = "eb32da077dfaf326cd6f73e0716b628da6427aa318a2d0b9fafa9ef31
|
|
| 18 |
# HF DATASET CONFIGURATION
|
| 19 |
# ============================
|
| 20 |
|
| 21 |
-
HF_DATASET_NAME = "
|
| 22 |
-
HF_TOKEN = os.environ.get("
|
| 23 |
login(HF_TOKEN)
|
| 24 |
|
| 25 |
# ============================
|
|
@@ -39,6 +41,31 @@ def load_hf_dataset():
|
|
| 39 |
|
| 40 |
def submit_annotation_hf(user_id, gender, score, audio_file):
|
| 41 |
"""Append annotation to HF Dataset."""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
ds = load_hf_dataset()
|
| 43 |
new_row = pd.DataFrame([{
|
| 44 |
"user_id": user_id,
|
|
@@ -49,6 +76,7 @@ def submit_annotation_hf(user_id, gender, score, audio_file):
|
|
| 49 |
ds_new = Dataset.from_pandas(new_row)
|
| 50 |
ds_combined = concatenate_datasets([ds, ds_new])
|
| 51 |
ds_combined.push_to_hub(HF_DATASET_NAME)
|
|
|
|
| 52 |
|
| 53 |
def load_next_audio(state):
|
| 54 |
if state is None:
|
|
|
|
| 1 |
+
from huggingface_hub import HfApi
|
| 2 |
import gradio as gr
|
| 3 |
import pandas as pd
|
| 4 |
import os
|
|
|
|
| 10 |
# CONFIGURATION
|
| 11 |
# ============================
|
| 12 |
|
| 13 |
+
LOCAL_CSV = "annotations.csv"
|
| 14 |
AUDIO_FOLDER = "audio_files"
|
| 15 |
audio_files = sorted(os.listdir(AUDIO_FOLDER))
|
| 16 |
|
|
|
|
| 20 |
# HF DATASET CONFIGURATION
|
| 21 |
# ============================
|
| 22 |
|
| 23 |
+
HF_DATASET_NAME = "PaulineDV/TTS_annotations_data" # replace with your HF dataset
|
| 24 |
+
HF_TOKEN = os.environ.get("MyJulySecretToken") # store your token as a secret in Spaces
|
| 25 |
login(HF_TOKEN)
|
| 26 |
|
| 27 |
# ============================
|
|
|
|
| 41 |
|
| 42 |
def submit_annotation_hf(user_id, gender, score, audio_file):
|
| 43 |
"""Append annotation to HF Dataset."""
|
| 44 |
+
row = pd.DataFrame([{
|
| 45 |
+
"user_id": user_id,
|
| 46 |
+
"gender": gender,
|
| 47 |
+
"audio_file": audio_file,
|
| 48 |
+
"score": score
|
| 49 |
+
}])
|
| 50 |
+
|
| 51 |
+
if os.path.exists(LOCAL_CSV):
|
| 52 |
+
df = pd.read_csv(LOCAL_CSV)
|
| 53 |
+
df = pd.concat([df, row], ignore_index = True)
|
| 54 |
+
else:
|
| 55 |
+
df = row
|
| 56 |
+
|
| 57 |
+
df.to_csv(LOCAL_CSV, index = False)
|
| 58 |
+
|
| 59 |
+
api = HfApi()
|
| 60 |
+
|
| 61 |
+
api.upload_file(
|
| 62 |
+
path_or_fileobj=LOCAL_CSV,
|
| 63 |
+
path_in_repo="annotations.csv",
|
| 64 |
+
repo_id="HF_DATASET_NAME",
|
| 65 |
+
repo_type="dataset"
|
| 66 |
+
)
|
| 67 |
+
|
| 68 |
+
"""
|
| 69 |
ds = load_hf_dataset()
|
| 70 |
new_row = pd.DataFrame([{
|
| 71 |
"user_id": user_id,
|
|
|
|
| 76 |
ds_new = Dataset.from_pandas(new_row)
|
| 77 |
ds_combined = concatenate_datasets([ds, ds_new])
|
| 78 |
ds_combined.push_to_hub(HF_DATASET_NAME)
|
| 79 |
+
"""
|
| 80 |
|
| 81 |
def load_next_audio(state):
|
| 82 |
if state is None:
|