Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,6 +7,7 @@ from datetime import datetime
|
|
| 7 |
import pandas as pd
|
| 8 |
from filelock import FileLock, Timeout
|
| 9 |
from pathlib import Path
|
|
|
|
| 10 |
|
| 11 |
|
| 12 |
class VideoArenaManager:
|
|
@@ -33,12 +34,9 @@ class VideoArenaManager:
|
|
| 33 |
"""Retrieve a list of data files in the /data directory."""
|
| 34 |
data_path = Path("/data")
|
| 35 |
files = [
|
| 36 |
-
{
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
"path": str(file)
|
| 40 |
-
}
|
| 41 |
-
for file in data_path.glob("*") if file.is_file()
|
| 42 |
]
|
| 43 |
return files
|
| 44 |
|
|
@@ -261,24 +259,29 @@ def create_arena_interface():
|
|
| 261 |
with gr.Accordion("Download Results File", open=False):
|
| 262 |
files = manager.get_data_files()
|
| 263 |
file_names = [file["name"] for file in files]
|
| 264 |
-
file_select = gr.Dropdown(
|
| 265 |
-
choices=file_names,
|
| 266 |
-
label="Select Results File to Download",
|
| 267 |
-
interactive=True
|
| 268 |
-
)
|
| 269 |
download_button = gr.Button("Download Selected File", size="sm") # Smaller button
|
| 270 |
|
| 271 |
def download_file(file_name: str):
|
| 272 |
"""Prepare the selected file for download."""
|
|
|
|
|
|
|
|
|
|
| 273 |
file_path = f"/data/{file_name}"
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 278 |
download_button.click(
|
| 279 |
fn=download_file,
|
| 280 |
inputs=[file_select],
|
| 281 |
-
outputs=gr.File(),
|
| 282 |
)
|
| 283 |
|
| 284 |
return demo
|
|
|
|
| 7 |
import pandas as pd
|
| 8 |
from filelock import FileLock, Timeout
|
| 9 |
from pathlib import Path
|
| 10 |
+
import tempfile
|
| 11 |
|
| 12 |
|
| 13 |
class VideoArenaManager:
|
|
|
|
| 34 |
"""Retrieve a list of data files in the /data directory."""
|
| 35 |
data_path = Path("/data")
|
| 36 |
files = [
|
| 37 |
+
{"name": file.name, "size": file.stat().st_size, "path": str(file)}
|
| 38 |
+
for file in data_path.glob("*")
|
| 39 |
+
if file.is_file()
|
|
|
|
|
|
|
|
|
|
| 40 |
]
|
| 41 |
return files
|
| 42 |
|
|
|
|
| 259 |
with gr.Accordion("Download Results File", open=False):
|
| 260 |
files = manager.get_data_files()
|
| 261 |
file_names = [file["name"] for file in files]
|
| 262 |
+
file_select = gr.Dropdown(choices=file_names, label="Select Results File to Download", interactive=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 263 |
download_button = gr.Button("Download Selected File", size="sm") # Smaller button
|
| 264 |
|
| 265 |
def download_file(file_name: str):
|
| 266 |
"""Prepare the selected file for download."""
|
| 267 |
+
if not file_name:
|
| 268 |
+
return None
|
| 269 |
+
|
| 270 |
file_path = f"/data/{file_name}"
|
| 271 |
+
try:
|
| 272 |
+
# Create a temporary file to handle the download
|
| 273 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=os.path.splitext(file_name)[1]) as tmp_file:
|
| 274 |
+
with open(file_path, "rb") as f:
|
| 275 |
+
tmp_file.write(f.read())
|
| 276 |
+
return tmp_file.name
|
| 277 |
+
except Exception as e:
|
| 278 |
+
print(f"Error preparing download: {e}")
|
| 279 |
+
return None
|
| 280 |
+
|
| 281 |
download_button.click(
|
| 282 |
fn=download_file,
|
| 283 |
inputs=[file_select],
|
| 284 |
+
outputs=gr.File(label="Download"),
|
| 285 |
)
|
| 286 |
|
| 287 |
return demo
|