Skip to content

Commit

Permalink
Minor ruff fix all
Browse files Browse the repository at this point in the history
  • Loading branch information
haixuanTao committed Jan 14, 2025
1 parent ed6ff42 commit 220a747
Show file tree
Hide file tree
Showing 48 changed files with 134 additions and 194 deletions.
2 changes: 1 addition & 1 deletion node-hub/dora-argotranslate/dora_argotranslate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

# Read the content of the README file
try:
with open(readme_path, "r", encoding="utf-8") as f:
with open(readme_path, encoding="utf-8") as f:
__doc__ = f.read()
except FileNotFoundError:
__doc__ = "README file not found."
4 changes: 2 additions & 2 deletions node-hub/dora-argotranslate/dora_argotranslate/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
available_packages = argostranslate.package.get_available_packages()
package_to_install = next(
filter(
lambda x: x.from_code == from_code and x.to_code == to_code, available_packages
)
lambda x: x.from_code == from_code and x.to_code == to_code, available_packages,
),
)
argostranslate.package.install_from_path(package_to_install.download())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

# Read the content of the README file
try:
with open(readme_path, "r", encoding="utf-8") as f:
with open(readme_path, encoding="utf-8") as f:
__doc__ = f.read()
except FileNotFoundError:
__doc__ = "README file not found."
4 changes: 2 additions & 2 deletions node-hub/dora-distil-whisper/dora_distil_whisper/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def cut_repetition(text, min_repeat_length=4, max_repeat_length=50):
if sum(1 for char in text if "\u4e00" <= char <= "\u9fff") / len(text) > 0.5:
# Chinese text processing
for repeat_length in range(
min_repeat_length, min(max_repeat_length, len(text) // 2)
min_repeat_length, min(max_repeat_length, len(text) // 2),
):
for i in range(len(text) - repeat_length * 2 + 1):
chunk1 = text[i : i + repeat_length]
Expand All @@ -90,7 +90,7 @@ def cut_repetition(text, min_repeat_length=4, max_repeat_length=50):
# Non-Chinese (space-separated) text processing
words = text.split()
for repeat_length in range(
min_repeat_length, min(max_repeat_length, len(words) // 2)
min_repeat_length, min(max_repeat_length, len(words) // 2),
):
for i in range(len(words) - repeat_length * 2 + 1):
chunk1 = " ".join(words[i : i + repeat_length])
Expand Down
2 changes: 1 addition & 1 deletion node-hub/dora-echo/dora_echo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

# Read the content of the README file
try:
with open(readme_path, "r", encoding="utf-8") as f:
with open(readme_path, encoding="utf-8") as f:
__doc__ = f.read()
except FileNotFoundError:
__doc__ = "README file not found."
2 changes: 1 addition & 1 deletion node-hub/dora-echo/dora_echo/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def main():
args = parser.parse_args()

node = Node(
args.name
args.name,
) # provide the name to connect to the dataflow if dynamic node

for event in node:
Expand Down
2 changes: 1 addition & 1 deletion node-hub/dora-internvl/dora_internvl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

# Read the content of the README file
try:
with open(readme_path, "r", encoding="utf-8") as f:
with open(readme_path, encoding="utf-8") as f:
__doc__ = f.read()
except FileNotFoundError:
__doc__ = "README file not found."
17 changes: 7 additions & 10 deletions node-hub/dora-internvl/dora_internvl/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def build_transform(input_size):
T.Resize((input_size, input_size), interpolation=InterpolationMode.BICUBIC),
T.ToTensor(),
T.Normalize(mean=MEAN, std=STD),
]
],
)
return transform

Expand All @@ -43,7 +43,7 @@ def find_closest_aspect_ratio(aspect_ratio, target_ratios, width, height, image_


def dynamic_preprocess(
image, min_num=1, max_num=12, image_size=448, use_thumbnail=False
image, min_num=1, max_num=12, image_size=448, use_thumbnail=False,
):
orig_width, orig_height = image.size
aspect_ratio = orig_width / orig_height
Expand All @@ -60,7 +60,7 @@ def dynamic_preprocess(

# find the closest aspect ratio to the target
target_aspect_ratio = find_closest_aspect_ratio(
aspect_ratio, target_ratios, orig_width, orig_height, image_size
aspect_ratio, target_ratios, orig_width, orig_height, image_size,
)

# calculate the target width and height
Expand Down Expand Up @@ -92,7 +92,7 @@ def load_image(image_array: np.array, input_size=448, max_num=12):
image = Image.fromarray(image_array).convert("RGB")
transform = build_transform(input_size=input_size)
images = dynamic_preprocess(
image, image_size=input_size, use_thumbnail=True, max_num=max_num
image, image_size=input_size, use_thumbnail=True, max_num=max_num,
)
pixel_values = [transform(image) for image in images]
pixel_values = torch.stack(pixel_values)
Expand All @@ -117,7 +117,7 @@ def main():
.to(device)
)
tokenizer = AutoTokenizer.from_pretrained(
model_path, trust_remote_code=True, use_fast=False
model_path, trust_remote_code=True, use_fast=False,
)

node = Node()
Expand All @@ -139,10 +139,7 @@ def main():
width = metadata["width"]
height = metadata["height"]

if encoding == "bgr8":
channels = 3
storage_type = np.uint8
elif encoding == "rgb8":
if encoding == "bgr8" or encoding == "rgb8":
channels = 3
storage_type = np.uint8
else:
Expand All @@ -169,7 +166,7 @@ def main():
)
generation_config = dict(max_new_tokens=1024, do_sample=True)
response = model.chat(
tokenizer, pixel_values, question, generation_config
tokenizer, pixel_values, question, generation_config,
)
node.send_output(
"text",
Expand Down
2 changes: 1 addition & 1 deletion node-hub/dora-keyboard/dora_keyboard/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

# Read the content of the README file
try:
with open(readme_path, "r", encoding="utf-8") as f:
with open(readme_path, encoding="utf-8") as f:
__doc__ = f.read()
except FileNotFoundError:
__doc__ = "README file not found."
2 changes: 1 addition & 1 deletion node-hub/dora-microphone/dora_microphone/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

# Read the content of the README file
try:
with open(readme_path, "r", encoding="utf-8") as f:
with open(readme_path, encoding="utf-8") as f:
__doc__ = f.read()
except FileNotFoundError:
__doc__ = "README file not found."
5 changes: 2 additions & 3 deletions node-hub/dora-microphone/dora_microphone/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ def main():
always_none = node.next(timeout=0.001) is None
finished = False

# noqa
def callback(indata, frames, time, status):
nonlocal buffer, node, start_recording_time, finished

Expand All @@ -36,7 +35,7 @@ def callback(indata, frames, time, status):

# Start recording
with sd.InputStream(
callback=callback, dtype=np.int16, channels=1, samplerate=SAMPLE_RATE
callback=callback, dtype=np.int16, channels=1, samplerate=SAMPLE_RATE,
):
while not finished:
sd.sleep(int(1000))
sd.sleep(1000)
2 changes: 1 addition & 1 deletion node-hub/dora-openai-server/dora_openai_server/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

# Read the content of the README file
try:
with open(readme_path, "r", encoding="utf-8") as f:
with open(readme_path, encoding="utf-8") as f:
__doc__ = f.read()
except FileNotFoundError:
__doc__ = "README file not found."
16 changes: 4 additions & 12 deletions node-hub/dora-openai-server/dora_openai_server/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,7 @@ async def create_chat_completion(request: ChatCompletionRequest):
print("Passing input as string")
if isinstance(data, list):
data = pa.array(data) # initialize pyarrow array
elif isinstance(data, str):
data = pa.array([data])
elif isinstance(data, int):
data = pa.array([data])
elif isinstance(data, float):
data = pa.array([data])
elif isinstance(data, dict):
elif isinstance(data, str) or isinstance(data, int) or isinstance(data, float) or isinstance(data, dict):
data = pa.array([data])
else:
data = pa.array(data) # initialize pyarrow array
Expand All @@ -74,12 +68,10 @@ async def create_chat_completion(request: ChatCompletionRequest):
if event["type"] == "ERROR":
response_str = "No response received. Err: " + event["value"][0].as_py()
break
elif event["type"] == "INPUT" and event["id"] == "v1/chat/completions":
if event["type"] == "INPUT" and event["id"] == "v1/chat/completions":
response = event["value"]
response_str = response[0].as_py() if response else "No response received"
break
else:
pass

return ChatCompletionResponse(
id="chatcmpl-1234",
Expand All @@ -91,7 +83,7 @@ async def create_chat_completion(request: ChatCompletionRequest):
"index": 0,
"message": {"role": "assistant", "content": response_str},
"finish_reason": "stop",
}
},
],
usage={
"prompt_tokens": len(data),
Expand All @@ -111,7 +103,7 @@ async def list_models():
"object": "model",
"created": 1677610602,
"owned_by": "openai",
}
},
],
}

