iruno commited on
Commit
d0126c7
·
verified ·
1 Parent(s): cb35226

Delete utils.py

Browse files
Files changed (1) hide show
  1. utils.py +0 -41
utils.py DELETED
@@ -1,41 +0,0 @@
1
- import tokenize
2
- import io
3
- import base64
4
- import numpy as np
5
- from PIL import Image
6
-
7
- def remove_inline_comments_safe(code: str) -> str:
8
- result = []
9
- tokens = tokenize.generate_tokens(io.StringIO(code).readline)
10
-
11
- last_line = -1
12
- current_line = ''
13
- for tok_type, tok_string, (srow, scol), (_, _), _ in tokens:
14
- if srow != last_line:
15
- if current_line:
16
- result.append(current_line.rstrip())
17
- current_line = ''
18
- last_line = srow
19
-
20
- if tok_type == tokenize.COMMENT:
21
- # 주석 무시 (아무 것도 추가하지 않음)
22
- continue
23
-
24
- current_line += tok_string
25
-
26
- if current_line:
27
- result.append(current_line.rstrip())
28
-
29
- return '\n'.join(result)
30
-
31
-
32
- def image_to_jpg_base64_url(image: Image.Image | np.ndarray) -> str:
33
- """Return a base64 *JPEG* data‑URL from a PIL image or NumPy array."""
34
- if isinstance(image, np.ndarray):
35
- image = Image.fromarray(image)
36
- if image.mode in {"RGBA", "LA"}:
37
- image = image.convert("RGB")
38
- with io.BytesIO() as buffer:
39
- image.save(buffer, format="JPEG")
40
- encoded: str = base64.b64encode(buffer.getvalue()).decode()
41
- return f"data:image/jpeg;base64,{encoded}"