Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,9 +5,30 @@ import os
|
|
| 5 |
import threading
|
| 6 |
import pandas as pd
|
| 7 |
from datasets import load_dataset
|
|
|
|
|
|
|
| 8 |
|
| 9 |
-
#
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
data_lock = threading.Lock()
|
| 12 |
|
| 13 |
def initialize_global_data():
|
|
@@ -26,22 +47,28 @@ def initialize_global_data():
|
|
| 26 |
if "text" not in data.columns:
|
| 27 |
data["text"] = ""
|
| 28 |
data.to_csv(DATA_FILE, index=False)
|
|
|
|
| 29 |
return data
|
| 30 |
else:
|
|
|
|
| 31 |
with data_lock:
|
| 32 |
df = pd.read_csv(DATA_FILE)
|
| 33 |
return df
|
| 34 |
|
| 35 |
def load_global_data():
|
| 36 |
"""CSV ํ์ผ์์ global_data DataFrame์ ์ฝ์ด์ต๋๋ค."""
|
|
|
|
| 37 |
with data_lock:
|
| 38 |
df = pd.read_csv(DATA_FILE)
|
| 39 |
return df
|
| 40 |
|
| 41 |
def save_global_data(df):
|
| 42 |
-
"""DataFrame์ CSV ํ์ผ์
|
| 43 |
with data_lock:
|
| 44 |
df.to_csv(DATA_FILE, index=False)
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
# CSV ํ์ผ์ ์ ์ฅ๋ global_data ์ด๊ธฐํ
|
| 47 |
global_data = initialize_global_data()
|
|
@@ -301,4 +328,4 @@ with gr.Blocks() as demo:
|
|
| 301 |
start_button.click(fn=stream_human_message, outputs=human_bubble)
|
| 302 |
submit_button.click(fn=submit_edit, inputs=edited_text_input, outputs=[human_bubble, ai_bubble])
|
| 303 |
|
| 304 |
-
demo.launch()
|
|
|
|
| 5 |
import threading
|
| 6 |
import pandas as pd
|
| 7 |
from datasets import load_dataset
|
| 8 |
+
import huggingface_hub
|
| 9 |
+
from huggingface_hub import Repository
|
| 10 |
|
| 11 |
+
# --- ๋ฐ์ดํฐ ์ฐ๊ฒฐ ๊ด๋ จ ์์ ---
|
| 12 |
+
# ๋ฐ์ดํฐ ํ์ผ๊ณผ ์ ์ฅํ ํด๋, ๊ทธ๋ฆฌ๊ณ Hugging Face Datasets repository URL์ ์ ์ํฉ๋๋ค.
|
| 13 |
+
DATA_FILENAME = "global_data.csv"
|
| 14 |
+
DATA_DIR = "data"
|
| 15 |
+
DATA_FILE = os.path.join(DATA_DIR, DATA_FILENAME)
|
| 16 |
+
# ์๋ URL์ ์ฐธ๊ณ ์ฉ์
๋๋ค. ๋ณธ์ธ์ repository URL๋ก ๋ณ๊ฒฝํ์ธ์.
|
| 17 |
+
DATASET_REPO_URL = "https://huggingface.co/datasets/gaeunseo/Interface1"
|
| 18 |
+
|
| 19 |
+
# ๋ฐ์ดํฐ ํด๋๊ฐ ์์ผ๋ฉด ์์ฑํฉ๋๋ค.
|
| 20 |
+
os.makedirs(DATA_DIR, exist_ok=True)
|
| 21 |
+
|
| 22 |
+
HF_TOKEN = os.environ.get("HF_TOKEN")
|
| 23 |
+
|
| 24 |
+
# Repository ๊ฐ์ฒด๋ฅผ ์์ฑํ์ฌ ๋ก์ปฌ ํด๋์ Hugging Face repo๋ฅผ ์ฐ๊ฒฐํฉ๋๋ค.
|
| 25 |
+
repo = Repository(
|
| 26 |
+
local_dir=DATA_DIR,
|
| 27 |
+
clone_from=DATASET_REPO_URL,
|
| 28 |
+
use_auth_token=HF_TOKEN
|
| 29 |
+
)
|
| 30 |
+
|
| 31 |
+
# ๋์ ์ ๊ทผ์ ์ํ Lock ์ ์ธ
|
| 32 |
data_lock = threading.Lock()
|
| 33 |
|
| 34 |
def initialize_global_data():
|
|
|
|
| 47 |
if "text" not in data.columns:
|
| 48 |
data["text"] = ""
|
| 49 |
data.to_csv(DATA_FILE, index=False)
|
| 50 |
+
repo.push_to_hub() # ์ CSV ํ์ผ์ Hugging Face repo์ ์
๋ก๋ํฉ๋๋ค.
|
| 51 |
return data
|
| 52 |
else:
|
| 53 |
+
repo.git_pull() # ์ต์ ๋ฐ์ดํฐ๋ก ์
๋ฐ์ดํธํฉ๋๋ค.
|
| 54 |
with data_lock:
|
| 55 |
df = pd.read_csv(DATA_FILE)
|
| 56 |
return df
|
| 57 |
|
| 58 |
def load_global_data():
|
| 59 |
"""CSV ํ์ผ์์ global_data DataFrame์ ์ฝ์ด์ต๋๋ค."""
|
| 60 |
+
repo.git_pull() # ์ต์ ๋ณ๊ฒฝ์ฌํญ์ ๋ฐ์ํฉ๋๋ค.
|
| 61 |
with data_lock:
|
| 62 |
df = pd.read_csv(DATA_FILE)
|
| 63 |
return df
|
| 64 |
|
| 65 |
def save_global_data(df):
|
| 66 |
+
"""DataFrame์ CSV ํ์ผ์ ์ ์ฅํ๊ณ Hugging Face repo์ ์
๋ก๋ํฉ๋๋ค."""
|
| 67 |
with data_lock:
|
| 68 |
df.to_csv(DATA_FILE, index=False)
|
| 69 |
+
repo.push_to_hub() # ์
๋ฐ์ดํธ๋ ํ์ผ์ ํธ์ํฉ๋๋ค.
|
| 70 |
+
# --- ๋ฐ์ดํฐ ์ฐ๊ฒฐ ๊ด๋ จ ์์ ๋ ---
|
| 71 |
+
|
| 72 |
|
| 73 |
# CSV ํ์ผ์ ์ ์ฅ๋ global_data ์ด๊ธฐํ
|
| 74 |
global_data = initialize_global_data()
|
|
|
|
| 328 |
start_button.click(fn=stream_human_message, outputs=human_bubble)
|
| 329 |
submit_button.click(fn=submit_edit, inputs=edited_text_input, outputs=[human_bubble, ai_bubble])
|
| 330 |
|
| 331 |
+
demo.launch()
|