Expand Down
2 changes: 1 addition & 1 deletion node-hub/dora-opus/dora_opus/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

# Read the content of the README file
try:
with open(readme_path, "r", encoding="utf-8") as f:
with open(readme_path, encoding="utf-8") as f:
__doc__ = f.read()
except FileNotFoundError:
__doc__ = "README file not found."
4 changes: 2 additions & 2 deletions node-hub/dora-opus/dora_opus/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def cut_repetition(text, min_repeat_length=4, max_repeat_length=50):
if sum(1 for char in text if "\u4e00" <= char <= "\u9fff") / len(text) > 0.5:
# Chinese text processing
for repeat_length in range(
min_repeat_length, min(max_repeat_length, len(text) // 2)
min_repeat_length, min(max_repeat_length, len(text) // 2),
):
for i in range(len(text) - repeat_length * 2 + 1):
chunk1 = text[i : i + repeat_length]
Expand All @@ -41,7 +41,7 @@ def cut_repetition(text, min_repeat_length=4, max_repeat_length=50):
# Non-Chinese (space-separated) text processing
words = text.split()
for repeat_length in range(
min_repeat_length, min(max_repeat_length, len(words) // 2)
min_repeat_length, min(max_repeat_length, len(words) // 2),
):
for i in range(len(words) - repeat_length * 2 + 1):
chunk1 = " ".join(words[i : i + repeat_length])
Expand Down
2 changes: 1 addition & 1 deletion node-hub/dora-outtetts/dora_outtetts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

# Read the content of the README file
try:
with open(readme_path, "r", encoding="utf-8") as f:
with open(readme_path, encoding="utf-8") as f:
__doc__ = f.read()
except FileNotFoundError:
__doc__ = "README file not found."
3 changes: 1 addition & 2 deletions node-hub/dora-outtetts/dora_outtetts/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ def create_speaker(interface, path):
interface.save_speaker(speaker, "speaker.json")

print("saved speaker.json")
return


def main(arg_list: list[str] | None = None):
Expand Down Expand Up @@ -86,7 +85,7 @@ def main(arg_list: list[str] | None = None):
f"""Node received:
id: {event["id"]},
value: {event["value"]},
metadata: {event["metadata"]}"""
metadata: {event["metadata"]}""",
)

elif event["id"] == "text":
Expand Down
2 changes: 1 addition & 1 deletion node-hub/dora-parler/dora_parler/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

# Read the content of the README file
try:
with open(readme_path, "r", encoding="utf-8") as f:
with open(readme_path, encoding="utf-8") as f:
__doc__ = f.read()
except FileNotFoundError:
__doc__ = "README file not found."
6 changes: 3 additions & 3 deletions node-hub/dora-parler/dora_parler/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
MODEL_NAME_OR_PATH = snapshot_download(MODEL_NAME_OR_PATH)

model = ParlerTTSForConditionalGeneration.from_pretrained(
MODEL_NAME_OR_PATH, torch_dtype=torch_dtype, low_cpu_mem_usage=True
MODEL_NAME_OR_PATH, torch_dtype=torch_dtype, low_cpu_mem_usage=True,
).to(device)
model.generation_config.cache_implementation = "static"
model.forward = torch.compile(model.forward, mode="default")
Expand Down Expand Up @@ -72,7 +72,7 @@ def __init__(self):
self.stop_signal = False

def __call__(
self, input_ids: torch.LongTensor, scores: torch.FloatTensor, **kwargs
self, input_ids: torch.LongTensor, scores: torch.FloatTensor, **kwargs,
) -> bool:
return self.stop_signal

Expand Down Expand Up @@ -125,7 +125,7 @@ def generate_base(
if event["id"] == "stop":
stopping_criteria.stop()
break
elif event["id"] == "text":
if event["id"] == "text":
stopping_criteria.stop()

text = event["value"][0].as_py()
Expand Down
2 changes: 1 addition & 1 deletion node-hub/dora-piper/dora_piper/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

# Read the content of the README file
try:
with open(readme_path, "r", encoding="utf-8") as f:
with open(readme_path, encoding="utf-8") as f:
__doc__ = f.read()
except FileNotFoundError:
__doc__ = "README file not found."
3 changes: 1 addition & 2 deletions node-hub/dora-piper/dora_piper/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@


def enable_fun(piper: C_PiperInterface):
"""
使能机械臂并检测使能状态,尝试5s,如果使能超时则退出程序
"""使能机械臂并检测使能状态,尝试5s,如果使能超时则退出程序
"""
enable_flag = False
# 设置超时时间(秒)
Expand Down
2 changes: 1 addition & 1 deletion node-hub/dora-pyorbbecksdk/dora_pyorbbecksdk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

# Read the content of the README file
try:
with open(readme_path, "r", encoding="utf-8") as f:
with open(readme_path, encoding="utf-8") as f:
__doc__ = f.read()
except FileNotFoundError:
__doc__ = "README file not found."
Loading

0 comments on commit 220a747

Please sign in to comment.