Spaces:
Runtime error
Runtime error
Upload app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from PIL import Image, ImageFont
|
| 2 |
+
|
| 3 |
+
from handright import Template, handwrite
|
| 4 |
+
|
| 5 |
+
def handwritings(text):
|
| 6 |
+
template = Template(
|
| 7 |
+
background = Image.new(mode="1", size=(2048, 2048), color=1),
|
| 8 |
+
font=ImageFont.truetype("font.ttf", size=100),
|
| 9 |
+
line_spacing=150,
|
| 10 |
+
fill=0, # 字体“颜色”
|
| 11 |
+
left_margin=100,
|
| 12 |
+
top_margin=100,
|
| 13 |
+
right_margin=100,
|
| 14 |
+
bottom_margin=100,
|
| 15 |
+
word_spacing=15,
|
| 16 |
+
line_spacing_sigma=6, # 行间距随机扰动
|
| 17 |
+
font_size_sigma=20, # 字体大小随机扰动
|
| 18 |
+
word_spacing_sigma=3, # 字间距随机扰动
|
| 19 |
+
end_chars=",。", # 防止特定字符因排版算法的自动换行而出现在行首
|
| 20 |
+
perturb_x_sigma=4, # 笔画横向偏移随机扰动
|
| 21 |
+
perturb_y_sigma=4, # 笔画纵向偏移随机扰动
|
| 22 |
+
perturb_theta_sigma=0.05, # 笔画旋转偏移随机扰动
|
| 23 |
+
)
|
| 24 |
+
images = handwrite(text, template)
|
| 25 |
+
|
| 26 |
+
for i, im in enumerate(images):
|
| 27 |
+
assert isinstance(im, Image.Image)
|
| 28 |
+
# im.show()
|
| 29 |
+
return im
|
| 30 |
+
|
| 31 |
+
import gradio as gr
|
| 32 |
+
demo = gr.Interface(handwritings, "text", "image")
|
| 33 |
+
demo.launch()
|