Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add aga ui launch command #98

Merged
merged 7 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,18 @@ The Autogluon Assistant Web UI is a user-friendly application that allows users
The web UI enables users to upload datasets, configure Autogluon-Assistant runs with customized settings, preview data, monitor execution progress, view and download results, and supports secure, isolated sessions for concurrent users.

#### To run the Autogluon Assistant Web UI:
Navigate to the project directory and run the app:

````
cd src/autogluon_assistant/ui && streamlit run app.py
aga ui

# OR

# Launch Web-UI on specific port e.g. 8888
aga ui --port 8888

````
The Autogluon Assistant Web UI should now be accessible in your web browser at `http://localhost:8501`

Autogluon Assistant Web UI should now be accessible in your web browser at `http://localhost:8501`

#### Add GPT4 Model to the LLM Option:
If you’d like to add additional GPT4 model to the language model (LLM) dropdown:
Expand Down Expand Up @@ -99,8 +106,8 @@ Note:

Now you can launch the AutoGluon Assistant run using the following command:
```
aga [NAME_OF_DATA_DIR] --presets [PRESET_QUALITY]
# e.g. aga ./toy_data --presets best_quality
aga run [NAME_OF_DATA_DIR] --presets [PRESET_QUALITY]
# e.g. aga run ./toy_data --presets best_quality
```

We support three presets, including `medium_quality`, `high_quality` and `best_quality`. We use `best_quality` as a default setting.
Expand All @@ -113,9 +120,9 @@ the `config_overrides` parameter with Hydra syntax from the command line.

Here’s an example command with some configuration overrides:
```
aga toy_data --config_overrides "feature_transformers=[], autogluon.predictor_fit_kwargs.time_limit=3600"
aga run toy_data --config_overrides "feature_transformers=[], autogluon.predictor_fit_kwargs.time_limit=3600"

# OR

aga toy_data --config_overrides "feature_transformers=[]" --config_overrides "autogluon.predictor_fit_kwargs.time_limit=3600"
aga run toy_data --config_overrides "feature_transformers=[]" --config_overrides "autogluon.predictor_fit_kwargs.time_limit=3600"
```
2 changes: 1 addition & 1 deletion docs/tutorials/autogluon-assistant-quick-start.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@
"outputs": [],
"source": [
"%%bash\n",
"autogluon-assistant ./toy_data \\\n",
"autogluon-assistant run ./toy_data \\\n",
" --presets medium_quality # (Optional) Choose prediction quality level:\n",
" # Options: medium_quality, high_quality, best_quality (default)"
]
Expand Down
52 changes: 51 additions & 1 deletion src/autogluon_assistant/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import datetime
import logging
import os
import subprocess
import sys
from pathlib import Path
from typing import List, Optional

Expand Down Expand Up @@ -72,6 +74,53 @@ def make_prediction_outputs(task: TabularPredictionTask, predictions: pd.DataFra
return outputs


def get_ui_path() -> str:
"""Get the absolute path to the UI directory using package resources"""
try:
# For Python 3.9+
with importlib.resources.files("autogluon_assistant.ui") as ui_path:
return str(ui_path)
except Exception:
# Fallback for older Python versions
import pkg_resources

return pkg_resources.resource_filename("autogluon_assistant", "ui")


def launch_ui(port: int = typer.Option(8501, help="Port to run the UI on")):
"""Launch the AutoGluon Assistant Web UI"""
try:
import streamlit
except Exception as e:
rprint(f"[red]Error UI not installed: {str(e)}[/red]")
sys.exit(1)

ui_dir = get_ui_path()
app_path = os.path.join(ui_dir, "app.py")

if not os.path.exists(app_path):
rprint(f"[red]Error: UI file not found at {app_path}[/red]")
sys.exit(1)

# Change working directory to UI directory before running streamlit
original_dir = os.getcwd()
os.chdir(ui_dir)

cmd = ["streamlit", "run", "app.py", "--server.port", str(port)] # Use relative path since we changed directory

try:
rprint(f"[green]Launching AutoGluon Assistant UI on port {port}...[/green]")
subprocess.run(cmd)
except KeyboardInterrupt:
rprint("\n[yellow]Shutting down UI server...[/yellow]")
except Exception as e:
rprint(f"[red]Error launching UI: {str(e)}[/red]")
finally:
# Change back to original directory
os.chdir(original_dir)
sys.exit(1)


def run_assistant(
task_path: Annotated[str, typer.Argument(help="Directory where task files are included")],
presets: Annotated[
Expand Down Expand Up @@ -162,7 +211,8 @@ def run_assistant(

def main():
app = typer.Typer(pretty_exceptions_enable=False)
app.command()(run_assistant)
app.command("run")(run_assistant) # CLI Mode
app.command("ui")(launch_ui) # UI Mode
app()


Expand Down
2 changes: 1 addition & 1 deletion src/autogluon_assistant/ui/pages/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def run_autogluon_assistant(data_dir):
data_dir (str): The path to the data directory.
"""
output_filename = generate_output_filename()
command = ["aga", data_dir]
command = ["aga", "run", data_dir]
if st.session_state.preset:
command.extend(["--presets", PRESET_MAPPING[st.session_state.preset]])
if st.session_state.config_overrides:
Expand Down
Loading