diff --git a/annotation_gui.py b/annotation_gui.py
index f03768f6..68fa19d0 100644
--- a/annotation_gui.py
+++ b/annotation_gui.py
@@ -10,6 +10,7 @@ To set default paths, edit config.py
from __future__ import annotations
import argparse
+import html
import json
import subprocess
import threading
@@ -37,6 +38,212 @@ except ImportError:
DEFAULT_MODEL_SIZE = "small"
+# Gradio 6 sanitizes
"""
- return html
+ return html_out
def _format_boxes_text(self, boxes: list[dict]) -> str:
"""Format boxes for display."""
@@ -1282,7 +1270,11 @@ def create_ui(app: AnnotationApp) -> gr.Blocks:
with gr.Row():
with gr.Column(scale=3):
- image_display = gr.HTML(label="Current Image", value="
Load images from Settings to start annotating
")
+ image_display = gr.HTML(
+ label="Current Image",
+ value="Load images from Settings to start annotating
",
+ js_on_load=CANVAS_JS_ON_LOAD,
+ )
with gr.Row():
prev_btn = gr.Button("⬅️ Previous")
@@ -1291,7 +1283,7 @@ def create_ui(app: AnnotationApp) -> gr.Blocks:
save_canvas_btn = gr.Button("💾 Save Canvas Changes")
# Hidden textbox to store canvas boxes data
- canvas_boxes_data = gr.Textbox(visible=False)
+ canvas_boxes_data = gr.Textbox(visible=False, elem_id="canvas-boxes-data")
with gr.Row():
threshold_slider = gr.Slider(0.1, 0.9, DEFAULT_DETECTION_THRESHOLD, label="Detection Threshold")
@@ -1614,6 +1606,12 @@ def main():
default=Path(DEFAULT_MODEL_WEIGHTS) if DEFAULT_MODEL_WEIGHTS else None,
help="Default trained model for auto-labeling (can be changed in GUI)"
)
+ parser.add_argument(
+ "--port",
+ type=int,
+ default=DEFAULT_PORT,
+ help="Port to run the GUI on"
+ )
args = parser.parse_args()
# Validate paths if provided
@@ -1651,7 +1649,7 @@ def main():
demo.launch(
server_name="0.0.0.0",
- server_port=7860,
+ server_port=args.port,
share=False
)
diff --git a/run_gui.sh b/run_gui.sh
new file mode 100755
index 00000000..c6d08ce3
--- /dev/null
+++ b/run_gui.sh
@@ -0,0 +1,96 @@
+#!/bin/bash
+
+# Script to run the annotation GUI with automatic virtual environment detection
+
+# Get the directory of this script
+SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+
+# Change to the script directory
+cd "$SCRIPT_DIR"
+
+# Function to check if a command exists
+command_exists() {
+ command -v "$1" >/dev/null 2>&1
+}
+
+# Check for Python
+if ! command_exists python; then
+ echo "Error: Python is not installed or not in PATH"
+ exit 1
+fi
+
+# Check for virtual environment
+VENV_DIR=""
+if [ -d "venv" ]; then
+ VENV_DIR="venv"
+elif [ -d ".venv" ]; then
+ VENV_DIR=".venv"
+elif [ -d "env" ]; then
+ VENV_DIR="env"
+fi
+
+# Check for conda environment
+CONDA_ENV=""
+if command_exists conda; then
+ # Check if we're already in a conda environment
+ if [ -n "$CONDA_DEFAULT_ENV" ]; then
+ CONDA_ENV="$CONDA_DEFAULT_ENV"
+ else
+ # Try to find a conda environment with the project name
+ PROJECT_NAME=$(basename "$SCRIPT_DIR")
+ if conda env list | grep -q "^$PROJECT_NAME "; then
+ CONDA_ENV="$PROJECT_NAME"
+ fi
+ fi
+fi
+
+# Activate virtual environment
+if [ -n "$VENV_DIR" ]; then
+ echo "Activating virtual environment: $VENV_DIR"
+ source "$VENV_DIR/bin/activate"
+elif [ -n "$CONDA_ENV" ]; then
+ echo "Activating conda environment: $CONDA_ENV"
+ conda activate "$CONDA_ENV"
+else
+ echo "Warning: No virtual environment found. Using system Python."
+ echo "Consider creating a virtual environment with:"
+ echo " python -m venv venv"
+ echo " source venv/bin/activate"
+ echo " pip install -r requirements.txt"
+fi
+
+# Check if requirements are installed
+echo "Checking if dependencies are installed..."
+python -c "
+import sys
+try:
+ import gradio
+ import torch
+ import PIL
+ print('✓ Core dependencies are installed')
+except ImportError as e:
+ print(f'✗ Missing dependency: {e}')
+ print('Installing requirements...')
+ import subprocess
+ result = subprocess.run([sys.executable, '-m', 'pip', 'install', '-r', 'requirements.txt'],
+ capture_output=True, text=True)
+ if result.returncode != 0:
+ print('Failed to install requirements:')
+ print(result.stderr)
+ sys.exit(1)
+ else:
+ print('✓ Requirements installed successfully')
+"
+
+# Run the GUI
+echo "Starting annotation GUI..."
+python annotation_gui.py "$@"
+
+# Deactivate virtual environment if activated
+if [ -n "$VENV_DIR" ] || [ -n "$CONDA_ENV" ]; then
+ if [ -n "$VENV_DIR" ]; then
+ deactivate
+ elif [ -n "$CONDA_ENV" ]; then
+ conda deactivate
+ fi
+fi
\ No newline at end of file