Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -26,17 +26,21 @@ def list_pending():
|
|
26 |
return sorted(glob.glob(f"{PENDING_DIR}/*"))
|
27 |
|
28 |
# -------- ADMIN: APPROVE & PUSH -----------------------------------
|
29 |
-
def approve_files(password,
|
|
|
30 |
if ADMIN_KEY_ENV and password != ADMIN_KEY_ENV:
|
31 |
-
return "🔒 Wrong admin key!",
|
32 |
|
33 |
-
if not
|
34 |
-
return "⚠️ Nothing selected.",
|
35 |
|
36 |
-
|
37 |
-
for
|
38 |
-
|
39 |
-
|
|
|
|
|
|
|
40 |
upload_file(
|
41 |
path_or_fileobj=file_path,
|
42 |
path_in_repo=f"images/{filename}",
|
@@ -44,10 +48,13 @@ def approve_files(password, selected_files):
|
|
44 |
repo_type="dataset",
|
45 |
token=HF_TOKEN,
|
46 |
)
|
|
|
47 |
# 2) move to approved/
|
48 |
shutil.move(file_path, os.path.join(APPROVED_DIR, filename))
|
49 |
-
|
50 |
-
|
|
|
|
|
51 |
|
52 |
# -------------------- UI ------------------------------------------
|
53 |
with gr.Blocks() as demo:
|
|
|
26 |
return sorted(glob.glob(f"{PENDING_DIR}/*"))
|
27 |
|
28 |
# -------- ADMIN: APPROVE & PUSH -----------------------------------
|
29 |
+
def approve_files(password, selected_items):
|
30 |
+
# ----- auth check -----
|
31 |
if ADMIN_KEY_ENV and password != ADMIN_KEY_ENV:
|
32 |
+
return "🔒 Wrong admin key!", list_pending()
|
33 |
|
34 |
+
if not selected_items:
|
35 |
+
return "⚠️ Nothing selected.", list_pending()
|
36 |
|
37 |
+
log_lines = []
|
38 |
+
for item in selected_items:
|
39 |
+
# New ✨ — handle tuple or str
|
40 |
+
file_path = item[0] if isinstance(item, (tuple, list)) else item
|
41 |
+
filename = os.path.basename(file_path)
|
42 |
+
|
43 |
+
# 1) push to dataset
|
44 |
upload_file(
|
45 |
path_or_fileobj=file_path,
|
46 |
path_in_repo=f"images/{filename}",
|
|
|
48 |
repo_type="dataset",
|
49 |
token=HF_TOKEN,
|
50 |
)
|
51 |
+
|
52 |
# 2) move to approved/
|
53 |
shutil.move(file_path, os.path.join(APPROVED_DIR, filename))
|
54 |
+
log_lines.append(f"✅ {filename}")
|
55 |
+
|
56 |
+
# return log and refreshed gallery
|
57 |
+
return "\n".join(log_lines), list_pending()
|
58 |
|
59 |
# -------------------- UI ------------------------------------------
|
60 |
with gr.Blocks() as demo:
|