Spaces:
Running
Running
Update ui/manual_dashboard.py
Browse files- ui/manual_dashboard.py +36 -17
ui/manual_dashboard.py
CHANGED
|
@@ -32,29 +32,48 @@ ensure_dirs()
|
|
| 32 |
|
| 33 |
# ---------------- FILE UPLOAD (HF SAFE) ----------------
|
| 34 |
def handle_file_upload(files):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
if not files:
|
| 36 |
-
return
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
-
|
|
|
|
| 44 |
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
with open(dest, "wb") as w:
|
| 48 |
-
w.write(f.data) # HF NamedString uses f.data
|
| 49 |
-
saved_filenames.append(f.name)
|
| 50 |
|
| 51 |
-
|
|
|
|
|
|
|
| 52 |
|
| 53 |
return (
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
gr.update(choices=
|
| 57 |
-
gr.update(choices=
|
| 58 |
)
|
| 59 |
|
| 60 |
|
|
|
|
| 32 |
|
| 33 |
# ---------------- FILE UPLOAD (HF SAFE) ----------------
|
| 34 |
def handle_file_upload(files):
|
| 35 |
+
"""
|
| 36 |
+
Handle uploads from Gradio. On HuggingFace Spaces, `files` is a list
|
| 37 |
+
of temporary file paths (strings), NOT objects with .read() / .data.
|
| 38 |
+
"""
|
| 39 |
+
|
| 40 |
if not files:
|
| 41 |
+
return "⚠️ No files uploaded.", [], None, None
|
| 42 |
+
|
| 43 |
+
saved_files = []
|
| 44 |
+
file_list = []
|
| 45 |
+
|
| 46 |
+
for temp_path in files:
|
| 47 |
+
if temp_path is None:
|
| 48 |
+
continue
|
| 49 |
+
|
| 50 |
+
filename = os.path.basename(temp_path)
|
| 51 |
+
dest_path = os.path.join(UPLOAD_DIR, filename)
|
| 52 |
+
|
| 53 |
+
try:
|
| 54 |
+
# Copy file from HF temp path to uploads folder
|
| 55 |
+
with open(temp_path, "rb") as src:
|
| 56 |
+
with open(dest_path, "wb") as dst:
|
| 57 |
+
dst.write(src.read())
|
| 58 |
+
|
| 59 |
+
saved_files.append(filename)
|
| 60 |
+
file_list.append(filename)
|
| 61 |
|
| 62 |
+
except Exception as e:
|
| 63 |
+
return f"⚠️ File save error:\n{e}", [], None, None
|
| 64 |
|
| 65 |
+
# Build display text
|
| 66 |
+
text = "\n".join([f"✓ {name}" for name in saved_files])
|
|
|
|
|
|
|
|
|
|
| 67 |
|
| 68 |
+
# Dropdown choices
|
| 69 |
+
choices = file_list
|
| 70 |
+
default = file_list[0] if file_list else None
|
| 71 |
|
| 72 |
return (
|
| 73 |
+
text,
|
| 74 |
+
file_list,
|
| 75 |
+
gr.update(choices=choices, value=default),
|
| 76 |
+
gr.update(choices=choices, value=default),
|
| 77 |
)
|
| 78 |
|
| 79 |
|