Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -780,14 +780,14 @@ def make_square(img: np.ndarray):
|
|
| 780 |
|
| 781 |
return padded
|
| 782 |
|
| 783 |
-
def predict_with_paper(image, paper_size, offset, finger_clearance=False):
|
| 784 |
"""Main prediction function using paper as reference"""
|
| 785 |
|
| 786 |
logger.info(f"Starting prediction with image shape: {image.shape}")
|
| 787 |
logger.info(f"Paper size: {paper_size}")
|
| 788 |
|
| 789 |
-
|
| 790 |
-
|
| 791 |
edge_radius = None
|
| 792 |
if edge_radius is None or edge_radius == 0:
|
| 793 |
edge_radius = 0.0001
|
|
@@ -902,7 +902,7 @@ def predict_with_paper(image, paper_size, offset, finger_clearance=False):
|
|
| 902 |
f"Scale: {scaling_factor:.4f} mm/px | Paper: {paper_size}"
|
| 903 |
)
|
| 904 |
|
| 905 |
-
def predict_full_paper(image, paper_size, offset_value_mm, enable_finger_cut, selected_outputs):
|
| 906 |
finger_flag = "On" if enable_finger_cut == "On" else "Off"
|
| 907 |
|
| 908 |
# Always get all outputs from predict_with_paper
|
|
@@ -910,6 +910,7 @@ def predict_full_paper(image, paper_size, offset_value_mm, enable_finger_cut, se
|
|
| 910 |
image,
|
| 911 |
paper_size,
|
| 912 |
offset=offset_value_mm,
|
|
|
|
| 913 |
finger_clearance=finger_flag,
|
| 914 |
)
|
| 915 |
|
|
@@ -957,14 +958,20 @@ if __name__ == "__main__":
|
|
| 957 |
|
| 958 |
with gr.Group():
|
| 959 |
gr.Markdown("### Contour Offset")
|
| 960 |
-
|
| 961 |
-
|
| 962 |
-
|
| 963 |
-
|
| 964 |
-
|
| 965 |
-
|
| 966 |
-
|
| 967 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 968 |
|
| 969 |
with gr.Group():
|
| 970 |
gr.Markdown("### Finger Cuts")
|
|
@@ -1015,7 +1022,8 @@ if __name__ == "__main__":
|
|
| 1015 |
inputs=[
|
| 1016 |
input_image,
|
| 1017 |
paper_size,
|
| 1018 |
-
offset_value_mm,
|
|
|
|
| 1019 |
enable_finger_cut,
|
| 1020 |
output_options
|
| 1021 |
],
|
|
|
|
| 780 |
|
| 781 |
return padded
|
| 782 |
|
| 783 |
+
def predict_with_paper(image, paper_size, offset,offset_unit, finger_clearance=False):
|
| 784 |
"""Main prediction function using paper as reference"""
|
| 785 |
|
| 786 |
logger.info(f"Starting prediction with image shape: {image.shape}")
|
| 787 |
logger.info(f"Paper size: {paper_size}")
|
| 788 |
|
| 789 |
+
if offset_unit == "inches":
|
| 790 |
+
offset *= 25.4
|
| 791 |
edge_radius = None
|
| 792 |
if edge_radius is None or edge_radius == 0:
|
| 793 |
edge_radius = 0.0001
|
|
|
|
| 902 |
f"Scale: {scaling_factor:.4f} mm/px | Paper: {paper_size}"
|
| 903 |
)
|
| 904 |
|
| 905 |
+
def predict_full_paper(image, paper_size, offset_value_mm,offset_unit, enable_finger_cut, selected_outputs):
|
| 906 |
finger_flag = "On" if enable_finger_cut == "On" else "Off"
|
| 907 |
|
| 908 |
# Always get all outputs from predict_with_paper
|
|
|
|
| 910 |
image,
|
| 911 |
paper_size,
|
| 912 |
offset=offset_value_mm,
|
| 913 |
+
offset_unit= offset_unit,
|
| 914 |
finger_clearance=finger_flag,
|
| 915 |
)
|
| 916 |
|
|
|
|
| 958 |
|
| 959 |
with gr.Group():
|
| 960 |
gr.Markdown("### Contour Offset")
|
| 961 |
+
with gr.Row():
|
| 962 |
+
offset_value_mm = gr.Slider(
|
| 963 |
+
minimum=0,
|
| 964 |
+
maximum=50,
|
| 965 |
+
step=1,
|
| 966 |
+
value=0,
|
| 967 |
+
label="Offset",
|
| 968 |
+
info="Expand contours outward by this amount"
|
| 969 |
+
)
|
| 970 |
+
offset_unit = gr.Dropdown(
|
| 971 |
+
choices=["mm", "inches"],
|
| 972 |
+
value="mm",
|
| 973 |
+
label="Unit"
|
| 974 |
+
)
|
| 975 |
|
| 976 |
with gr.Group():
|
| 977 |
gr.Markdown("### Finger Cuts")
|
|
|
|
| 1022 |
inputs=[
|
| 1023 |
input_image,
|
| 1024 |
paper_size,
|
| 1025 |
+
offset_value_mm,
|
| 1026 |
+
offset_unit,
|
| 1027 |
enable_finger_cut,
|
| 1028 |
output_options
|
| 1029 |
],
|