Upload alpha_factory/ui.py
Browse files- alpha_factory/ui.py +30 -15
alpha_factory/ui.py
CHANGED
|
@@ -1,7 +1,10 @@
|
|
| 1 |
"""
|
| 2 |
-
Alpha Factory β Gradio UI
|
| 3 |
View generated alphas, copy expressions, run new batches,
|
| 4 |
-
and SELECT per-tier models from
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
Run: uv run python -m alpha_factory.ui
|
| 7 |
"""
|
|
@@ -31,9 +34,7 @@ _LAST_DISCOVERED_MODELS: list[ModelInfo] = []
|
|
| 31 |
|
| 32 |
def _model_choice_name(m: ModelInfo) -> str:
|
| 33 |
"""Human-readable label for a model in the dropdown."""
|
| 34 |
-
|
| 35 |
-
quant = f" [{m.quantization}]" if m.quantization else ""
|
| 36 |
-
return f"[{m.provider.value.upper()}] {m.name}{size}{quant}"
|
| 37 |
|
| 38 |
|
| 39 |
def _discover_models_sync(
|
|
@@ -70,15 +71,16 @@ def refresh_all_dropdowns(ollama_url: str, hf_token: str):
|
|
| 70 |
msg = "β οΈ No models found. Is Ollama running? Is HF_TOKEN set?"
|
| 71 |
return msg, ["Use Default (auto-assign)"], ["Use Default (auto-assign)"], ["Use Default (auto-assign)"], ["Use Default (auto-assign)"]
|
| 72 |
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
|
|
|
| 76 |
|
| 77 |
choices = _get_dropdown_choices(models)
|
| 78 |
return msg, choices, choices, choices, choices
|
| 79 |
|
| 80 |
|
| 81 |
-
# ββ DB helpers
|
| 82 |
|
| 83 |
def get_alphas_from_db(limit=50):
|
| 84 |
if not DB_PATH.exists():
|
|
@@ -132,16 +134,19 @@ def get_full_expression(evt: gr.SelectData):
|
|
| 132 |
return ""
|
| 133 |
|
| 134 |
|
| 135 |
-
# ββ Pipeline runner
|
| 136 |
|
| 137 |
def _extract_model_name(choice: str) -> Optional[str]:
|
| 138 |
-
"""Strip [PROVIDER] prefix and size/quant suffix to get raw model name."""
|
| 139 |
if not choice or choice == "Use Default (auto-assign)":
|
| 140 |
return None
|
| 141 |
if "]" in choice:
|
| 142 |
raw = choice.split("]", 1)[1].strip()
|
| 143 |
# Remove trailing size/quant suffixes: " (4.7GB) [q4_k_m]" etc.
|
| 144 |
raw = raw.split(" (")[0].split(" [")[0].strip()
|
|
|
|
|
|
|
|
|
|
| 145 |
return raw
|
| 146 |
return choice.strip()
|
| 147 |
|
|
@@ -261,9 +266,15 @@ def build_ui():
|
|
| 261 |
refresh_models_btn = gr.Button("π Refresh Model List", variant="secondary")
|
| 262 |
discovery_status = gr.Textbox(
|
| 263 |
label="Discovery Status",
|
| 264 |
-
value="Click 'Refresh Model List' to discover
|
| 265 |
interactive=False,
|
| 266 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 267 |
|
| 268 |
with gr.Column(scale=2):
|
| 269 |
gr.Markdown("### Model Selection β One Per Tier")
|
|
@@ -283,24 +294,28 @@ def build_ui():
|
|
| 283 |
value="Use Default (auto-assign)",
|
| 284 |
label="π Microfish β Hypothesis Generation",
|
| 285 |
info="Bulk idea generation (fast, small model)",
|
|
|
|
| 286 |
)
|
| 287 |
tinyfish_dropdown = gr.Dropdown(
|
| 288 |
choices=default_choices,
|
| 289 |
value="Use Default (auto-assign)",
|
| 290 |
label="π Tinyfish β Expression Compilation",
|
| 291 |
info="Converts hypothesis to BRAIN expression",
|
|
|
|
| 292 |
)
|
| 293 |
mediumfish_dropdown = gr.Dropdown(
|
| 294 |
choices=default_choices,
|
| 295 |
value="Use Default (auto-assign)",
|
| 296 |
label="π¦ Mediumfish β Critique & Diagnosis",
|
| 297 |
info="Novelty check + performance analysis",
|
|
|
|
| 298 |
)
|
| 299 |
bigfish_dropdown = gr.Dropdown(
|
| 300 |
choices=default_choices,
|
| 301 |
value="Use Default (auto-assign)",
|
| 302 |
label="π Bigfish β Final Gatekeeper",
|
| 303 |
info="Production go/no-go decision (slowest, most capable)",
|
|
|
|
| 304 |
)
|
| 305 |
|
| 306 |
refresh_models_btn.click(
|
|
@@ -360,7 +375,6 @@ def build_ui():
|
|
| 360 |
gr.Markdown("### Pipeline Log")
|
| 361 |
pipeline_log = gr.Textbox(label="Output", lines=20, interactive=False)
|
| 362 |
|
| 363 |
-
# Events
|
| 364 |
alpha_table.select(get_full_expression, outputs=[full_expr])
|
| 365 |
refresh_table_btn.click(get_alpha_cards, outputs=[alpha_table])
|
| 366 |
generate_btn.click(
|
|
@@ -394,8 +408,9 @@ def build_ui():
|
|
| 394 |
- **LLM Mode**: Uses local (Ollama) or cloud (HuggingFace) models
|
| 395 |
|
| 396 |
### Model Discovery
|
| 397 |
-
-
|
| 398 |
-
-
|
|
|
|
| 399 |
- Select which model to use for each tier, or leave as "Use Default"
|
| 400 |
|
| 401 |
### BRAIN Integration
|
|
|
|
| 1 |
"""
|
| 2 |
+
Alpha Factory β Gradio UI v3
|
| 3 |
View generated alphas, copy expressions, run new batches,
|
| 4 |
+
and SELECT per-tier models from:
|
| 5 |
+
- Installed Ollama models
|
| 6 |
+
- Pullable Ollama models (recommended tags)
|
| 7 |
+
- HuggingFace Inference API (cloud)
|
| 8 |
|
| 9 |
Run: uv run python -m alpha_factory.ui
|
| 10 |
"""
|
|
|
|
| 34 |
|
| 35 |
def _model_choice_name(m: ModelInfo) -> str:
|
| 36 |
"""Human-readable label for a model in the dropdown."""
|
| 37 |
+
return m.display_name()
|
|
|
|
|
|
|
| 38 |
|
| 39 |
|
| 40 |
def _discover_models_sync(
|
|
|
|
| 71 |
msg = "β οΈ No models found. Is Ollama running? Is HF_TOKEN set?"
|
| 72 |
return msg, ["Use Default (auto-assign)"], ["Use Default (auto-assign)"], ["Use Default (auto-assign)"], ["Use Default (auto-assign)"]
|
| 73 |
|
| 74 |
+
installed = sum(1 for m in models if m.provider == ModelProvider.OLLAMA and m.is_installed)
|
| 75 |
+
pullable = sum(1 for m in models if m.provider == ModelProvider.OLLAMA and not m.is_installed)
|
| 76 |
+
cloud = sum(1 for m in models if m.provider == ModelProvider.HUGGINGFACE)
|
| 77 |
+
msg = f"β
Found {installed} Ollama installed + {pullable} pullable + {cloud} HF cloud"
|
| 78 |
|
| 79 |
choices = _get_dropdown_choices(models)
|
| 80 |
return msg, choices, choices, choices, choices
|
| 81 |
|
| 82 |
|
| 83 |
+
# ββ DB helpers ββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 84 |
|
| 85 |
def get_alphas_from_db(limit=50):
|
| 86 |
if not DB_PATH.exists():
|
|
|
|
| 134 |
return ""
|
| 135 |
|
| 136 |
|
| 137 |
+
# ββ Pipeline runner βββββββββββββββββββββββββββ
|
| 138 |
|
| 139 |
def _extract_model_name(choice: str) -> Optional[str]:
|
| 140 |
+
"""Strip [PROVIDER] prefix and size/quant/pullable suffix to get raw model name."""
|
| 141 |
if not choice or choice == "Use Default (auto-assign)":
|
| 142 |
return None
|
| 143 |
if "]" in choice:
|
| 144 |
raw = choice.split("]", 1)[1].strip()
|
| 145 |
# Remove trailing size/quant suffixes: " (4.7GB) [q4_k_m]" etc.
|
| 146 |
raw = raw.split(" (")[0].split(" [")[0].strip()
|
| 147 |
+
# Remove " [PULLABLE β ollama pull ...]" suffix if present
|
| 148 |
+
if "[PULLABLE" in raw:
|
| 149 |
+
raw = raw.split(" [PULLABLE")[0].strip()
|
| 150 |
return raw
|
| 151 |
return choice.strip()
|
| 152 |
|
|
|
|
| 266 |
refresh_models_btn = gr.Button("π Refresh Model List", variant="secondary")
|
| 267 |
discovery_status = gr.Textbox(
|
| 268 |
label="Discovery Status",
|
| 269 |
+
value="Click 'Refresh Model List' to discover installed + pullable models",
|
| 270 |
interactive=False,
|
| 271 |
)
|
| 272 |
+
gr.Markdown("""
|
| 273 |
+
**Legend:**
|
| 274 |
+
- β
`[ollama]` β already installed locally
|
| 275 |
+
- β¬οΈ `[ollama]` + `[PULLABLE]` β run `ollama pull <name>` first
|
| 276 |
+
- βοΈ `[huggingface]` β cloud Inference API (needs HF token)
|
| 277 |
+
""")
|
| 278 |
|
| 279 |
with gr.Column(scale=2):
|
| 280 |
gr.Markdown("### Model Selection β One Per Tier")
|
|
|
|
| 294 |
value="Use Default (auto-assign)",
|
| 295 |
label="π Microfish β Hypothesis Generation",
|
| 296 |
info="Bulk idea generation (fast, small model)",
|
| 297 |
+
allow_custom_value=True,
|
| 298 |
)
|
| 299 |
tinyfish_dropdown = gr.Dropdown(
|
| 300 |
choices=default_choices,
|
| 301 |
value="Use Default (auto-assign)",
|
| 302 |
label="π Tinyfish β Expression Compilation",
|
| 303 |
info="Converts hypothesis to BRAIN expression",
|
| 304 |
+
allow_custom_value=True,
|
| 305 |
)
|
| 306 |
mediumfish_dropdown = gr.Dropdown(
|
| 307 |
choices=default_choices,
|
| 308 |
value="Use Default (auto-assign)",
|
| 309 |
label="π¦ Mediumfish β Critique & Diagnosis",
|
| 310 |
info="Novelty check + performance analysis",
|
| 311 |
+
allow_custom_value=True,
|
| 312 |
)
|
| 313 |
bigfish_dropdown = gr.Dropdown(
|
| 314 |
choices=default_choices,
|
| 315 |
value="Use Default (auto-assign)",
|
| 316 |
label="π Bigfish β Final Gatekeeper",
|
| 317 |
info="Production go/no-go decision (slowest, most capable)",
|
| 318 |
+
allow_custom_value=True,
|
| 319 |
)
|
| 320 |
|
| 321 |
refresh_models_btn.click(
|
|
|
|
| 375 |
gr.Markdown("### Pipeline Log")
|
| 376 |
pipeline_log = gr.Textbox(label="Output", lines=20, interactive=False)
|
| 377 |
|
|
|
|
| 378 |
alpha_table.select(get_full_expression, outputs=[full_expr])
|
| 379 |
refresh_table_btn.click(get_alpha_cards, outputs=[alpha_table])
|
| 380 |
generate_btn.click(
|
|
|
|
| 408 |
- **LLM Mode**: Uses local (Ollama) or cloud (HuggingFace) models
|
| 409 |
|
| 410 |
### Model Discovery
|
| 411 |
+
- **Installed Ollama models** β already pulled, ready to run
|
| 412 |
+
- **Pullable Ollama models** β recommended tags you can `ollama pull` first
|
| 413 |
+
- **HuggingFace cloud models** β Inference API, needs HF token
|
| 414 |
- Select which model to use for each tier, or leave as "Use Default"
|
| 415 |
|
| 416 |
### BRAIN Integration
|