Spaces:
Runtime error
Runtime error
Commit ·
272536e
1
Parent(s): 5488dc0
changed output
Browse files
app.py
CHANGED
|
@@ -110,7 +110,12 @@ def process(width:int, height:int, scale:float, image: np.ndarray):
|
|
| 110 |
|
| 111 |
packer.pack()
|
| 112 |
figure = packer.visualize()
|
| 113 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
|
| 115 |
if __name__ == "__main__":
|
| 116 |
with gr.Blocks() as demo:
|
|
@@ -121,31 +126,21 @@ if __name__ == "__main__":
|
|
| 121 |
"""
|
| 122 |
)
|
| 123 |
|
| 124 |
-
maxScale = gr.State(value=1.0)
|
| 125 |
with gr.Row():
|
| 126 |
with gr.Column():
|
| 127 |
image = gr.Image(image_mode="RGBA")
|
| 128 |
with gr.Row():
|
| 129 |
width = gr.Slider(value=1500, minimum=100, maximum=8000, label="Width")
|
| 130 |
height = gr.Slider(value=1500, minimum=100, maximum=8000, label="Height")
|
| 131 |
-
scale = gr.Slider(value=1.
|
| 132 |
fit = gr.Button("Submit")
|
| 133 |
|
| 134 |
with gr.Column():
|
| 135 |
plot_output = gr.Plot()
|
| 136 |
total = gr.Number(label="Total")
|
|
|
|
| 137 |
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
widthImage, heightImage = image.shape[:2]
|
| 141 |
-
scaler = int((width/widthImage + height/heightImage)/2)
|
| 142 |
-
scale.maximum = scaler
|
| 143 |
-
return {
|
| 144 |
-
maxScale: scaler
|
| 145 |
-
}
|
| 146 |
-
image.change(fn=update_scale, inputs=[width, height, image], outputs=[maxScale])
|
| 147 |
-
scale.maximum=5
|
| 148 |
-
fit.click(fn=process, inputs=[width, height, scale, image], outputs=[plot_output, total])
|
| 149 |
|
| 150 |
|
| 151 |
demo.launch()
|
|
|
|
| 110 |
|
| 111 |
packer.pack()
|
| 112 |
figure = packer.visualize()
|
| 113 |
+
if packer.total == 0:
|
| 114 |
+
text = "Input too big"
|
| 115 |
+
else:
|
| 116 |
+
text = f"Fit {packer.total} instances"
|
| 117 |
+
|
| 118 |
+
return [figure, text]
|
| 119 |
|
| 120 |
if __name__ == "__main__":
|
| 121 |
with gr.Blocks() as demo:
|
|
|
|
| 126 |
"""
|
| 127 |
)
|
| 128 |
|
|
|
|
| 129 |
with gr.Row():
|
| 130 |
with gr.Column():
|
| 131 |
image = gr.Image(image_mode="RGBA")
|
| 132 |
with gr.Row():
|
| 133 |
width = gr.Slider(value=1500, minimum=100, maximum=8000, label="Width")
|
| 134 |
height = gr.Slider(value=1500, minimum=100, maximum=8000, label="Height")
|
| 135 |
+
scale = gr.Slider(value=1.0, minimum=0, maximum=5, step=0.01, label="Input Scale")
|
| 136 |
fit = gr.Button("Submit")
|
| 137 |
|
| 138 |
with gr.Column():
|
| 139 |
plot_output = gr.Plot()
|
| 140 |
total = gr.Number(label="Total")
|
| 141 |
+
text = gr.Text()
|
| 142 |
|
| 143 |
+
fit.click(fn=process, inputs=[width, height, scale, image], outputs=[plot_output, text])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 144 |
|
| 145 |
|
| 146 |
demo.launch()
|