Spaces:
Configuration error
Configuration error
Keep workspace images full-res and fix example loader quality
Browse files
app.py
CHANGED
|
@@ -1352,22 +1352,9 @@ def load_image(file_path, page_num=1):
|
|
| 1352 |
def _scale_workspace_image(img, workspace_scale):
|
| 1353 |
if img is None:
|
| 1354 |
return None
|
| 1355 |
-
|
| 1356 |
-
|
| 1357 |
-
|
| 1358 |
-
scale = WORKSPACE_DEFAULT_SCALE
|
| 1359 |
-
# Target a predictable initial in-canvas zoom by fitting image into
|
| 1360 |
-
# a virtual viewport derived from editor size and requested scale.
|
| 1361 |
-
target_ratio = max(0.6, min(2.2, scale / 100.0))
|
| 1362 |
-
max_w = max(1, int(round(WORKSPACE_EDITOR_WIDTH_EST / target_ratio)))
|
| 1363 |
-
max_h = max(1, int(round(WORKSPACE_EDITOR_HEIGHT / target_ratio)))
|
| 1364 |
-
fit_ratio = min(max_w / max(1, img.width), max_h / max(1, img.height), 1.0)
|
| 1365 |
-
if fit_ratio >= 0.999:
|
| 1366 |
-
return img
|
| 1367 |
-
new_w = max(1, int(round(img.width * fit_ratio)))
|
| 1368 |
-
new_h = max(1, int(round(img.height * fit_ratio)))
|
| 1369 |
-
resample = Image.Resampling.BILINEAR if hasattr(Image, "Resampling") else Image.BILINEAR
|
| 1370 |
-
return img.resize((new_w, new_h), resample)
|
| 1371 |
|
| 1372 |
def _prepare_workspace_image(img, workspace_scale=WORKSPACE_DEFAULT_SCALE):
|
| 1373 |
if img is None:
|
|
@@ -1382,6 +1369,9 @@ def load_image_with_size(file_path, page_num=1, workspace_scale=WORKSPACE_DEFAUL
|
|
| 1382 |
def load_example_into_workspace(example_value):
|
| 1383 |
if example_value is None:
|
| 1384 |
return None, None, None
|
|
|
|
|
|
|
|
|
|
| 1385 |
if isinstance(example_value, Image.Image):
|
| 1386 |
img = example_value
|
| 1387 |
else:
|
|
@@ -1557,7 +1547,7 @@ with gr.Blocks(**blocks_kwargs) as demo:
|
|
| 1557 |
if HAS_REGION_WORKSPACE and region_editor is not None:
|
| 1558 |
image_examples_input = gr.Image(
|
| 1559 |
label="Example Loader",
|
| 1560 |
-
type="
|
| 1561 |
visible=False,
|
| 1562 |
show_label=False,
|
| 1563 |
)
|
|
@@ -1595,7 +1585,7 @@ with gr.Blocks(**blocks_kwargs) as demo:
|
|
| 1595 |
2. Choose **Input Scope**:
|
| 1596 |
- `Entire Page` for the full page.
|
| 1597 |
- `Selected Region` for a specific area.
|
| 1598 |
-
2a. Workspace
|
| 1599 |
3. For `Selected Region`, use the **Image Workspace**:
|
| 1600 |
- Recommended: freehand selection (draw/highlight target); app uses an automatic bounding box around your marks.
|
| 1601 |
- Optional rectangle selection: use the **Crop** tool.
|
|
|
|
| 1352 |
def _scale_workspace_image(img, workspace_scale):
|
| 1353 |
if img is None:
|
| 1354 |
return None
|
| 1355 |
+
# Keep native pixels for workspace quality. Gradio's in-canvas zoom controls
|
| 1356 |
+
# visual scale; pre-resampling here causes blurry math when users zoom in.
|
| 1357 |
+
return img
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1358 |
|
| 1359 |
def _prepare_workspace_image(img, workspace_scale=WORKSPACE_DEFAULT_SCALE):
|
| 1360 |
if img is None:
|
|
|
|
| 1369 |
def load_example_into_workspace(example_value):
|
| 1370 |
if example_value is None:
|
| 1371 |
return None, None, None
|
| 1372 |
+
if isinstance(example_value, str):
|
| 1373 |
+
img = load_image(example_value, 1)
|
| 1374 |
+
return _prepare_workspace_image(img, WORKSPACE_DEFAULT_SCALE)
|
| 1375 |
if isinstance(example_value, Image.Image):
|
| 1376 |
img = example_value
|
| 1377 |
else:
|
|
|
|
| 1547 |
if HAS_REGION_WORKSPACE and region_editor is not None:
|
| 1548 |
image_examples_input = gr.Image(
|
| 1549 |
label="Example Loader",
|
| 1550 |
+
type="filepath",
|
| 1551 |
visible=False,
|
| 1552 |
show_label=False,
|
| 1553 |
)
|
|
|
|
| 1585 |
2. Choose **Input Scope**:
|
| 1586 |
- `Entire Page` for the full page.
|
| 1587 |
- `Selected Region` for a specific area.
|
| 1588 |
+
2a. Workspace keeps native image resolution for clarity (especially equations); use in-canvas zoom/pan as needed.
|
| 1589 |
3. For `Selected Region`, use the **Image Workspace**:
|
| 1590 |
- Recommended: freehand selection (draw/highlight target); app uses an automatic bounding box around your marks.
|
| 1591 |
- Optional rectangle selection: use the **Crop** tool.
|