11import os
22import os .path
3+ from typing import Optional
34
45from fastapi import HTTPException , Request
56from fastapi .responses import HTMLResponse , StreamingResponse
7+ from hydra .core .hydra_config import HydraConfig
68
79try :
810 # conditional on libmagic being installed on the machine
1719
1820
1921class MountOutputsFolder (GatewayModule ):
22+ dir : Optional [str ] = None
23+
2024 def connect (self , channels : GatewayChannels ) -> None :
21- # NO-OP
22- ...
25+ if self .dir is None :
26+ if HydraConfig .initialized ():
27+ self .dir = os .path .abspath (os .path .join (HydraConfig .get ().runtime .output_dir , ".." , ".." , ".." ))
28+ else :
29+ self .dir = os .path .abspath (os .path .join (os .getcwd (), "outputs" ))
2330
2431 def rest (self , app : GatewayWebApp ) -> None :
2532 app_router = app .get_router ("app" )
@@ -32,11 +39,10 @@ def browse_logs(full_path: str, request: Request):
3239 This endpoint is a small webpage for browsing the [hydra](https://github.com/facebookresearch/hydra)
3340 output logs and configuration settings of the running application.
3441 """
35- outputs_dir = os .path .join (os .getcwd (), "outputs" )
36- file_or_dir = outputs_dir
42+ file_or_dir = self .dir
3743 if full_path :
3844 file_or_dir = os .path .join (file_or_dir , full_path )
39- if os .path .abspath (file_or_dir ).startswith (outputs_dir ) and os .path .exists (file_or_dir ):
45+ if os .path .abspath (file_or_dir ).startswith (self . dir ) and os .path .exists (file_or_dir ):
4046 if os .path .isdir (file_or_dir ):
4147 files = os .listdir (file_or_dir )
4248 files_paths = sorted ([f"{ request .url ._url } /{ f } " .replace ("outputs//" , "outputs/" ) for f in files ])
0 commit comments