Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -253,8 +253,9 @@ def run_script(script: str, output_format: str, dataset_info: Dict[str, Any] = N
|
|
| 253 |
if not output_file:
|
| 254 |
output_file = file_path
|
| 255 |
|
| 256 |
-
# Převeď na base64 -
|
| 257 |
data_b64 = ""
|
|
|
|
| 258 |
if all_output_files:
|
| 259 |
# Najdi největší soubor
|
| 260 |
largest_file = max(all_output_files, key=lambda f: os.path.getsize(f) if os.path.exists(f) else 0)
|
|
@@ -264,12 +265,20 @@ def run_script(script: str, output_format: str, dataset_info: Dict[str, Any] = N
|
|
| 264 |
if len(blob) > max_output:
|
| 265 |
raise HTTPException(status_code=413, detail="Výstup je příliš velký")
|
| 266 |
data_b64 = base64.b64encode(blob).decode("utf-8")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 267 |
elif output_file and os.path.exists(output_file):
|
| 268 |
with open(output_file, "rb") as f:
|
| 269 |
blob = f.read()
|
| 270 |
if len(blob) > max_output:
|
| 271 |
raise HTTPException(status_code=413, detail="Výstup je příliš velký")
|
| 272 |
data_b64 = base64.b64encode(blob).decode("utf-8")
|
|
|
|
| 273 |
else:
|
| 274 |
# Debug: vypiš všechny soubory v tmp adresáři
|
| 275 |
all_files = os.listdir(tmp)
|
|
@@ -283,6 +292,7 @@ def run_script(script: str, output_format: str, dataset_info: Dict[str, Any] = N
|
|
| 283 |
"stderr": res.stderr,
|
| 284 |
"output_b64": data_b64,
|
| 285 |
"all_files": [os.path.basename(f) for f in all_output_files], # Debug info
|
|
|
|
| 286 |
}
|
| 287 |
|
| 288 |
|
|
@@ -308,6 +318,7 @@ def advanced_visualization(req: VisualizationRequest) -> Dict[str, Any]:
|
|
| 308 |
},
|
| 309 |
"generated_files": result.get("all_files", []), # Seznam všech vygenerovaných souborů
|
| 310 |
"file_count": len(result.get("all_files", [])), # Počet vygenerovaných souborů
|
|
|
|
| 311 |
}
|
| 312 |
except HTTPException:
|
| 313 |
raise
|
|
@@ -318,4 +329,4 @@ def advanced_visualization(req: VisualizationRequest) -> Dict[str, Any]:
|
|
| 318 |
if __name__ == "__main__":
|
| 319 |
import uvicorn
|
| 320 |
|
| 321 |
-
uvicorn.run(app, host="0.0.0.0", port=int(os.getenv("PORT", "7860")))
|
|
|
|
| 253 |
if not output_file:
|
| 254 |
output_file = file_path
|
| 255 |
|
| 256 |
+
# Převeď na base64 - sbírej všechny soubory (galerie) a pro kompatibilitu nech i single preview
|
| 257 |
data_b64 = ""
|
| 258 |
+
gallery_b64: list[str] = []
|
| 259 |
if all_output_files:
|
| 260 |
# Najdi největší soubor
|
| 261 |
largest_file = max(all_output_files, key=lambda f: os.path.getsize(f) if os.path.exists(f) else 0)
|
|
|
|
| 265 |
if len(blob) > max_output:
|
| 266 |
raise HTTPException(status_code=413, detail="Výstup je příliš velký")
|
| 267 |
data_b64 = base64.b64encode(blob).decode("utf-8")
|
| 268 |
+
# Naplň galerii
|
| 269 |
+
for fpath in all_output_files:
|
| 270 |
+
if os.path.exists(fpath):
|
| 271 |
+
with open(fpath, "rb") as fb:
|
| 272 |
+
blob = fb.read()
|
| 273 |
+
if len(blob) <= max_output:
|
| 274 |
+
gallery_b64.append(base64.b64encode(blob).decode("utf-8"))
|
| 275 |
elif output_file and os.path.exists(output_file):
|
| 276 |
with open(output_file, "rb") as f:
|
| 277 |
blob = f.read()
|
| 278 |
if len(blob) > max_output:
|
| 279 |
raise HTTPException(status_code=413, detail="Výstup je příliš velký")
|
| 280 |
data_b64 = base64.b64encode(blob).decode("utf-8")
|
| 281 |
+
gallery_b64 = [data_b64]
|
| 282 |
else:
|
| 283 |
# Debug: vypiš všechny soubory v tmp adresáři
|
| 284 |
all_files = os.listdir(tmp)
|
|
|
|
| 292 |
"stderr": res.stderr,
|
| 293 |
"output_b64": data_b64,
|
| 294 |
"all_files": [os.path.basename(f) for f in all_output_files], # Debug info
|
| 295 |
+
"gallery_b64": gallery_b64,
|
| 296 |
}
|
| 297 |
|
| 298 |
|
|
|
|
| 318 |
},
|
| 319 |
"generated_files": result.get("all_files", []), # Seznam všech vygenerovaných souborů
|
| 320 |
"file_count": len(result.get("all_files", [])), # Počet vygenerovaných souborů
|
| 321 |
+
"visualizations_multi": result.get("gallery_b64", []),
|
| 322 |
}
|
| 323 |
except HTTPException:
|
| 324 |
raise
|
|
|
|
| 329 |
if __name__ == "__main__":
|
| 330 |
import uvicorn
|
| 331 |
|
| 332 |
+
uvicorn.run(app, host="0.0.0.0", port=int(os.getenv("PORT", "7860")))
|