Skip to content

Commit 458c91d

Browse files
QYuFongQiuYuFong
andauthored
clean code (#1185)
Co-authored-by: qiuyufeng <[email protected]>
1 parent eff29d5 commit 458c91d

File tree

3 files changed

+38
-19
lines changed

3 files changed

+38
-19
lines changed

examples/opensora_hpcai/opensora/models/vae/vae.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,12 +252,14 @@ def build_module_from_config(config):
252252
- type: model class name
253253
- others: model init args
254254
"""
255+
supported_model = {"VideoAutoencoderKL": VideoAutoencoderKL, "VAE_Temporal_SD": VAE_Temporal_SD}
255256
cfg = config.copy()
256257
name = cfg.pop("type")
257258
kwargs = cfg
258-
259+
if name not in supported_model:
260+
raise ValueError(f"Get unsupported model type {name}")
259261
# FIXME: use importlib with path
260-
module = eval(name)(**kwargs)
262+
module = supported_model[name](**kwargs)
261263
return module
262264

263265

examples/step_video_t2v/api/call_remote_server.py

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import argparse
66
import ast
77
import os
8-
import pickle
98
import threading
109

1110
from flask import Blueprint, Flask, Response, request
@@ -91,14 +90,20 @@ def get(self):
9190
# print("Caught Exception: ", e)
9291
# return Response(e)
9392

94-
feature = pickle.loads(request.get_data())
95-
feature["api"] = "vae"
96-
97-
feature = {k: v for k, v in feature.items() if v is not None}
98-
video_latents = self.vae_pipeline.decode(**feature)
99-
100-
response = pickle.dumps(video_latents)
101-
93+
print(
94+
"Using pickle to transfer data may bring security risks. "
95+
"Please confirm the security risks before using this API."
96+
"You can remove the comment markers of L99 ~ L104 and "
97+
"add a comment marker at L105 ~ L106 to re-enable the code."
98+
)
99+
# import pickle
100+
# feature = pickle.loads(request.get_data())
101+
# feature["api"] = "vae"
102+
# feature = {k: v for k, v in feature.items() if v is not None}
103+
# video_latents = self.vae_pipeline.decode(**feature)
104+
# response = pickle.dumps(video_latents)
105+
feature = request.get_data()
106+
response = feature
102107
return Response(response)
103108

104109

@@ -164,13 +169,20 @@ def get(self):
164169
# print("Caught Exception: ", e)
165170
# return Response(e)
166171

167-
feature = pickle.loads(request.get_data())
168-
feature["api"] = "caption"
169-
170-
feature = {k: v for k, v in feature.items() if v is not None}
171-
embeddings = self.caption_pipeline.embedding(**feature)
172-
response = pickle.dumps(embeddings)
173-
172+
print(
173+
"Using pickle to transfer data may bring security risks. "
174+
"Please confirm the security risks before using this API."
175+
"You can remove the comment markers of L178 ~ L183 and "
176+
"add a comment marker at L184 ~ L185 to re-enable the code."
177+
)
178+
# import pickle
179+
# feature = pickle.loads(request.get_data())
180+
# feature["api"] = "caption"
181+
# feature = {k: v for k, v in feature.items() if v is not None}
182+
# embeddings = self.caption_pipeline.embedding(**feature)
183+
# response = pickle.dumps(embeddings)
184+
feature = request.get_data()
185+
response = feature
174186
return Response(response)
175187

176188

tools/t2v_curation/pipeline/splitting/cut.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import argparse
2+
import ast
3+
import json
24
import os
35
import subprocess
46
from functools import partial
@@ -28,7 +30,10 @@ def process_single_row(row, args):
2830
timestamp = row["timestamp"]
2931
if not (timestamp.startswith("[") and timestamp.endswith("]")):
3032
return False
31-
scene_list = eval(timestamp)
33+
try:
34+
scene_list = json.loads(timestamp)
35+
except json.JSONDecodeError:
36+
scene_list = ast.literal_eval(timestamp)
3237
scene_list = [(FrameTimecode(s, fps=100), FrameTimecode(t, fps=100)) for s, t in scene_list]
3338
else:
3439
scene_list = [None]

0 commit comments

Comments
 (0)