Spaces:
Build error
Build error
Commit
·
d966012
1
Parent(s):
24c77b9
Add application file
Browse files
app.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from PIL import Image, ImageDraw
|
| 3 |
+
import numpy as np
|
| 4 |
+
|
| 5 |
+
def draw_lines(x, y):
|
| 6 |
+
# キャンバスのサイズ
|
| 7 |
+
width, height = 1024, 1024
|
| 8 |
+
# 白背景のキャンバスを作成
|
| 9 |
+
image = Image.new("RGB", (width, height), "white")
|
| 10 |
+
draw = ImageDraw.Draw(image)
|
| 11 |
+
|
| 12 |
+
# 直線を描画する関数
|
| 13 |
+
def draw_rotated_line(angle):
|
| 14 |
+
rad = np.radians(angle)
|
| 15 |
+
cos_val = np.cos(rad)
|
| 16 |
+
sin_val = np.sin(rad)
|
| 17 |
+
# キャンバスの対角線の長さを計算
|
| 18 |
+
diagonal_length = np.sqrt(width**2 + height**2)
|
| 19 |
+
# 中心から端までの線を計算
|
| 20 |
+
line_length = diagonal_length
|
| 21 |
+
# 線の始点と終点を計算
|
| 22 |
+
start_x = x - line_length * cos_val
|
| 23 |
+
start_y = y - line_length * sin_val
|
| 24 |
+
end_x = x + line_length * cos_val
|
| 25 |
+
end_y = y + line_length * sin_val
|
| 26 |
+
# 線を描画
|
| 27 |
+
draw.line((start_x, start_y, end_x, end_y), fill="blue", width=2)
|
| 28 |
+
|
| 29 |
+
# 5度ずつ回転させながら直線を描画
|
| 30 |
+
for angle in range(0, 360, 5):
|
| 31 |
+
draw_rotated_line(angle)
|
| 32 |
+
|
| 33 |
+
# PIL Imageをnumpy配列に変換
|
| 34 |
+
return np.array(image)
|
| 35 |
+
|
| 36 |
+
# Gradioインターフェース
|
| 37 |
+
iface = gr.Interface(fn=draw_lines,
|
| 38 |
+
inputs=[gr.inputs.Slider(minimum=0, maximum=1024, default=512, label="X座標"),
|
| 39 |
+
gr.inputs.Slider(minimum=0, maximum=1024, default=512, label="Y座標")],
|
| 40 |
+
outputs="image",
|
| 41 |
+
live=True,
|
| 42 |
+
title="VP preprocess")
|
| 43 |
+
|
| 44 |
+
iface.launch()
|