Spaces:
Runtime error
Runtime error
init
Browse files- .gitattributes +2 -0
- .gitignore +2 -0
- app.py +34 -0
- assets/input_01.png +3 -0
- assets/input_02.webp +3 -0
- core/base.py +48 -0
- requirements.txt +1 -0
.gitattributes
CHANGED
@@ -33,3 +33,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
assets/input_01.png filter=lfs diff=lfs merge=lfs -text
|
37 |
+
assets/input_02.webp filter=lfs diff=lfs merge=lfs -text
|
.gitignore
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
__pycache__/
|
2 |
+
gradio_cached_examples/
|
app.py
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from core.base import repeat_partent
|
3 |
+
|
4 |
+
with gr.Blocks(theme=gr.themes.Soft(primary_hue=gr.themes.colors.blue)) as demo:
|
5 |
+
|
6 |
+
# ui
|
7 |
+
with gr.Row():
|
8 |
+
with gr.Column():
|
9 |
+
image_input = gr.Image(label="Input Image", interactive=True, sources="upload", type="pil")
|
10 |
+
with gr.Row():
|
11 |
+
new_width = gr.Textbox(label="Width", value="1024", type="text", interactive=True)
|
12 |
+
new_height = gr.Textbox(label="Height", value="1024", type="text", interactive=True)
|
13 |
+
image_output = gr.Image(label="Ouptut", interactive=False, show_download_button = True)
|
14 |
+
|
15 |
+
|
16 |
+
|
17 |
+
process_btn = gr.Button(value="process", variant="primary")
|
18 |
+
|
19 |
+
process_btn.click(
|
20 |
+
fn=repeat_partent,
|
21 |
+
inputs=[image_input, new_width, new_height],
|
22 |
+
outputs=[image_output],
|
23 |
+
show_api=False
|
24 |
+
)
|
25 |
+
gr.Examples(
|
26 |
+
fn=repeat_partent,
|
27 |
+
examples=[
|
28 |
+
["assets/input_01.png", "3072", "3072"],
|
29 |
+
["assets/input_02.webp", "4096", "2048"],
|
30 |
+
],
|
31 |
+
inputs=[image_input, new_width, new_height],
|
32 |
+
outputs=[image_output],
|
33 |
+
cache_examples = True)
|
34 |
+
demo.queue().launch()
|
assets/input_01.png
ADDED
![]() |
Git LFS Details
|
assets/input_02.webp
ADDED
![]() |
Git LFS Details
|
core/base.py
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from PIL import Image
|
2 |
+
|
3 |
+
|
4 |
+
def repeat_partent(image: Image, new_width: str, new_height: str):
|
5 |
+
'''
|
6 |
+
This function takes an image and repeats the partent in the image to fill the target_tile_size.
|
7 |
+
'''
|
8 |
+
|
9 |
+
width, height = image.size
|
10 |
+
new_width, new_height = int(new_width), int(new_height)
|
11 |
+
|
12 |
+
|
13 |
+
# calculate the width of every partent in the image
|
14 |
+
o = new_width//width
|
15 |
+
list_width = [width]*o
|
16 |
+
r = new_width%width
|
17 |
+
if r > 0:
|
18 |
+
list_width.append(r)
|
19 |
+
|
20 |
+
# calculate the height of every partent in the image
|
21 |
+
o = new_height//height
|
22 |
+
list_height = [height]*o
|
23 |
+
r = new_height%height
|
24 |
+
if r > 0:
|
25 |
+
list_height.append(r)
|
26 |
+
|
27 |
+
# create a new image with the new width and height
|
28 |
+
new_image = Image.new('RGB', (new_width, new_height))
|
29 |
+
w_start, h_start = 0, 0
|
30 |
+
for w in list_width:
|
31 |
+
for h in list_height:
|
32 |
+
if h < height or w < width:
|
33 |
+
new_image.paste(image.crop((0, 0, w, h)), (w_start, h_start))
|
34 |
+
else:
|
35 |
+
new_image.paste(image, (w_start, h_start))
|
36 |
+
h_start += h
|
37 |
+
|
38 |
+
w_start += w
|
39 |
+
h_start = 0
|
40 |
+
return new_image
|
41 |
+
|
42 |
+
# test the function
|
43 |
+
if __name__ == '__main__':
|
44 |
+
image = Image.open("input.png")
|
45 |
+
result = repeat_partent(image=image, new_width=2000, new_height=1000)
|
46 |
+
result.save("output.png")
|
47 |
+
|
48 |
+
|
requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
gradio
|