Spaces:
Running
Running
Commit
·
8dc0e4d
1
Parent(s):
1c00552
Quick fix for missing inference token
Browse files- io_utils.py +2 -10
io_utils.py
CHANGED
|
@@ -28,7 +28,6 @@ def read_scanners(uid):
|
|
| 28 |
with open(get_yaml_path(uid), "r") as f:
|
| 29 |
config = yaml.load(f, Loader=yaml.FullLoader)
|
| 30 |
scanners = config.get("detectors", [])
|
| 31 |
-
f.close()
|
| 32 |
return scanners
|
| 33 |
|
| 34 |
|
|
@@ -38,11 +37,9 @@ def write_scanners(scanners, uid):
|
|
| 38 |
config = yaml.load(f, Loader=yaml.FullLoader)
|
| 39 |
if config:
|
| 40 |
config["detectors"] = scanners
|
| 41 |
-
f.close()
|
| 42 |
# save scanners to detectors in yaml
|
| 43 |
with open(get_yaml_path(uid), "w") as f:
|
| 44 |
yaml.dump(config, f, Dumper=Dumper)
|
| 45 |
-
f.close()
|
| 46 |
|
| 47 |
|
| 48 |
# read model_type from yaml file
|
|
@@ -51,7 +48,6 @@ def read_inference_type(uid):
|
|
| 51 |
with open(get_yaml_path(uid), "r") as f:
|
| 52 |
config = yaml.load(f, Loader=yaml.FullLoader)
|
| 53 |
inference_type = config.get("inference_type", "")
|
| 54 |
-
f.close()
|
| 55 |
return inference_type
|
| 56 |
|
| 57 |
|
|
@@ -64,11 +60,11 @@ def write_inference_type(use_inference, inference_token, uid):
|
|
| 64 |
config["inference_token"] = inference_token
|
| 65 |
else:
|
| 66 |
config["inference_type"] = "hf_pipeline"
|
| 67 |
-
|
|
|
|
| 68 |
# save inference_type to inference_type in yaml
|
| 69 |
with open(get_yaml_path(uid), "w") as f:
|
| 70 |
yaml.dump(config, f, Dumper=Dumper)
|
| 71 |
-
f.close()
|
| 72 |
|
| 73 |
|
| 74 |
|
|
@@ -79,7 +75,6 @@ def read_column_mapping(uid):
|
|
| 79 |
config = yaml.load(f, Loader=yaml.FullLoader)
|
| 80 |
if config:
|
| 81 |
column_mapping = config.get("column_mapping", dict())
|
| 82 |
-
f.close()
|
| 83 |
return column_mapping
|
| 84 |
|
| 85 |
|
|
@@ -87,7 +82,6 @@ def read_column_mapping(uid):
|
|
| 87 |
def write_column_mapping(mapping, uid):
|
| 88 |
with open(get_yaml_path(uid), "r") as f:
|
| 89 |
config = yaml.load(f, Loader=yaml.FullLoader)
|
| 90 |
-
f.close()
|
| 91 |
|
| 92 |
if config is None:
|
| 93 |
return
|
|
@@ -98,7 +92,6 @@ def write_column_mapping(mapping, uid):
|
|
| 98 |
|
| 99 |
with open(get_yaml_path(uid), "w") as f:
|
| 100 |
yaml.dump(config, f, Dumper=Dumper)
|
| 101 |
-
f.close()
|
| 102 |
|
| 103 |
|
| 104 |
# convert column mapping dataframe to json
|
|
@@ -121,7 +114,6 @@ def get_logs_file(uid):
|
|
| 121 |
def write_log_to_user_file(id, log):
|
| 122 |
with open(f"./tmp/{id}_log", "a") as f:
|
| 123 |
f.write(log)
|
| 124 |
-
f.close()
|
| 125 |
|
| 126 |
|
| 127 |
def save_job_to_pipe(id, job, lock):
|
|
|
|
| 28 |
with open(get_yaml_path(uid), "r") as f:
|
| 29 |
config = yaml.load(f, Loader=yaml.FullLoader)
|
| 30 |
scanners = config.get("detectors", [])
|
|
|
|
| 31 |
return scanners
|
| 32 |
|
| 33 |
|
|
|
|
| 37 |
config = yaml.load(f, Loader=yaml.FullLoader)
|
| 38 |
if config:
|
| 39 |
config["detectors"] = scanners
|
|
|
|
| 40 |
# save scanners to detectors in yaml
|
| 41 |
with open(get_yaml_path(uid), "w") as f:
|
| 42 |
yaml.dump(config, f, Dumper=Dumper)
|
|
|
|
| 43 |
|
| 44 |
|
| 45 |
# read model_type from yaml file
|
|
|
|
| 48 |
with open(get_yaml_path(uid), "r") as f:
|
| 49 |
config = yaml.load(f, Loader=yaml.FullLoader)
|
| 50 |
inference_type = config.get("inference_type", "")
|
|
|
|
| 51 |
return inference_type
|
| 52 |
|
| 53 |
|
|
|
|
| 60 |
config["inference_token"] = inference_token
|
| 61 |
else:
|
| 62 |
config["inference_type"] = "hf_pipeline"
|
| 63 |
+
# FIXME: A quick and temp fix for missing token
|
| 64 |
+
config["inference_token"] = ""
|
| 65 |
# save inference_type to inference_type in yaml
|
| 66 |
with open(get_yaml_path(uid), "w") as f:
|
| 67 |
yaml.dump(config, f, Dumper=Dumper)
|
|
|
|
| 68 |
|
| 69 |
|
| 70 |
|
|
|
|
| 75 |
config = yaml.load(f, Loader=yaml.FullLoader)
|
| 76 |
if config:
|
| 77 |
column_mapping = config.get("column_mapping", dict())
|
|
|
|
| 78 |
return column_mapping
|
| 79 |
|
| 80 |
|
|
|
|
| 82 |
def write_column_mapping(mapping, uid):
|
| 83 |
with open(get_yaml_path(uid), "r") as f:
|
| 84 |
config = yaml.load(f, Loader=yaml.FullLoader)
|
|
|
|
| 85 |
|
| 86 |
if config is None:
|
| 87 |
return
|
|
|
|
| 92 |
|
| 93 |
with open(get_yaml_path(uid), "w") as f:
|
| 94 |
yaml.dump(config, f, Dumper=Dumper)
|
|
|
|
| 95 |
|
| 96 |
|
| 97 |
# convert column mapping dataframe to json
|
|
|
|
| 114 |
def write_log_to_user_file(id, log):
|
| 115 |
with open(f"./tmp/{id}_log", "a") as f:
|
| 116 |
f.write(log)
|
|
|
|
| 117 |
|
| 118 |
|
| 119 |
def save_job_to_pipe(id, job, lock):
|