Spaces:
Sleeping
Sleeping
Upload 9 files
Browse files- __pycache__/app.cpython-313.pyc +0 -0
- app.py +41 -11
__pycache__/app.cpython-313.pyc
CHANGED
|
Binary files a/__pycache__/app.cpython-313.pyc and b/__pycache__/app.cpython-313.pyc differ
|
|
|
app.py
CHANGED
|
@@ -82,7 +82,13 @@ def upload_training_images(files):
|
|
| 82 |
db = load_db()
|
| 83 |
if not files:
|
| 84 |
choices = [x["filename"] for x in db["images"]]
|
| 85 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
|
| 87 |
if not isinstance(files, list):
|
| 88 |
files = [files]
|
|
@@ -143,7 +149,20 @@ def upload_training_images(files):
|
|
| 143 |
msg = f"✅ Saved {saved} image(s) to {location}."
|
| 144 |
else:
|
| 145 |
msg = "⚠️ No images were saved."
|
| 146 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 147 |
|
| 148 |
|
| 149 |
def make_data_url(path):
|
|
@@ -739,6 +758,7 @@ with gr.Blocks(title="Anything Detector", js=ANNOTATOR_JS) as demo:
|
|
| 739 |
files = gr.File(
|
| 740 |
file_count="multiple",
|
| 741 |
file_types=["image"],
|
|
|
|
| 742 |
label="Training images",
|
| 743 |
)
|
| 744 |
save_images = gr.Button(
|
|
@@ -753,13 +773,17 @@ with gr.Blocks(title="Anything Detector", js=ANNOTATOR_JS) as demo:
|
|
| 753 |
label="Training image",
|
| 754 |
)
|
| 755 |
upload_status = gr.Markdown()
|
| 756 |
-
|
| 757 |
-
|
| 758 |
-
|
| 759 |
-
|
| 760 |
-
|
|
|
|
|
|
|
|
|
|
| 761 |
)
|
| 762 |
|
|
|
|
| 763 |
with gr.Tab("2 · Draw boxes"):
|
| 764 |
gr.Markdown(
|
| 765 |
"""
|
|
@@ -777,11 +801,11 @@ This is a native HTML5 canvas — there is no `gradio_image_annotation` package.
|
|
| 777 |
"""
|
| 778 |
)
|
| 779 |
|
|
|
|
|
|
|
| 780 |
ann_selector = gr.Dropdown(
|
| 781 |
-
choices=[
|
| 782 |
-
|
| 783 |
-
for x in load_db()["images"]
|
| 784 |
-
],
|
| 785 |
label="Image to annotate",
|
| 786 |
)
|
| 787 |
|
|
@@ -829,6 +853,12 @@ This is a native HTML5 canvas — there is no `gradio_image_annotation` package.
|
|
| 829 |
outputs=annotator_html,
|
| 830 |
)
|
| 831 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 832 |
annotation_payload.change(
|
| 833 |
save_annotation_payload,
|
| 834 |
inputs=annotation_payload,
|
|
|
|
| 82 |
db = load_db()
|
| 83 |
if not files:
|
| 84 |
choices = [x["filename"] for x in db["images"]]
|
| 85 |
+
return (
|
| 86 |
+
gr.update(choices=choices, value=choices[-1] if choices else None),
|
| 87 |
+
"⚠️ No images selected.",
|
| 88 |
+
[x["path"] for x in db["images"] if Path(x.get("path", "")).exists()],
|
| 89 |
+
gr.update(choices=choices, value=choices[-1] if choices else None),
|
| 90 |
+
annotation_html(choices[-1] if choices else None),
|
| 91 |
+
)
|
| 92 |
|
| 93 |
if not isinstance(files, list):
|
| 94 |
files = [files]
|
|
|
|
| 149 |
msg = f"✅ Saved {saved} image(s) to {location}."
|
| 150 |
else:
|
| 151 |
msg = "⚠️ No images were saved."
|
| 152 |
+
latest = choices[-1] if choices else None
|
| 153 |
+
gallery_value = [x["path"] for x in db["images"] if Path(x.get("path", "")).exists()]
|
| 154 |
+
annotator_value = (
|
| 155 |
+
f'<div class="annotator-shell" data-filename="{html.escape(latest or "", quote=True)}">'
|
| 156 |
+
f'{annotation_html(latest)}</div>'
|
| 157 |
+
if latest else annotation_html(None)
|
| 158 |
+
)
|
| 159 |
+
return (
|
| 160 |
+
gr.update(choices=choices, value=latest),
|
| 161 |
+
msg,
|
| 162 |
+
gallery_value,
|
| 163 |
+
gr.update(choices=choices, value=latest),
|
| 164 |
+
annotator_value,
|
| 165 |
+
)
|
| 166 |
|
| 167 |
|
| 168 |
def make_data_url(path):
|
|
|
|
| 758 |
files = gr.File(
|
| 759 |
file_count="multiple",
|
| 760 |
file_types=["image"],
|
| 761 |
+
type="filepath",
|
| 762 |
label="Training images",
|
| 763 |
)
|
| 764 |
save_images = gr.Button(
|
|
|
|
| 773 |
label="Training image",
|
| 774 |
)
|
| 775 |
upload_status = gr.Markdown()
|
| 776 |
+
saved_images = gr.Gallery(
|
| 777 |
+
value=[x["path"] for x in load_db()["images"] if Path(x.get("path", "")).exists()],
|
| 778 |
+
label="Saved training images",
|
| 779 |
+
columns=5,
|
| 780 |
+
rows=2,
|
| 781 |
+
height="auto",
|
| 782 |
+
object_fit="contain",
|
| 783 |
+
show_label=True,
|
| 784 |
)
|
| 785 |
|
| 786 |
+
|
| 787 |
with gr.Tab("2 · Draw boxes"):
|
| 788 |
gr.Markdown(
|
| 789 |
"""
|
|
|
|
| 801 |
"""
|
| 802 |
)
|
| 803 |
|
| 804 |
+
_initial_images = load_db()["images"]
|
| 805 |
+
_initial_filename = _initial_images[0]["filename"] if _initial_images else None
|
| 806 |
ann_selector = gr.Dropdown(
|
| 807 |
+
choices=[x["filename"] for x in _initial_images],
|
| 808 |
+
value=_initial_filename,
|
|
|
|
|
|
|
| 809 |
label="Image to annotate",
|
| 810 |
)
|
| 811 |
|
|
|
|
| 853 |
outputs=annotator_html,
|
| 854 |
)
|
| 855 |
|
| 856 |
+
save_images.click(
|
| 857 |
+
upload_training_images,
|
| 858 |
+
inputs=files,
|
| 859 |
+
outputs=[image_selector, upload_status, saved_images, ann_selector, annotator_html],
|
| 860 |
+
)
|
| 861 |
+
|
| 862 |
annotation_payload.change(
|
| 863 |
save_annotation_payload,
|
| 864 |
inputs=annotation_payload,
|