Spaces:
Runtime error
Runtime error
init
Browse filesFiles changed (7)
- .gitattributes+2
- .gitignoreAdded+2
- app.pyAdded+34
- assets/input_01.pngAdded
- assets/input_02.webpAdded
- core/base.pyAdded+48
- requirements.txtAdded+1
32 unmodified lines33343532 unmodified lines*.zip filter=lfs diff=lfs merge=lfs -text*.zst filter=lfs diff=lfs merge=lfs -text*tfevents* filter=lfs diff=lfs merge=lfs -text32 unmodified lines333435363732 unmodified lines*.zip filter=lfs diff=lfs merge=lfs -text*.zst filter=lfs diff=lfs merge=lfs -text*tfevents* filter=lfs diff=lfs merge=lfs -textassets/input_01.png filter=lfs diff=lfs merge=lfs -textassets/input_02.webp filter=lfs diff=lfs merge=lfs -text
12__pycache__/gradio_cached_examples/12345678910111213141516171819202122232425262728293031323334import gradio as grfrom core.base import repeat_partent
with gr.Blocks(theme=gr.themes.Soft(primary_hue=gr.themes.colors.blue)) as demo: # ui with gr.Row(): with gr.Column(): image_input = gr.Image(label="Input Image", interactive=True, sources="upload", type="pil") with gr.Row(): new_width = gr.Textbox(label="Width", value="1024", type="text", interactive=True) new_height = gr.Textbox(label="Height", value="1024", type="text", interactive=True) image_output = gr.Image(label="Ouptut", interactive=False, show_download_button = True)
process_btn = gr.Button(value="process", variant="primary") process_btn.click( fn=repeat_partent, inputs=[image_input, new_width, new_height], outputs=[image_output], show_api=False ) gr.Examples( fn=repeat_partent, examples=[ ["assets/input_01.png", "3072", "3072"], ["assets/input_02.webp", "4096", "2048"], ], inputs=[image_input, new_width, new_height], outputs=[image_output], cache_examples = True)demo.queue().launch()123456789101112131415161718192021222324252627282930313233343536373839404142434445464748from PIL import Image
def repeat_partent(image: Image, new_width: str, new_height: str): ''' This function takes an image and repeats the partent in the image to fill the target_tile_size. ''' width, height = image.size new_width, new_height = int(new_width), int(new_height) # calculate the width of every partent in the image o = new_width//width list_width = [width]*o r = new_width%width if r > 0: list_width.append(r) # calculate the height of every partent in the image o = new_height//height list_height = [height]*o r = new_height%height if r > 0: list_height.append(r) # create a new image with the new width and height new_image = Image.new('RGB', (new_width, new_height)) w_start, h_start = 0, 0 for w in list_width: for h in list_height: if h < height or w < width: new_image.paste(image.crop((0, 0, w, h)), (w_start, h_start)) else: new_image.paste(image, (w_start, h_start)) h_start += h w_start += w h_start = 0 return new_image
# test the functionif __name__ == '__main__': image = Image.open("input.png") result = repeat_partent(image=image, new_width=2000, new_height=1000) result.save("output.png") 1gradio.gitattributes+2
.gitignoreAdded+2
app.pyAdded+34
assets/input_01.pngAdded

Large File Pointer Details
- SHA256: c062f29c8272beeb8eff5cbddf3eeb99b3d4acae9d77881811b0181e113e94b8
- Pointer size: 132 Bytes
- Size of remote file: 5.24 MB
assets/input_02.webpAdded

Large File Pointer Details
- SHA256: 852d823b07a20ca7e5014f888beafb4b155eca4db3d6e702e45fadfeb2b688e8
- Pointer size: 131 Bytes
- Size of remote file: 912 kB
core/base.pyAdded+48
requirements.txtAdded+1