Spaces:
Running
Running
jisubae
commited on
Commit
ยท
cd13f52
1
Parent(s):
5e8f045
fix: HF login error and future warning
Browse files- README.md +1 -0
- freshqa/fresheval_parallel.py +1 -1
- freshqa/freshqa_acc.py +1 -1
- requirements.txt +1 -1
- src/leaderboard_manager.py +14 -1
- src/quick_csv_loader.py +13 -1
- src/submission_handler.py +31 -32
- src/submission_tracker.py +77 -62
- ui/submission_tab.py +37 -3
README.md
CHANGED
|
@@ -7,6 +7,7 @@ sdk: gradio
|
|
| 7 |
app_file: app.py
|
| 8 |
pinned: false
|
| 9 |
license: apache-2.0
|
|
|
|
| 10 |
---
|
| 11 |
|
| 12 |
## Ko-FreshQA Leaderboard
|
|
|
|
| 7 |
app_file: app.py
|
| 8 |
pinned: false
|
| 9 |
license: apache-2.0
|
| 10 |
+
hf_oauth: true
|
| 11 |
---
|
| 12 |
|
| 13 |
## Ko-FreshQA Leaderboard
|
freshqa/fresheval_parallel.py
CHANGED
|
@@ -85,7 +85,7 @@ class FreshEvalParallel:
|
|
| 85 |
progress_queue.put(1)
|
| 86 |
|
| 87 |
total_time = time.time() - start_time
|
| 88 |
-
print(f"โ
{mode} ๋ชจ๋ ํ๊ฐ ์๋ฃ: {total_time:.1f}์ด ์์")
|
| 89 |
|
| 90 |
return pd.DataFrame(results)
|
| 91 |
|
|
|
|
| 85 |
progress_queue.put(1)
|
| 86 |
|
| 87 |
total_time = time.time() - start_time
|
| 88 |
+
# print(f"โ
{mode} ๋ชจ๋ ํ๊ฐ ์๋ฃ: {total_time:.1f}์ด ์์")
|
| 89 |
|
| 90 |
return pd.DataFrame(results)
|
| 91 |
|
freshqa/freshqa_acc.py
CHANGED
|
@@ -50,7 +50,7 @@ def process_freshqa_dataframe(df):
|
|
| 50 |
processed_df = df.copy()
|
| 51 |
processed_df['rating'] = 0 # ๊ธฐ๋ณธ๊ฐ์ผ๋ก 0 ์ค์
|
| 52 |
|
| 53 |
-
print(f"FreshQA ๋ฐ์ดํฐ ์ฒ๋ฆฌ ์๋ฃ: {len(processed_df)}๊ฐ ์ํ")
|
| 54 |
return processed_df
|
| 55 |
except Exception as e:
|
| 56 |
print(f"๋ฐ์ดํฐ ์ฒ๋ฆฌ ์ค ์ค๋ฅ ๋ฐ์: {e}")
|
|
|
|
| 50 |
processed_df = df.copy()
|
| 51 |
processed_df['rating'] = 0 # ๊ธฐ๋ณธ๊ฐ์ผ๋ก 0 ์ค์
|
| 52 |
|
| 53 |
+
# print(f"FreshQA ๋ฐ์ดํฐ ์ฒ๋ฆฌ ์๋ฃ: {len(processed_df)}๊ฐ ์ํ")
|
| 54 |
return processed_df
|
| 55 |
except Exception as e:
|
| 56 |
print(f"๋ฐ์ดํฐ ์ฒ๋ฆฌ ์ค ์ค๋ฅ ๋ฐ์: {e}")
|
requirements.txt
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
# Core dependencies for Hugging Face Spaces
|
| 2 |
-
gradio>=5.0.0
|
| 3 |
huggingface_hub<1.0.0
|
| 4 |
pandas>=2.0.0
|
| 5 |
numpy>=1.24.0
|
|
|
|
| 1 |
# Core dependencies for Hugging Face Spaces
|
| 2 |
+
gradio[oauth]>=5.0.0
|
| 3 |
huggingface_hub<1.0.0
|
| 4 |
pandas>=2.0.0
|
| 5 |
numpy>=1.24.0
|
src/leaderboard_manager.py
CHANGED
|
@@ -126,7 +126,20 @@ def append_to_leaderboard_data(new_data_list):
|
|
| 126 |
# ์๋ก์ด ๋ฐ์ดํฐ ์ถ๊ฐ
|
| 127 |
new_df = pd.DataFrame(new_data_list)
|
| 128 |
|
| 129 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 130 |
|
| 131 |
# ์ ๋ ฌ (accuracy ๊ธฐ์ค)
|
| 132 |
if not combined_df.empty and 'accuracy' in combined_df.columns:
|
|
|
|
| 126 |
# ์๋ก์ด ๋ฐ์ดํฐ ์ถ๊ฐ
|
| 127 |
new_df = pd.DataFrame(new_data_list)
|
| 128 |
|
| 129 |
+
# FutureWarning ๋ฐฉ์ง: ๋น DataFrame์ ์ ์ธํ๊ณ ๊ฒฐํฉ
|
| 130 |
+
frames_to_concat = []
|
| 131 |
+
if isinstance(existing_df, pd.DataFrame) and not existing_df.empty:
|
| 132 |
+
frames_to_concat.append(existing_df)
|
| 133 |
+
if isinstance(new_df, pd.DataFrame) and not new_df.empty:
|
| 134 |
+
frames_to_concat.append(new_df)
|
| 135 |
+
|
| 136 |
+
if len(frames_to_concat) == 0:
|
| 137 |
+
# ๋ ๋ค ๋น์ด์์ผ๋ฉด ๊ธฐ์กด ์คํค๋ง ์ ์ง
|
| 138 |
+
combined_df = existing_df.copy()
|
| 139 |
+
elif len(frames_to_concat) == 1:
|
| 140 |
+
combined_df = frames_to_concat[0].copy()
|
| 141 |
+
else:
|
| 142 |
+
combined_df = pd.concat(frames_to_concat, ignore_index=True)
|
| 143 |
|
| 144 |
# ์ ๋ ฌ (accuracy ๊ธฐ์ค)
|
| 145 |
if not combined_df.empty and 'accuracy' in combined_df.columns:
|
src/quick_csv_loader.py
CHANGED
|
@@ -90,7 +90,19 @@ def merge_with_leaderboard(new_results_df: pd.DataFrame,
|
|
| 90 |
existing_df = pd.read_csv(leaderboard_path)
|
| 91 |
|
| 92 |
# ๋ณํฉ
|
| 93 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
|
| 95 |
# ์ค๋ณต ์ ๊ฑฐ (๋์ผํ id์ evaluation_date ์กฐํฉ)
|
| 96 |
if 'id' in merged_df.columns and 'evaluation_date' in merged_df.columns:
|
|
|
|
| 90 |
existing_df = pd.read_csv(leaderboard_path)
|
| 91 |
|
| 92 |
# ๋ณํฉ
|
| 93 |
+
# FutureWarning ๋ฐฉ์ง: ๋น DataFrame ์ ์ธ ํ ๊ฒฐํฉ
|
| 94 |
+
frames_to_concat = []
|
| 95 |
+
if isinstance(existing_df, pd.DataFrame) and not existing_df.empty:
|
| 96 |
+
frames_to_concat.append(existing_df)
|
| 97 |
+
if isinstance(new_results_df, pd.DataFrame) and not new_results_df.empty:
|
| 98 |
+
frames_to_concat.append(new_results_df)
|
| 99 |
+
|
| 100 |
+
if len(frames_to_concat) == 0:
|
| 101 |
+
merged_df = existing_df.copy()
|
| 102 |
+
elif len(frames_to_concat) == 1:
|
| 103 |
+
merged_df = frames_to_concat[0].copy()
|
| 104 |
+
else:
|
| 105 |
+
merged_df = pd.concat(frames_to_concat, ignore_index=True)
|
| 106 |
|
| 107 |
# ์ค๋ณต ์ ๊ฑฐ (๋์ผํ id์ evaluation_date ์กฐํฉ)
|
| 108 |
if 'id' in merged_df.columns and 'evaluation_date' in merged_df.columns:
|
src/submission_handler.py
CHANGED
|
@@ -45,7 +45,6 @@ class SubmissionHandler:
|
|
| 45 |
self.tracker = tracker
|
| 46 |
self.cfg = cfg or Config
|
| 47 |
|
| 48 |
-
# ๊ธฐ์กด ์ฝ๋์ ํธํ๋๋ ์์ฑ (Config ์ง์ ์ฐธ์กฐ ์ ๊ฑฐ)
|
| 49 |
self.enable_limit = getattr(self.cfg, "ENABLE_SUBMISSION_LIMIT", False)
|
| 50 |
self.repo_id = getattr(self.cfg, "FRESHQA_DATA_REPO_ID", None)
|
| 51 |
self.filename = getattr(self.cfg, "FRESHQA_DATA_FILENAME", None)
|
|
@@ -174,11 +173,6 @@ class SubmissionHandler:
|
|
| 174 |
|
| 175 |
# --------- 6) ์์ฝ ----------
|
| 176 |
def _build_summary(self, name: str, relaxed_accs: dict, strict_accs: dict) -> str:
|
| 177 |
-
"""
|
| 178 |
-
result_summary๊ฐ ๊ธฐ๋ํ๋ ์ด์ ๋ฌธ์์ด ํฌ๋งท์ ๊ทธ๋๋ก ์ ์งํฉ๋๋ค.
|
| 179 |
-
- ํค๋/์น์
์ ๋ชฉ/์ค๋ฐ๊ฟ/ํํ(์์์ 1์๋ฆฌ) ๋์ผ
|
| 180 |
-
- ํ
์คํธ์
๊ธฐ์ค ์งํ: acc_test, *_fast_changing, *_two_hop, *_old, *_new, *_vp, *_fp
|
| 181 |
-
"""
|
| 182 |
submitter = name if name else "(์ด๋ฆ ๋ฏธ์
๋ ฅ)"
|
| 183 |
|
| 184 |
lines = []
|
|
@@ -224,7 +218,6 @@ class SubmissionHandler:
|
|
| 224 |
relaxed_table: pd.DataFrame,
|
| 225 |
strict_table: pd.DataFrame,
|
| 226 |
) -> str:
|
| 227 |
-
# ๋ณด๊ธฐ ์ข์ ํฌ๋งท์ผ๋ก ์ผ์ชฝ ์ ๋ ฌ/๊ตฌ๋ถ์ /์ฌ๋ฐฑ์ ์ ์ฉํด ๋ฌธ์์ด ๊ตฌ์ฑ
|
| 228 |
display_file = os.path.basename(file_name) if file_name else ""
|
| 229 |
lines: list[str] = []
|
| 230 |
lines.append("โ
์ ์ถ ๋ฐ ํ๊ฐ ์๋ฃ")
|
|
@@ -404,7 +397,6 @@ class SubmissionHandler:
|
|
| 404 |
except Exception as e:
|
| 405 |
print(f"โ ๏ธ ๋ฆฌ๋๋ณด๋ ์ ์ฅ ์คํจ: {e}")
|
| 406 |
|
| 407 |
-
|
| 408 |
# --------- 9) ๊ณต๊ฐ ์๋ํฌ์ธํธ(ํต์ฌ) ----------
|
| 409 |
def process_submission(
|
| 410 |
self,
|
|
@@ -412,7 +404,8 @@ class SubmissionHandler:
|
|
| 412 |
name: str,
|
| 413 |
submit_model: str,
|
| 414 |
submit_description: str,
|
| 415 |
-
|
|
|
|
| 416 |
) -> str:
|
| 417 |
"""
|
| 418 |
์ ์ถ ํ์ผ ์ฒ๋ฆฌ ๋ฐ ํ๊ฐ
|
|
@@ -428,12 +421,17 @@ class SubmissionHandler:
|
|
| 428 |
# 1) ์ ์ถ ์ ํ ํ์ธ
|
| 429 |
tracker: Optional[SubmissionTracker] = None
|
| 430 |
if self.enable_limit:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 431 |
tracker = self.tracker or get_submission_tracker()
|
| 432 |
if tracker is not None:
|
| 433 |
self.tracker = tracker
|
|
|
|
| 434 |
if self.enable_limit and tracker:
|
| 435 |
try:
|
| 436 |
-
can_submit, message, remaining = tracker.can_submit()
|
| 437 |
if not can_submit:
|
| 438 |
return f"โ ์ ์ถ ์ ํ: {message}"
|
| 439 |
except Exception as e:
|
|
@@ -469,11 +467,12 @@ class SubmissionHandler:
|
|
| 469 |
ev = self._evaluate_freshqa(merged_df, on_progress=on_inner_progress)
|
| 470 |
if not ev.ok:
|
| 471 |
# ์คํจ ๊ธฐ๋ก
|
| 472 |
-
if self.enable_limit and tracker:
|
| 473 |
try:
|
| 474 |
tracker.record_submission(
|
| 475 |
-
|
| 476 |
-
|
|
|
|
| 477 |
success=False,
|
| 478 |
error_message=ev.error or "ํ๊ฐ ์คํจ",
|
| 479 |
submit_model=normalized_model,
|
|
@@ -489,11 +488,12 @@ class SubmissionHandler:
|
|
| 489 |
progress(0.8, desc="ํ๊ฐ ๊ฒฐ๊ณผ ๋ถ์ ์ค...")
|
| 490 |
r = self._calculate_accuracy(relaxed_df)
|
| 491 |
if not r.ok:
|
| 492 |
-
if self.enable_limit and tracker:
|
| 493 |
try:
|
| 494 |
tracker.record_submission(
|
| 495 |
-
|
| 496 |
-
|
|
|
|
| 497 |
success=False,
|
| 498 |
error_message=r.error or "์ง๊ณ ์คํจ",
|
| 499 |
submit_model=normalized_model,
|
|
@@ -505,11 +505,12 @@ class SubmissionHandler:
|
|
| 505 |
|
| 506 |
s = self._calculate_accuracy(strict_df)
|
| 507 |
if not s.ok:
|
| 508 |
-
if self.enable_limit and tracker:
|
| 509 |
try:
|
| 510 |
tracker.record_submission(
|
| 511 |
-
|
| 512 |
-
|
|
|
|
| 513 |
success=False,
|
| 514 |
error_message=s.error or "์ง๊ณ ์คํจ",
|
| 515 |
submit_model=normalized_model,
|
|
@@ -536,15 +537,17 @@ class SubmissionHandler:
|
|
| 536 |
)
|
| 537 |
|
| 538 |
# 8) ์ ์ถ ์ฑ๊ณต ๊ธฐ๋ก ๋ฐ ๋ฆฌ๋๋ณด๋ ์ ์ฅ
|
| 539 |
-
if self.enable_limit and tracker:
|
| 540 |
progress(0.85, desc="์ ์ถ ๋ด์ญ ์ ์ฅ ์ค...")
|
| 541 |
save_ok = tracker.record_submission(
|
| 542 |
-
|
| 543 |
-
|
|
|
|
| 544 |
success=True,
|
| 545 |
submit_model=normalized_model,
|
| 546 |
submit_description=normalized_description,
|
| 547 |
)
|
|
|
|
| 548 |
progress(0.9, desc="๋ฆฌ๋๋ณด๋ ์
๋ฐ์ดํธ ์ค...")
|
| 549 |
self._save_leaderboard(name, normalized_model, normalized_description, relaxed_accs, strict_accs)
|
| 550 |
else:
|
|
@@ -563,7 +566,8 @@ def process_submission(
|
|
| 563 |
name: str,
|
| 564 |
submit_model: str,
|
| 565 |
submit_description: str,
|
| 566 |
-
|
|
|
|
| 567 |
) -> str:
|
| 568 |
"""
|
| 569 |
Gradio์์ ์ง์ ํธ์ถํ๋ ์ํธ๋ฆฌํฌ์ธํธ.
|
|
@@ -577,21 +581,16 @@ def process_submission(
|
|
| 577 |
name=name,
|
| 578 |
submit_model=submit_model,
|
| 579 |
submit_description=submit_description,
|
|
|
|
| 580 |
progress=progress,
|
| 581 |
)
|
| 582 |
except Exception as e:
|
| 583 |
# ์ต์์ ๋ณดํธ๋ง: ์์์น ๋ชปํ ์์ธ๋ ์ฌ์ฉ์ ์นํ์ ์ผ๋ก ๋ฐํ
|
| 584 |
try:
|
| 585 |
-
|
| 586 |
-
if handler.enable_limit and handler.tracker:
|
| 587 |
-
# ๋๊ฐ ์ ์ถํ๋์ง๋ tracker๊ฐ ์๊ณ ์๋ค๋ฉด ๊ธฐ๋ก
|
| 588 |
-
try:
|
| 589 |
-
tracking_user_id = handler.tracker.get_user_id()
|
| 590 |
-
except Exception:
|
| 591 |
-
tracking_user_id = None
|
| 592 |
-
if handler.enable_limit and handler.tracker:
|
| 593 |
handler.tracker.record_submission(
|
| 594 |
-
|
|
|
|
| 595 |
file_name=os.path.basename(file.name) if file else "(unknown)",
|
| 596 |
success=False,
|
| 597 |
error_message=str(e),
|
|
|
|
| 45 |
self.tracker = tracker
|
| 46 |
self.cfg = cfg or Config
|
| 47 |
|
|
|
|
| 48 |
self.enable_limit = getattr(self.cfg, "ENABLE_SUBMISSION_LIMIT", False)
|
| 49 |
self.repo_id = getattr(self.cfg, "FRESHQA_DATA_REPO_ID", None)
|
| 50 |
self.filename = getattr(self.cfg, "FRESHQA_DATA_FILENAME", None)
|
|
|
|
| 173 |
|
| 174 |
# --------- 6) ์์ฝ ----------
|
| 175 |
def _build_summary(self, name: str, relaxed_accs: dict, strict_accs: dict) -> str:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 176 |
submitter = name if name else "(์ด๋ฆ ๋ฏธ์
๋ ฅ)"
|
| 177 |
|
| 178 |
lines = []
|
|
|
|
| 218 |
relaxed_table: pd.DataFrame,
|
| 219 |
strict_table: pd.DataFrame,
|
| 220 |
) -> str:
|
|
|
|
| 221 |
display_file = os.path.basename(file_name) if file_name else ""
|
| 222 |
lines: list[str] = []
|
| 223 |
lines.append("โ
์ ์ถ ๋ฐ ํ๊ฐ ์๋ฃ")
|
|
|
|
| 397 |
except Exception as e:
|
| 398 |
print(f"โ ๏ธ ๋ฆฌ๋๋ณด๋ ์ ์ฅ ์คํจ: {e}")
|
| 399 |
|
|
|
|
| 400 |
# --------- 9) ๊ณต๊ฐ ์๋ํฌ์ธํธ(ํต์ฌ) ----------
|
| 401 |
def process_submission(
|
| 402 |
self,
|
|
|
|
| 404 |
name: str,
|
| 405 |
submit_model: str,
|
| 406 |
submit_description: str,
|
| 407 |
+
user_id: Optional[str] = None,
|
| 408 |
+
progress: gr.Progress = gr.Progress(),
|
| 409 |
) -> str:
|
| 410 |
"""
|
| 411 |
์ ์ถ ํ์ผ ์ฒ๋ฆฌ ๋ฐ ํ๊ฐ
|
|
|
|
| 421 |
# 1) ์ ์ถ ์ ํ ํ์ธ
|
| 422 |
tracker: Optional[SubmissionTracker] = None
|
| 423 |
if self.enable_limit:
|
| 424 |
+
# ๋ก๊ทธ์ธ ๊ธฐ๋ฐ ์ ์ถ ์ ์ฝ: user_id ์์ผ๋ฉด ๋ฐ๋ก ์๋ฌ
|
| 425 |
+
if not user_id:
|
| 426 |
+
return "โ HuggingFace ๋ก๊ทธ์ธ ์ํ์์๋ง ์ ์ถ ๊ฐ๋ฅํฉ๋๋ค. ๋จผ์ ๋ก๊ทธ์ธ ํ ๋ค์ ์๋ํด์ฃผ์ธ์."
|
| 427 |
+
|
| 428 |
tracker = self.tracker or get_submission_tracker()
|
| 429 |
if tracker is not None:
|
| 430 |
self.tracker = tracker
|
| 431 |
+
|
| 432 |
if self.enable_limit and tracker:
|
| 433 |
try:
|
| 434 |
+
can_submit, message, remaining = tracker.can_submit(user_id=user_id)
|
| 435 |
if not can_submit:
|
| 436 |
return f"โ ์ ์ถ ์ ํ: {message}"
|
| 437 |
except Exception as e:
|
|
|
|
| 467 |
ev = self._evaluate_freshqa(merged_df, on_progress=on_inner_progress)
|
| 468 |
if not ev.ok:
|
| 469 |
# ์คํจ ๊ธฐ๋ก
|
| 470 |
+
if self.enable_limit and tracker and user_id:
|
| 471 |
try:
|
| 472 |
tracker.record_submission(
|
| 473 |
+
user_id=user_id,
|
| 474 |
+
submitter_name=name,
|
| 475 |
+
file_name=os.path.basename(file.name),
|
| 476 |
success=False,
|
| 477 |
error_message=ev.error or "ํ๊ฐ ์คํจ",
|
| 478 |
submit_model=normalized_model,
|
|
|
|
| 488 |
progress(0.8, desc="ํ๊ฐ ๊ฒฐ๊ณผ ๋ถ์ ์ค...")
|
| 489 |
r = self._calculate_accuracy(relaxed_df)
|
| 490 |
if not r.ok:
|
| 491 |
+
if self.enable_limit and tracker and user_id:
|
| 492 |
try:
|
| 493 |
tracker.record_submission(
|
| 494 |
+
user_id=user_id,
|
| 495 |
+
submitter_name=name,
|
| 496 |
+
file_name=os.path.basename(file.name),
|
| 497 |
success=False,
|
| 498 |
error_message=r.error or "์ง๊ณ ์คํจ",
|
| 499 |
submit_model=normalized_model,
|
|
|
|
| 505 |
|
| 506 |
s = self._calculate_accuracy(strict_df)
|
| 507 |
if not s.ok:
|
| 508 |
+
if self.enable_limit and tracker and user_id:
|
| 509 |
try:
|
| 510 |
tracker.record_submission(
|
| 511 |
+
user_id=user_id,
|
| 512 |
+
submitter_name=name,
|
| 513 |
+
file_name=os.path.basename(file.name),
|
| 514 |
success=False,
|
| 515 |
error_message=s.error or "์ง๊ณ ์คํจ",
|
| 516 |
submit_model=normalized_model,
|
|
|
|
| 537 |
)
|
| 538 |
|
| 539 |
# 8) ์ ์ถ ์ฑ๊ณต ๊ธฐ๋ก ๋ฐ ๋ฆฌ๋๋ณด๋ ์ ์ฅ
|
| 540 |
+
if self.enable_limit and tracker and user_id:
|
| 541 |
progress(0.85, desc="์ ์ถ ๋ด์ญ ์ ์ฅ ์ค...")
|
| 542 |
save_ok = tracker.record_submission(
|
| 543 |
+
user_id=user_id,
|
| 544 |
+
submitter_name=name,
|
| 545 |
+
file_name=os.path.basename(file.name),
|
| 546 |
success=True,
|
| 547 |
submit_model=normalized_model,
|
| 548 |
submit_description=normalized_description,
|
| 549 |
)
|
| 550 |
+
# save_ok ์คํจํด๋ ํ๊ฐ ๊ฒฐ๊ณผ๋ ๋ฆฌ๋๋ณด๋์ ๋ฐ์
|
| 551 |
progress(0.9, desc="๋ฆฌ๋๋ณด๋ ์
๋ฐ์ดํธ ์ค...")
|
| 552 |
self._save_leaderboard(name, normalized_model, normalized_description, relaxed_accs, strict_accs)
|
| 553 |
else:
|
|
|
|
| 566 |
name: str,
|
| 567 |
submit_model: str,
|
| 568 |
submit_description: str,
|
| 569 |
+
user_id: Optional[str] = None,
|
| 570 |
+
progress: gr.Progress = gr.Progress(),
|
| 571 |
) -> str:
|
| 572 |
"""
|
| 573 |
Gradio์์ ์ง์ ํธ์ถํ๋ ์ํธ๋ฆฌํฌ์ธํธ.
|
|
|
|
| 581 |
name=name,
|
| 582 |
submit_model=submit_model,
|
| 583 |
submit_description=submit_description,
|
| 584 |
+
user_id=user_id,
|
| 585 |
progress=progress,
|
| 586 |
)
|
| 587 |
except Exception as e:
|
| 588 |
# ์ต์์ ๋ณดํธ๋ง: ์์์น ๋ชปํ ์์ธ๋ ์ฌ์ฉ์ ์นํ์ ์ผ๋ก ๋ฐํ
|
| 589 |
try:
|
| 590 |
+
if handler.enable_limit and handler.tracker and user_id:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 591 |
handler.tracker.record_submission(
|
| 592 |
+
user_id=user_id,
|
| 593 |
+
submitter_name=name,
|
| 594 |
file_name=os.path.basename(file.name) if file else "(unknown)",
|
| 595 |
success=False,
|
| 596 |
error_message=str(e),
|
src/submission_tracker.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
"""
|
| 2 |
์ฌ์ฉ์ ์ ์ถ ์ถ์ ๋ชจ๋
|
| 3 |
-
|
| 4 |
์ ์ถ ์ ๋ณด๋ ๋ณ๋์ HuggingFace repository์์ ๊ด๋ฆฌ๋ฉ๋๋ค.
|
| 5 |
"""
|
| 6 |
|
|
@@ -8,10 +8,11 @@ import os
|
|
| 8 |
import json
|
| 9 |
import pandas as pd
|
| 10 |
import tempfile
|
| 11 |
-
from datetime import datetime
|
| 12 |
from typing import Dict, List, Optional, Tuple
|
| 13 |
-
from huggingface_hub import
|
| 14 |
import pytz
|
|
|
|
| 15 |
from src.utils import file_lock, get_current_date_str, get_current_datetime_str
|
| 16 |
|
| 17 |
# ํ๊ตญ ์๊ฐ๋ ์ค์
|
|
@@ -21,50 +22,45 @@ KOREA_TZ = pytz.timezone('Asia/Seoul')
|
|
| 21 |
class SubmissionTracker:
|
| 22 |
"""์ฌ์ฉ์ ์ ์ถ ์ถ์ ํด๋์ค - HuggingFace Repository ๊ธฐ๋ฐ"""
|
| 23 |
|
| 24 |
-
def __init__(
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
"""
|
| 29 |
Args:
|
| 30 |
-
repo_id: HuggingFace repository ID (์: "username/submission-tracker")
|
| 31 |
-
token: HuggingFace API ํ ํฐ (None์ด๋ฉด ํ๊ฒฝ๋ณ์์์ ์๋ ๋ก๋)
|
| 32 |
filename: ์ ์ถ ๊ธฐ๋ก ํ์ผ๋ช
|
| 33 |
"""
|
| 34 |
# ํ๊ฒฝ๋ณ์์์ ์ค์ ๊ฐ์ ธ์ค๊ธฐ
|
| 35 |
-
self.repo_id =
|
| 36 |
-
self.
|
| 37 |
self.filename = filename
|
| 38 |
|
| 39 |
if not self.repo_id:
|
| 40 |
raise ValueError(
|
| 41 |
"SUBMISSION_TRACKER_REPO_ID ํ๊ฒฝ๋ณ์๊ฐ ์ค์ ๋์ง ์์์ต๋๋ค. "
|
| 42 |
-
"๋๋ repo_id๋ฅผ ์ง์ ์ ๋ฌํด์ฃผ์ธ์."
|
| 43 |
)
|
| 44 |
|
| 45 |
-
if not self.
|
| 46 |
raise ValueError(
|
| 47 |
-
"HuggingFace ํ ํฐ์ด ํ์ํฉ๋๋ค. "
|
| 48 |
-
"
|
| 49 |
)
|
| 50 |
|
| 51 |
# HuggingFace API ์ด๊ธฐํ
|
| 52 |
self.api = HfApi()
|
| 53 |
try:
|
| 54 |
-
|
| 55 |
-
|
| 56 |
except Exception as e:
|
| 57 |
print(f"โ HuggingFace ๋ก๊ทธ์ธ ์คํจ: {e}")
|
| 58 |
raise
|
| 59 |
|
| 60 |
# ์ ์ถ ๊ธฐ๋ก ๋ก๋
|
| 61 |
-
self.submissions = self.load_submissions()
|
| 62 |
|
| 63 |
def load_submissions(self) -> Dict:
|
| 64 |
"""HuggingFace repository์์ ์ ์ถ ๊ธฐ๋ก ๋ก๋"""
|
| 65 |
try:
|
| 66 |
-
# ๐ฅ HuggingFace repository์์ ์ ์ถ ๊ธฐ๋ก ๋ก๋ ์ค: {self.repo_id}/{self.filename}
|
| 67 |
-
|
| 68 |
# ์์ ๋๋ ํ ๋ฆฌ์ ํ์ผ ๋ค์ด๋ก๋
|
| 69 |
with tempfile.TemporaryDirectory() as temp_dir:
|
| 70 |
file_path = hf_hub_download(
|
|
@@ -72,43 +68,47 @@ class SubmissionTracker:
|
|
| 72 |
filename=self.filename,
|
| 73 |
local_dir=temp_dir,
|
| 74 |
repo_type="dataset",
|
| 75 |
-
token=self.
|
| 76 |
)
|
| 77 |
|
| 78 |
# JSON ํ์ผ ๋ก๋
|
| 79 |
-
with open(file_path,
|
| 80 |
submissions = json.load(f)
|
| 81 |
|
| 82 |
-
# โ
์ ์ถ ๊ธฐ๋ก ๋ก๋ ์๋ฃ: {len(submissions)}๋ช
์ ์ฌ์ฉ์ ๊ธฐ๋ก
|
| 83 |
return submissions
|
| 84 |
|
| 85 |
except Exception as e:
|
| 86 |
print(f"โ ๏ธ ์ ์ถ ๊ธฐ๋ก ๋ก๋ ์คํจ (์๋ก ์์): {e}")
|
| 87 |
return {}
|
| 88 |
-
|
| 89 |
-
def get_user_id(self) -> Optional[str]:
|
| 90 |
-
"""HuggingFace์์ ํ์ฌ ์ฌ์ฉ์ ID ๊ฐ์ ธ์ค๊ธฐ (๊ณ ์ ID ์ฌ์ฉ)"""
|
| 91 |
-
try:
|
| 92 |
-
user_info = whoami()
|
| 93 |
-
# ๊ณ ์ ID ์ฌ์ฉ (๋ณ๊ฒฝ ๋ถ๊ฐ๋ฅํ ์๋ณ์)
|
| 94 |
-
return user_info.get("id", None)
|
| 95 |
-
except Exception as e:
|
| 96 |
-
print(f"โ ๏ธ ์ฌ์ฉ์ ID ๊ฐ์ ธ์ค๊ธฐ ์คํจ: {e}")
|
| 97 |
-
raise Exception("โ ์ฌ์ฉ์ ID๋ฅผ ๊ฐ์ ธ์ฌ ์ ์์ต๋๋ค. HuggingFace์ ๋ก๊ทธ์ธ๋์ด ์๋์ง ํ์ธํด์ฃผ์ธ์.")
|
| 98 |
-
|
| 99 |
def get_today_submissions(self, user_id: str) -> List[Dict]:
|
| 100 |
"""์ค๋ ์ฌ์ฉ์์ ์ ์ถ ๊ธฐ๋ก ๊ฐ์ ธ์ค๊ธฐ"""
|
|
|
|
|
|
|
| 101 |
today = get_current_date_str()
|
| 102 |
user_submissions = self.submissions.get(user_id, {})
|
| 103 |
return user_submissions.get(today, [])
|
| 104 |
|
| 105 |
-
def can_submit(
|
| 106 |
-
|
| 107 |
-
user_id
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
data = submissions_data if submissions_data is not None else self.submissions
|
| 109 |
today = get_current_date_str()
|
| 110 |
today_submissions = data.get(user_id, {}).get(today, [])
|
| 111 |
-
successful_count = len([s for s in today_submissions if s.get(
|
| 112 |
|
| 113 |
if successful_count >= 3:
|
| 114 |
raise Exception("โ ์ค๋ ์ ์ถ ํ๋๋ฅผ ์ด๊ณผํ์ต๋๋ค. ๋ด์ผ ๋ค์ ์๋ํด์ฃผ์ธ์.")
|
|
@@ -118,15 +118,22 @@ class SubmissionTracker:
|
|
| 118 |
|
| 119 |
def record_submission(
|
| 120 |
self,
|
|
|
|
| 121 |
submitter_name: str,
|
| 122 |
file_name: str,
|
| 123 |
success: bool,
|
| 124 |
-
error_message: str = None,
|
| 125 |
submit_model: Optional[str] = None,
|
| 126 |
-
submit_description: Optional[str] = None
|
| 127 |
) -> bool:
|
| 128 |
-
"""
|
| 129 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 130 |
|
| 131 |
# ์ ๊ธ ํ์ผ ๊ฒฝ๋ก ์์ฑ
|
| 132 |
lock_file_path = tempfile.gettempdir() + f'/{self.repo_id.replace("/", "_")}.lock'
|
|
@@ -139,11 +146,14 @@ class SubmissionTracker:
|
|
| 139 |
|
| 140 |
# Lock ๋ด๋ถ์์ ์ต์ ๋ฐ์ดํฐ ๊ธฐ์ค์ผ๋ก ์ ์ถ ๊ฐ๋ฅ ์ฌ๋ถ ์ฌํ์ธ
|
| 141 |
try:
|
| 142 |
-
|
|
|
|
|
|
|
|
|
|
| 143 |
except Exception as e:
|
| 144 |
# ์ ์ถ ์ ํ ์ด๊ณผ ์
|
| 145 |
-
|
| 146 |
-
# ๋ฉ๋ชจ๋ฆฌ๋ง
|
| 147 |
self.submissions = latest_submissions
|
| 148 |
return False
|
| 149 |
|
|
@@ -164,7 +174,7 @@ class SubmissionTracker:
|
|
| 164 |
"success": success,
|
| 165 |
"error_message": error_message,
|
| 166 |
"submit_model": submit_model,
|
| 167 |
-
"submit_description": submit_description
|
| 168 |
}
|
| 169 |
|
| 170 |
latest_submissions[user_id][today].append(submission_record)
|
|
@@ -182,10 +192,13 @@ class SubmissionTracker:
|
|
| 182 |
def _save_submissions_internal(self, submissions_data: Dict) -> bool:
|
| 183 |
"""๋ด๋ถ ์ ์ฅ ํจ์ (lock์ ์ด๋ฏธ ํ๋๋ ์ํ)"""
|
| 184 |
try:
|
| 185 |
-
# ๐พ HuggingFace repository์ ์ ์ถ ๊ธฐ๋ก ์ ์ฅ ์ค: {self.repo_id}/{self.filename}
|
| 186 |
-
|
| 187 |
# ์์ ํ์ผ์ JSON ๋ฐ์ดํฐ ์ ์ฅ
|
| 188 |
-
with tempfile.NamedTemporaryFile(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 189 |
json.dump(submissions_data, temp_file, ensure_ascii=False, indent=2)
|
| 190 |
temp_file_path = temp_file.name
|
| 191 |
|
|
@@ -195,14 +208,16 @@ class SubmissionTracker:
|
|
| 195 |
path_in_repo=self.filename,
|
| 196 |
repo_id=self.repo_id,
|
| 197 |
repo_type="dataset",
|
| 198 |
-
token=self.
|
| 199 |
-
commit_message=
|
|
|
|
|
|
|
|
|
|
| 200 |
)
|
| 201 |
|
| 202 |
# ์์ ํ์ผ ์ญ์
|
| 203 |
os.unlink(temp_file_path)
|
| 204 |
|
| 205 |
-
# โ
์ ์ถ ๊ธฐ๋ก ์ ์ฅ ์๋ฃ
|
| 206 |
return True
|
| 207 |
|
| 208 |
except Exception as e:
|
|
@@ -217,10 +232,10 @@ class SubmissionTracker:
|
|
| 217 |
user_submissions = self.submissions[user_id]
|
| 218 |
today = datetime.now(KOREA_TZ).date()
|
| 219 |
|
| 220 |
-
history = {}
|
| 221 |
for i in range(days):
|
| 222 |
check_date = today - pd.Timedelta(days=i)
|
| 223 |
-
date_str = check_date.strftime(
|
| 224 |
|
| 225 |
if date_str in user_submissions:
|
| 226 |
history[date_str] = user_submissions[date_str]
|
|
@@ -233,13 +248,13 @@ class SubmissionTracker:
|
|
| 233 |
return {}
|
| 234 |
|
| 235 |
today_submissions = self.get_today_submissions(user_id)
|
| 236 |
-
successful_today_count = len([s for s in today_submissions if s.get(
|
| 237 |
history = self.get_user_submission_history(user_id, 7)
|
| 238 |
|
| 239 |
# ํต๊ณ ๊ณ์ฐ
|
| 240 |
total_submissions = sum(len(day_submissions) for day_submissions in history.values())
|
| 241 |
successful_submissions = sum(
|
| 242 |
-
len([s for s in day_submissions if s.get(
|
| 243 |
for day_submissions in history.values()
|
| 244 |
)
|
| 245 |
failed_submissions = total_submissions - successful_submissions
|
|
@@ -250,10 +265,10 @@ class SubmissionTracker:
|
|
| 250 |
"week_total": total_submissions,
|
| 251 |
"week_successful": successful_submissions,
|
| 252 |
"week_failed": failed_submissions,
|
| 253 |
-
"history": history
|
| 254 |
}
|
| 255 |
|
| 256 |
-
def cleanup_old_records(self, days_to_keep: int = 30):
|
| 257 |
"""์ค๋๋ ์ ์ถ ๊ธฐ๋ก ์ ๋ฆฌ (ํ์ผ ์ ๊ธ ์ฌ์ฉ)"""
|
| 258 |
# ์ ๊ธ ํ์ผ ๊ฒฝ๋ก ์์ฑ
|
| 259 |
lock_file_path = tempfile.gettempdir() + f'/{self.repo_id.replace("/", "_")}.lock'
|
|
@@ -265,11 +280,11 @@ class SubmissionTracker:
|
|
| 265 |
latest_submissions = self.load_submissions()
|
| 266 |
|
| 267 |
cutoff_date = datetime.now(KOREA_TZ) - pd.Timedelta(days=days_to_keep)
|
| 268 |
-
cutoff_str = cutoff_date.strftime(
|
| 269 |
|
| 270 |
cleaned_count = 0
|
| 271 |
-
for
|
| 272 |
-
user_submissions = latest_submissions[
|
| 273 |
for date_str in list(user_submissions.keys()):
|
| 274 |
if date_str < cutoff_str:
|
| 275 |
del user_submissions[date_str]
|
|
@@ -277,7 +292,7 @@ class SubmissionTracker:
|
|
| 277 |
|
| 278 |
# ๋น ์ฌ์ฉ์ ๊ธฐ๋ก ์ ๊ฑฐ
|
| 279 |
if not user_submissions:
|
| 280 |
-
del latest_submissions[
|
| 281 |
|
| 282 |
# ๋ฉ๋ชจ๋ฆฌ ์
๋ฐ์ดํธ
|
| 283 |
self.submissions = latest_submissions
|
|
|
|
| 1 |
"""
|
| 2 |
์ฌ์ฉ์ ์ ์ถ ์ถ์ ๋ชจ๋
|
| 3 |
+
๋ก๊ทธ์ธํ ์ฌ์ฉ์์ user_id๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ํ๋ฃจ 3๋ฒ ์ ํ ๊ธฐ๋ฅ์ ์ ๊ณตํฉ๋๋ค.
|
| 4 |
์ ์ถ ์ ๋ณด๋ ๋ณ๋์ HuggingFace repository์์ ๊ด๋ฆฌ๋ฉ๋๋ค.
|
| 5 |
"""
|
| 6 |
|
|
|
|
| 8 |
import json
|
| 9 |
import pandas as pd
|
| 10 |
import tempfile
|
| 11 |
+
from datetime import datetime
|
| 12 |
from typing import Dict, List, Optional, Tuple
|
| 13 |
+
from huggingface_hub import hf_hub_download, login, HfApi
|
| 14 |
import pytz
|
| 15 |
+
|
| 16 |
from src.utils import file_lock, get_current_date_str, get_current_datetime_str
|
| 17 |
|
| 18 |
# ํ๊ตญ ์๊ฐ๋ ์ค์
|
|
|
|
| 22 |
class SubmissionTracker:
|
| 23 |
"""์ฌ์ฉ์ ์ ์ถ ์ถ์ ํด๋์ค - HuggingFace Repository ๊ธฐ๋ฐ"""
|
| 24 |
|
| 25 |
+
def __init__(
|
| 26 |
+
self,
|
| 27 |
+
filename: str = "user_submissions.json",
|
| 28 |
+
):
|
| 29 |
"""
|
| 30 |
Args:
|
|
|
|
|
|
|
| 31 |
filename: ์ ์ถ ๊ธฐ๋ก ํ์ผ๋ช
|
| 32 |
"""
|
| 33 |
# ํ๊ฒฝ๋ณ์์์ ์ค์ ๊ฐ์ ธ์ค๊ธฐ
|
| 34 |
+
self.repo_id = os.getenv("SUBMISSION_TRACKER_REPO_ID")
|
| 35 |
+
self.admin_token = os.getenv("HF_TOKEN")
|
| 36 |
self.filename = filename
|
| 37 |
|
| 38 |
if not self.repo_id:
|
| 39 |
raise ValueError(
|
| 40 |
"SUBMISSION_TRACKER_REPO_ID ํ๊ฒฝ๋ณ์๊ฐ ์ค์ ๋์ง ์์์ต๋๋ค. "
|
|
|
|
| 41 |
)
|
| 42 |
|
| 43 |
+
if not self.admin_token:
|
| 44 |
raise ValueError(
|
| 45 |
+
"HuggingFace Admin ํ ํฐ์ด ํ์ํฉ๋๋ค. "
|
| 46 |
+
"HF_TOKEN ํ๊ฒฝ๋ณ์๋ฅผ ์ค์ ํ์ธ์."
|
| 47 |
)
|
| 48 |
|
| 49 |
# HuggingFace API ์ด๊ธฐํ
|
| 50 |
self.api = HfApi()
|
| 51 |
try:
|
| 52 |
+
# ๊ด๋ฆฌ์ ํ ํฐ์ผ๋ก ๋ก๊ทธ์ธ (dataset read/write ์ฉ)
|
| 53 |
+
login(token=self.admin_token)
|
| 54 |
except Exception as e:
|
| 55 |
print(f"โ HuggingFace ๋ก๊ทธ์ธ ์คํจ: {e}")
|
| 56 |
raise
|
| 57 |
|
| 58 |
# ์ ์ถ ๊ธฐ๋ก ๋ก๋
|
| 59 |
+
self.submissions: Dict = self.load_submissions()
|
| 60 |
|
| 61 |
def load_submissions(self) -> Dict:
|
| 62 |
"""HuggingFace repository์์ ์ ์ถ ๊ธฐ๋ก ๋ก๋"""
|
| 63 |
try:
|
|
|
|
|
|
|
| 64 |
# ์์ ๋๋ ํ ๋ฆฌ์ ํ์ผ ๋ค์ด๋ก๋
|
| 65 |
with tempfile.TemporaryDirectory() as temp_dir:
|
| 66 |
file_path = hf_hub_download(
|
|
|
|
| 68 |
filename=self.filename,
|
| 69 |
local_dir=temp_dir,
|
| 70 |
repo_type="dataset",
|
| 71 |
+
token=self.admin_token,
|
| 72 |
)
|
| 73 |
|
| 74 |
# JSON ํ์ผ ๋ก๋
|
| 75 |
+
with open(file_path, "r", encoding="utf-8") as f:
|
| 76 |
submissions = json.load(f)
|
| 77 |
|
|
|
|
| 78 |
return submissions
|
| 79 |
|
| 80 |
except Exception as e:
|
| 81 |
print(f"โ ๏ธ ์ ์ถ ๊ธฐ๋ก ๋ก๋ ์คํจ (์๋ก ์์): {e}")
|
| 82 |
return {}
|
| 83 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
def get_today_submissions(self, user_id: str) -> List[Dict]:
|
| 85 |
"""์ค๋ ์ฌ์ฉ์์ ์ ์ถ ๊ธฐ๋ก ๊ฐ์ ธ์ค๊ธฐ"""
|
| 86 |
+
if not user_id:
|
| 87 |
+
return []
|
| 88 |
today = get_current_date_str()
|
| 89 |
user_submissions = self.submissions.get(user_id, {})
|
| 90 |
return user_submissions.get(today, [])
|
| 91 |
|
| 92 |
+
def can_submit(
|
| 93 |
+
self,
|
| 94 |
+
user_id: str,
|
| 95 |
+
submissions_data: Optional[Dict] = None,
|
| 96 |
+
) -> Tuple[bool, str, int]:
|
| 97 |
+
"""
|
| 98 |
+
์ฌ์ฉ์๊ฐ ์ ์ถํ ์ ์๋์ง ํ์ธ.
|
| 99 |
+
|
| 100 |
+
Args:
|
| 101 |
+
user_id: ๋ก๊ทธ์ธํ ์ฌ์ฉ์์ ๊ณ ์ ID (HF ๊ณ์ ID ๋ฑ)
|
| 102 |
+
submissions_data: ๊ฒ์ฌ์ ์ฌ์ฉํ ์ ์ถ ๋ฐ์ดํฐ(ํ
์คํธ/๋ฝ ๋ด๋ถ ์ฌ๊ฒ์ฌ์ฉ).
|
| 103 |
+
None์ด๋ฉด self.submissions ์ฌ์ฉ.
|
| 104 |
+
"""
|
| 105 |
+
if not user_id:
|
| 106 |
+
raise ValueError("โ HuggingFace ๋ก๊ทธ์ธ ์ํ์์๋ง ์ ์ถ ๊ฐ๋ฅํฉ๋๋ค. ๋ก๊ทธ์ธ ์ ๋ณด๋ฅผ ํ์ธํด์ฃผ์ธ์.")
|
| 107 |
+
|
| 108 |
data = submissions_data if submissions_data is not None else self.submissions
|
| 109 |
today = get_current_date_str()
|
| 110 |
today_submissions = data.get(user_id, {}).get(today, [])
|
| 111 |
+
successful_count = len([s for s in today_submissions if s.get("success", False)])
|
| 112 |
|
| 113 |
if successful_count >= 3:
|
| 114 |
raise Exception("โ ์ค๋ ์ ์ถ ํ๋๋ฅผ ์ด๊ณผํ์ต๋๋ค. ๋ด์ผ ๋ค์ ์๋ํด์ฃผ์ธ์.")
|
|
|
|
| 118 |
|
| 119 |
def record_submission(
|
| 120 |
self,
|
| 121 |
+
user_id: str,
|
| 122 |
submitter_name: str,
|
| 123 |
file_name: str,
|
| 124 |
success: bool,
|
| 125 |
+
error_message: Optional[str] = None,
|
| 126 |
submit_model: Optional[str] = None,
|
| 127 |
+
submit_description: Optional[str] = None,
|
| 128 |
) -> bool:
|
| 129 |
+
"""
|
| 130 |
+
์ ์ถ ๊ธฐ๋ก ์ถ๊ฐ (ํ์ผ ์ ๊ธ์ผ๋ก ๋ณดํธ)
|
| 131 |
+
|
| 132 |
+
Args:
|
| 133 |
+
user_id: ๋ก๊ทธ์ธํ ์ฌ์ฉ์์ ๊ณ ์ ID (HF ๊ณ์ ID ๋ฑ)
|
| 134 |
+
"""
|
| 135 |
+
if not user_id:
|
| 136 |
+
raise ValueError("โ HuggingFace ๋ก๊ทธ์ธ ์ํ์์๋ง ์ ์ถ ๊ฐ๋ฅํฉ๋๋ค. ๋ก๊ทธ์ธ ์ ๋ณด๋ฅผ ํ์ธํด์ฃผ์ธ์.")
|
| 137 |
|
| 138 |
# ์ ๊ธ ํ์ผ ๊ฒฝ๋ก ์์ฑ
|
| 139 |
lock_file_path = tempfile.gettempdir() + f'/{self.repo_id.replace("/", "_")}.lock'
|
|
|
|
| 146 |
|
| 147 |
# Lock ๋ด๋ถ์์ ์ต์ ๋ฐ์ดํฐ ๊ธฐ์ค์ผ๋ก ์ ์ถ ๊ฐ๋ฅ ์ฌ๋ถ ์ฌํ์ธ
|
| 148 |
try:
|
| 149 |
+
self.can_submit(
|
| 150 |
+
user_id=user_id,
|
| 151 |
+
submissions_data=latest_submissions,
|
| 152 |
+
)
|
| 153 |
except Exception as e:
|
| 154 |
# ์ ์ถ ์ ํ ์ด๊ณผ ์
|
| 155 |
+
print(f"์ ์ถ ์ ํ ์ด๊ณผ: {e}")
|
| 156 |
+
# ๋ฉ๋ชจ๋ฆฌ๋ง ์ต์ ์ผ๋ก ๋ง์ถ๊ณ ์ ์ฅํ์ง ์์
|
| 157 |
self.submissions = latest_submissions
|
| 158 |
return False
|
| 159 |
|
|
|
|
| 174 |
"success": success,
|
| 175 |
"error_message": error_message,
|
| 176 |
"submit_model": submit_model,
|
| 177 |
+
"submit_description": submit_description,
|
| 178 |
}
|
| 179 |
|
| 180 |
latest_submissions[user_id][today].append(submission_record)
|
|
|
|
| 192 |
def _save_submissions_internal(self, submissions_data: Dict) -> bool:
|
| 193 |
"""๋ด๋ถ ์ ์ฅ ํจ์ (lock์ ์ด๋ฏธ ํ๋๋ ์ํ)"""
|
| 194 |
try:
|
|
|
|
|
|
|
| 195 |
# ์์ ํ์ผ์ JSON ๋ฐ์ดํฐ ์ ์ฅ
|
| 196 |
+
with tempfile.NamedTemporaryFile(
|
| 197 |
+
mode="w",
|
| 198 |
+
encoding="utf-8",
|
| 199 |
+
suffix=".json",
|
| 200 |
+
delete=False,
|
| 201 |
+
) as temp_file:
|
| 202 |
json.dump(submissions_data, temp_file, ensure_ascii=False, indent=2)
|
| 203 |
temp_file_path = temp_file.name
|
| 204 |
|
|
|
|
| 208 |
path_in_repo=self.filename,
|
| 209 |
repo_id=self.repo_id,
|
| 210 |
repo_type="dataset",
|
| 211 |
+
token=self.admin_token,
|
| 212 |
+
commit_message=(
|
| 213 |
+
"Update submission records - "
|
| 214 |
+
f"{datetime.now(KOREA_TZ).strftime('%Y-%m-%d %H:%M:%S')}"
|
| 215 |
+
),
|
| 216 |
)
|
| 217 |
|
| 218 |
# ์์ ํ์ผ ์ญ์
|
| 219 |
os.unlink(temp_file_path)
|
| 220 |
|
|
|
|
| 221 |
return True
|
| 222 |
|
| 223 |
except Exception as e:
|
|
|
|
| 232 |
user_submissions = self.submissions[user_id]
|
| 233 |
today = datetime.now(KOREA_TZ).date()
|
| 234 |
|
| 235 |
+
history: Dict[str, List[Dict]] = {}
|
| 236 |
for i in range(days):
|
| 237 |
check_date = today - pd.Timedelta(days=i)
|
| 238 |
+
date_str = check_date.strftime("%Y-%m-%d")
|
| 239 |
|
| 240 |
if date_str in user_submissions:
|
| 241 |
history[date_str] = user_submissions[date_str]
|
|
|
|
| 248 |
return {}
|
| 249 |
|
| 250 |
today_submissions = self.get_today_submissions(user_id)
|
| 251 |
+
successful_today_count = len([s for s in today_submissions if s.get("success", False)])
|
| 252 |
history = self.get_user_submission_history(user_id, 7)
|
| 253 |
|
| 254 |
# ํต๊ณ ๊ณ์ฐ
|
| 255 |
total_submissions = sum(len(day_submissions) for day_submissions in history.values())
|
| 256 |
successful_submissions = sum(
|
| 257 |
+
len([s for s in day_submissions if s.get("success", False)])
|
| 258 |
for day_submissions in history.values()
|
| 259 |
)
|
| 260 |
failed_submissions = total_submissions - successful_submissions
|
|
|
|
| 265 |
"week_total": total_submissions,
|
| 266 |
"week_successful": successful_submissions,
|
| 267 |
"week_failed": failed_submissions,
|
| 268 |
+
"history": history,
|
| 269 |
}
|
| 270 |
|
| 271 |
+
def cleanup_old_records(self, days_to_keep: int = 30) -> int:
|
| 272 |
"""์ค๋๋ ์ ์ถ ๊ธฐ๋ก ์ ๋ฆฌ (ํ์ผ ์ ๊ธ ์ฌ์ฉ)"""
|
| 273 |
# ์ ๊ธ ํ์ผ ๊ฒฝ๋ก ์์ฑ
|
| 274 |
lock_file_path = tempfile.gettempdir() + f'/{self.repo_id.replace("/", "_")}.lock'
|
|
|
|
| 280 |
latest_submissions = self.load_submissions()
|
| 281 |
|
| 282 |
cutoff_date = datetime.now(KOREA_TZ) - pd.Timedelta(days=days_to_keep)
|
| 283 |
+
cutoff_str = cutoff_date.strftime("%Y-%m-%d")
|
| 284 |
|
| 285 |
cleaned_count = 0
|
| 286 |
+
for uid in list(latest_submissions.keys()):
|
| 287 |
+
user_submissions = latest_submissions[uid]
|
| 288 |
for date_str in list(user_submissions.keys()):
|
| 289 |
if date_str < cutoff_str:
|
| 290 |
del user_submissions[date_str]
|
|
|
|
| 292 |
|
| 293 |
# ๋น ์ฌ์ฉ์ ๊ธฐ๋ก ์ ๊ฑฐ
|
| 294 |
if not user_submissions:
|
| 295 |
+
del latest_submissions[uid]
|
| 296 |
|
| 297 |
# ๋ฉ๋ชจ๋ฆฌ ์
๋ฐ์ดํธ
|
| 298 |
self.submissions = latest_submissions
|
ui/submission_tab.py
CHANGED
|
@@ -5,9 +5,42 @@
|
|
| 5 |
"""
|
| 6 |
|
| 7 |
import gradio as gr
|
|
|
|
|
|
|
| 8 |
from src.submission_handler import process_submission
|
| 9 |
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
def create_submission_tab():
|
| 12 |
"""์ ์ถ ๋ฐ ํ๊ฐ ํญ UI ์์ฑ"""
|
| 13 |
|
|
@@ -53,7 +86,8 @@ def create_submission_tab():
|
|
| 53 |
<br>
|
| 54 |
""")
|
| 55 |
|
| 56 |
-
|
|
|
|
| 57 |
|
| 58 |
submission_file = gr.File(
|
| 59 |
label="์ ๋ต์ด ํฌํจ๋ CSV ํ์ผ ์
๋ก๋",
|
|
@@ -91,8 +125,8 @@ def create_submission_tab():
|
|
| 91 |
|
| 92 |
# ์ ์ถ ๋ฒํผ ์ด๋ฒคํธ ์ฐ๊ฒฐ
|
| 93 |
submit_btn.click(
|
| 94 |
-
fn=
|
| 95 |
inputs=[submission_file, submitter_name, submit_model, submit_description],
|
| 96 |
outputs=[submission_status],
|
| 97 |
-
concurrency_limit=3
|
| 98 |
)
|
|
|
|
| 5 |
"""
|
| 6 |
|
| 7 |
import gradio as gr
|
| 8 |
+
from huggingface_hub import whoami
|
| 9 |
+
|
| 10 |
from src.submission_handler import process_submission
|
| 11 |
|
| 12 |
|
| 13 |
+
def _process_submission_with_oauth(
|
| 14 |
+
file,
|
| 15 |
+
name: str,
|
| 16 |
+
submit_model: str,
|
| 17 |
+
submit_description: str,
|
| 18 |
+
oauth_token: gr.OAuthToken | None = None, # ๐ง Gradio๊ฐ ์๋์ผ๋ก ์ฃผ์
|
| 19 |
+
):
|
| 20 |
+
"""
|
| 21 |
+
- hf_oauth: true ๊ฐ ์ผ์ง HF Space์์๋ง ์ค์ ํ ํฐ์ด ๋ค์ด์ด
|
| 22 |
+
- ๋ก์ปฌ ๊ฐ๋ฐ ํ๊ฒฝ์์๋ oauth_token์ด None ์ด๋ฏ๋ก user_id=None ์ผ๋ก ๋์
|
| 23 |
+
"""
|
| 24 |
+
user_id = None
|
| 25 |
+
|
| 26 |
+
if oauth_token is not None:
|
| 27 |
+
try:
|
| 28 |
+
info = whoami(oauth_token.token) # ๐ง ๋ก๊ทธ์ธํ ์ ์ ํ ํฐ์ผ๋ก whoami ํธ์ถ
|
| 29 |
+
user_id = info.get("id")
|
| 30 |
+
except Exception as e:
|
| 31 |
+
print(f"๐จ whoami ์คํจ, user_id๋ฅผ ๊ฐ์ ธ์ค์ง ๋ชปํ์ต๋๋ค: {e}")
|
| 32 |
+
user_id = None
|
| 33 |
+
|
| 34 |
+
# submission_handler.process_submission ์ user_id ๋๊ฒจ์ค
|
| 35 |
+
return process_submission(
|
| 36 |
+
file=file,
|
| 37 |
+
name=name,
|
| 38 |
+
submit_model=submit_model,
|
| 39 |
+
submit_description=submit_description,
|
| 40 |
+
user_id=user_id,
|
| 41 |
+
)
|
| 42 |
+
|
| 43 |
+
|
| 44 |
def create_submission_tab():
|
| 45 |
"""์ ์ถ ๋ฐ ํ๊ฐ ํญ UI ์์ฑ"""
|
| 46 |
|
|
|
|
| 86 |
<br>
|
| 87 |
""")
|
| 88 |
|
| 89 |
+
# ๐ง HF OAuth ๋ก๊ทธ์ธ ๋ฒํผ (Space์์๋ง ์ค์ ๋ก ๋์, ๋ก์ปฌ์์๋ ๊ทธ๋ฅ ํ์๋ง)
|
| 90 |
+
gr.LoginButton()
|
| 91 |
|
| 92 |
submission_file = gr.File(
|
| 93 |
label="์ ๋ต์ด ํฌํจ๋ CSV ํ์ผ ์
๋ก๋",
|
|
|
|
| 125 |
|
| 126 |
# ์ ์ถ ๋ฒํผ ์ด๋ฒคํธ ์ฐ๊ฒฐ
|
| 127 |
submit_btn.click(
|
| 128 |
+
fn=_process_submission_with_oauth,
|
| 129 |
inputs=[submission_file, submitter_name, submit_model, submit_description],
|
| 130 |
outputs=[submission_status],
|
| 131 |
+
concurrency_limit=3,
|
| 132 |
)
|