1
1
import os
2
2
import os .path
3
+ from typing import Optional
3
4
4
5
from fastapi import HTTPException , Request
5
6
from fastapi .responses import HTMLResponse , StreamingResponse
7
+ from hydra .core .hydra_config import HydraConfig
6
8
7
9
try :
8
10
# conditional on libmagic being installed on the machine
17
19
18
20
19
21
class MountOutputsFolder (GatewayModule ):
22
+ dir : Optional [str ] = None
23
+
20
24
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" ))
23
30
24
31
def rest (self , app : GatewayWebApp ) -> None :
25
32
app_router = app .get_router ("app" )
@@ -32,11 +39,10 @@ def browse_logs(full_path: str, request: Request):
32
39
This endpoint is a small webpage for browsing the [hydra](https://github.com/facebookresearch/hydra)
33
40
output logs and configuration settings of the running application.
34
41
"""
35
- outputs_dir = os .path .join (os .getcwd (), "outputs" )
36
- file_or_dir = outputs_dir
42
+ file_or_dir = self .dir
37
43
if full_path :
38
44
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 ):
40
46
if os .path .isdir (file_or_dir ):
41
47
files = os .listdir (file_or_dir )
42
48
files_paths = sorted ([f"{ request .url ._url } /{ f } " .replace ("outputs//" , "outputs/" ) for f in files ])
0 commit comments