Spaces:
Runtime error
Runtime error
KJMAN678
commited on
Commit
·
f60665f
1
Parent(s):
85efe73
Add application file
Browse files- .gitignore +2 -0
- README.md +26 -0
- app.py +37 -0
- bul_image_maker.py +76 -0
- images/bul_image.jpg +0 -0
- requirements.txt +3 -0
.gitignore
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
.venv/
|
2 |
+
__pycache__/
|
README.md
CHANGED
@@ -9,4 +9,30 @@ app_file: app.py
|
|
9 |
pinned: false
|
10 |
---
|
11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
9 |
pinned: false
|
10 |
---
|
11 |
|
12 |
+
## ファイル構成
|
13 |
+
|
14 |
+
- app.py streamlit でのアプリ実装部分
|
15 |
+
- bul_image_maker.py ぼかし画像を作成
|
16 |
+
|
17 |
+
## アプリで作成される画像のサンプル
|
18 |
+
|
19 |
+
<img src="images/bul_image.jpg" width="200">
|
20 |
+
|
21 |
+
```sh:mac仮想環境作成
|
22 |
+
# 仮想環境の作成
|
23 |
+
python -m venv .venv
|
24 |
+
|
25 |
+
# 仮想環境のアクティベート
|
26 |
+
source .venv/bin/activate
|
27 |
+
|
28 |
+
# pip のアップグレード
|
29 |
+
python -m pip install --upgrade pip
|
30 |
+
|
31 |
+
# ライブラリのインストール
|
32 |
+
pip install -r requirements.txt
|
33 |
+
|
34 |
+
# streamlit アプリをローカルで起動
|
35 |
+
streamlit run app.py
|
36 |
+
```
|
37 |
+
|
38 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from sbul_image_maker import bul_image_maker
|
3 |
+
|
4 |
+
|
5 |
+
def main():
|
6 |
+
|
7 |
+
st.title("ぼやかしの入った白黒画像メーカー")
|
8 |
+
|
9 |
+
height = st.slider(
|
10 |
+
label="タテのサイズ",
|
11 |
+
min_value=200,
|
12 |
+
max_value=1000,
|
13 |
+
value=500,
|
14 |
+
)
|
15 |
+
|
16 |
+
width = st.slider(
|
17 |
+
label="ヨコのサイズ",
|
18 |
+
min_value=200,
|
19 |
+
max_value=1000,
|
20 |
+
value=500,
|
21 |
+
)
|
22 |
+
|
23 |
+
times = st.slider(
|
24 |
+
label="試行回数",
|
25 |
+
min_value=5,
|
26 |
+
max_value=100,
|
27 |
+
value=30,
|
28 |
+
)
|
29 |
+
|
30 |
+
if st.button("処理の実行"):
|
31 |
+
x = bul_image_maker(height, width, times)
|
32 |
+
st.image(x)
|
33 |
+
|
34 |
+
|
35 |
+
if __name__ == "__main__":
|
36 |
+
|
37 |
+
main()
|
bul_image_maker.py
ADDED
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import random
|
2 |
+
|
3 |
+
import matplotlib.pyplot as plt
|
4 |
+
import numpy as np
|
5 |
+
|
6 |
+
|
7 |
+
def bul_image_maker(height: int, width: int, times: int) -> None:
|
8 |
+
|
9 |
+
"""
|
10 |
+
ランダム + 累積和で画像を作って表示する
|
11 |
+
|
12 |
+
args:
|
13 |
+
height (int): 画像の縦サイズ
|
14 |
+
width (int): 画像の横サイズ
|
15 |
+
times (int): 累積和の計算を行う回数。数を増やすほどランダム性の高い画像となる
|
16 |
+
return: None
|
17 |
+
"""
|
18 |
+
|
19 |
+
H, W, N = (height, width, 256 // times)
|
20 |
+
|
21 |
+
coef_list = [random.choice([-1, 1]) for i in range(times)]
|
22 |
+
|
23 |
+
result = np.zeros((height, width, 3))
|
24 |
+
|
25 |
+
im = np.zeros((height, width))
|
26 |
+
|
27 |
+
for time in range(times):
|
28 |
+
|
29 |
+
H_start = random.randint((random.randint(1, H - 3)), H - 2)
|
30 |
+
H_end = H_start
|
31 |
+
W_start = random.randint(random.randint(1, W - 3), W - 2)
|
32 |
+
W_end = W_start
|
33 |
+
|
34 |
+
ABCD = []
|
35 |
+
|
36 |
+
for i in range(N):
|
37 |
+
ABCD.append(
|
38 |
+
[
|
39 |
+
random.randint(1, H_start),
|
40 |
+
random.randint(1, W_start),
|
41 |
+
random.randint(H_end, H),
|
42 |
+
random.randint(W_end, W),
|
43 |
+
]
|
44 |
+
)
|
45 |
+
|
46 |
+
Z = [[0] * (W + 2) for i in range(H + 2)] # Z = [[0] * (W+1)] * H だとダメっぽい
|
47 |
+
answer = [[0] * (W + 2) for i in range(H + 2)]
|
48 |
+
|
49 |
+
for i in range(N):
|
50 |
+
A, B, C, D = ABCD[i][0], ABCD[i][1], ABCD[i][2], ABCD[i][3]
|
51 |
+
|
52 |
+
Z[A][B] += 1 * coef_list[time]
|
53 |
+
Z[C + 1][D + 1] += 1 * coef_list[time]
|
54 |
+
Z[A][D + 1] -= 1 * coef_list[time]
|
55 |
+
Z[C + 1][B] -= 1 * coef_list[time]
|
56 |
+
|
57 |
+
# 横
|
58 |
+
for i in range(1, H + 1):
|
59 |
+
for j in range(1, W + 1):
|
60 |
+
answer[i][j] = answer[i][j - 1] + Z[i][j]
|
61 |
+
|
62 |
+
# 横
|
63 |
+
for i in range(1, W + 1):
|
64 |
+
for j in range(1, H + 1):
|
65 |
+
answer[j][i] = answer[j - 1][i] + answer[j][i]
|
66 |
+
|
67 |
+
im += np.array(answer)[1:-1, 1:-1]
|
68 |
+
|
69 |
+
im = im + (np.max(im) - np.min(im))
|
70 |
+
im = im * (255 / np.max(im))
|
71 |
+
im = im / np.max(im)
|
72 |
+
|
73 |
+
plt.axis("off")
|
74 |
+
plt.imshow(im)
|
75 |
+
|
76 |
+
return im
|
images/bul_image.jpg
ADDED
![]() |
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
matplotlib==3.6.2
|
2 |
+
numpy==1.23.5
|
3 |
+
streamlit==1.15.2
|