Spaces:
Runtime error
Runtime error
burtenshaw
commited on
Commit
Β·
9629dc8
1
Parent(s):
df45759
tidy wandb link and drop tab
Browse files
app.py
CHANGED
|
@@ -684,11 +684,11 @@ def fetch_runs_for_ui():
|
|
| 684 |
return pd.DataFrame(
|
| 685 |
{
|
| 686 |
"Status": [],
|
|
|
|
| 687 |
"Project": [],
|
| 688 |
"Task": [],
|
| 689 |
"Model": [],
|
| 690 |
"Created": [],
|
| 691 |
-
"W&B Link": [],
|
| 692 |
"Run ID": [],
|
| 693 |
}
|
| 694 |
)
|
|
@@ -697,23 +697,21 @@ def fetch_runs_for_ui():
|
|
| 697 |
for run in reversed(runs): # Newest first
|
| 698 |
wandb_link = ""
|
| 699 |
if run.get("wandb_url"):
|
| 700 |
-
wandb_link = (
|
| 701 |
-
f'<a href="{run["wandb_url"]}" target="_blank">View W&B</a>'
|
| 702 |
-
)
|
| 703 |
|
| 704 |
data.append(
|
| 705 |
{
|
| 706 |
"Status": f"{get_status_emoji(run['status'])} {run['status'].title()}",
|
|
|
|
| 707 |
"Project": run["project_name"],
|
| 708 |
"Task": run["task"].replace("-", " ").title(),
|
| 709 |
"Model": run["base_model"],
|
| 710 |
"Created": run["created_at"][:16].replace("T", " "),
|
| 711 |
-
"W&B Link": wandb_link,
|
| 712 |
"Run ID": run["run_id"][:8] + "...",
|
| 713 |
}
|
| 714 |
)
|
| 715 |
|
| 716 |
-
return pd.DataFrame(data)
|
| 717 |
|
| 718 |
except Exception as e:
|
| 719 |
return pd.DataFrame({"Error": [f"Failed to fetch runs: {str(e)}"]})
|
|
@@ -808,168 +806,11 @@ with gr.Blocks(
|
|
| 808 |
# Dashboard Tab
|
| 809 |
with gr.Tab("π Dashboard"):
|
| 810 |
with gr.Row():
|
| 811 |
-
|
| 812 |
-
|
| 813 |
-
|
| 814 |
-
|
| 815 |
-
|
| 816 |
-
)
|
| 817 |
-
|
| 818 |
-
with gr.Column(scale=1):
|
| 819 |
-
gr.Markdown("## Quick Stats")
|
| 820 |
-
stats = gr.Textbox(
|
| 821 |
-
value=get_system_status(), interactive=False, lines=15
|
| 822 |
-
)
|
| 823 |
-
|
| 824 |
-
# Start Training Tab
|
| 825 |
-
with gr.Tab("π Start Training"):
|
| 826 |
-
gr.Markdown("## Submit New Training Job")
|
| 827 |
-
|
| 828 |
-
gr.Markdown("""
|
| 829 |
-
π‘ **Hub Integration**: Enable "Push to Hub" to automatically upload your trained model to Hugging Face Hub.
|
| 830 |
-
Requires `HF_USERNAME` and `HF_TOKEN` environment variables.
|
| 831 |
-
""")
|
| 832 |
-
|
| 833 |
-
with gr.Row():
|
| 834 |
-
with gr.Column():
|
| 835 |
-
task_dropdown = gr.Dropdown(
|
| 836 |
-
choices=[
|
| 837 |
-
"text-classification",
|
| 838 |
-
"llm-sft",
|
| 839 |
-
"llm-dpo",
|
| 840 |
-
"llm-orpo",
|
| 841 |
-
"image-classification",
|
| 842 |
-
],
|
| 843 |
-
label="Task Type",
|
| 844 |
-
value="text-classification",
|
| 845 |
-
)
|
| 846 |
-
|
| 847 |
-
project_name = gr.Textbox(
|
| 848 |
-
label="Project Name", placeholder="my-training-project"
|
| 849 |
-
)
|
| 850 |
-
|
| 851 |
-
base_model = gr.Textbox(
|
| 852 |
-
label="Base Model", placeholder="distilbert-base-uncased"
|
| 853 |
-
)
|
| 854 |
-
|
| 855 |
-
dataset_path = gr.Textbox(label="Dataset Path", placeholder="imdb")
|
| 856 |
-
|
| 857 |
-
with gr.Column():
|
| 858 |
-
epochs = gr.Slider(1, 20, value=3, step=1, label="Epochs")
|
| 859 |
-
batch_size = gr.Slider(1, 128, value=16, step=1, label="Batch Size")
|
| 860 |
-
learning_rate = gr.Number(value=2e-5, label="Learning Rate")
|
| 861 |
-
backend = gr.Dropdown(
|
| 862 |
-
choices=["local", "spaces-t4-small", "spaces-a10g-large"],
|
| 863 |
-
label="Backend",
|
| 864 |
-
value="local",
|
| 865 |
-
)
|
| 866 |
-
|
| 867 |
-
with gr.Row():
|
| 868 |
-
with gr.Column():
|
| 869 |
-
push_to_hub = gr.Checkbox(label="Push to Hub", value=False)
|
| 870 |
-
hub_repo_id = gr.Textbox(
|
| 871 |
-
label="Hub Repository ID", placeholder="your-repo-id"
|
| 872 |
-
)
|
| 873 |
-
|
| 874 |
-
submit_btn = gr.Button("π Start Training", variant="primary", size="lg")
|
| 875 |
-
submit_output = gr.Textbox(label="Status", interactive=False, lines=10)
|
| 876 |
-
|
| 877 |
-
# MCP Info Tab
|
| 878 |
-
with gr.Tab("π MCP Integration"):
|
| 879 |
-
# Extract nested expressions to avoid f-string nesting in Gradio markdown
|
| 880 |
-
total_runs = len(load_runs())
|
| 881 |
-
wandb_auth = (
|
| 882 |
-
"β
Configured"
|
| 883 |
-
if os.environ.get("WANDB_API_KEY")
|
| 884 |
-
else "β Missing WANDB_API_KEY"
|
| 885 |
-
)
|
| 886 |
-
hub_auth = (
|
| 887 |
-
"β
Configured" if os.environ.get("HF_TOKEN") else "β Missing HF_TOKEN"
|
| 888 |
-
)
|
| 889 |
-
|
| 890 |
-
gr.Markdown(f"""
|
| 891 |
-
## MCP Server Information
|
| 892 |
-
|
| 893 |
-
This Gradio app automatically serves as an MCP server.
|
| 894 |
-
|
| 895 |
-
**MCP Endpoint:** `http://SPACE_URL/gradio_api/mcp/sse`
|
| 896 |
-
**MCP Schema:** `http://SPACE_URL/gradio_api/mcp/schema`
|
| 897 |
-
|
| 898 |
-
### Available MCP Tools:
|
| 899 |
-
|
| 900 |
-
- `start_training_job` - Submit new training jobs (includes Hub push)
|
| 901 |
-
- `get_training_runs` - List all runs with status
|
| 902 |
-
- `get_run_details` - Get detailed run information
|
| 903 |
-
- `get_task_recommendations` - Get training recommendations
|
| 904 |
-
- `get_system_status` - Check system status
|
| 905 |
-
|
| 906 |
-
### π Weights & Biases Integration:
|
| 907 |
-
|
| 908 |
-
For **complete training metrics** (loss, accuracy, etc.), set:
|
| 909 |
-
|
| 910 |
-
```bash
|
| 911 |
-
export WANDB_API_KEY="your-wandb-api-key"
|
| 912 |
-
export WANDB_PROJECT="autotrain-mcp" # Optional: custom project name
|
| 913 |
-
```
|
| 914 |
-
|
| 915 |
-
Get your API key from: https://wandb.ai/authorize
|
| 916 |
-
|
| 917 |
-
**What gets logged by AutoTrain:**
|
| 918 |
-
- β
Training/validation loss
|
| 919 |
-
- β
Learning rate schedule
|
| 920 |
-
- β
Gradient norms
|
| 921 |
-
- β
Model checkpoints
|
| 922 |
-
- β
System metrics (GPU, CPU, memory)
|
| 923 |
-
|
| 924 |
-
### π€ Hugging Face Hub Integration:
|
| 925 |
-
|
| 926 |
-
To push models to the Hub, set these environment variables:
|
| 927 |
-
|
| 928 |
-
```bash
|
| 929 |
-
export HF_USERNAME="your-hf-username"
|
| 930 |
-
export HF_TOKEN="your-hf-write-token"
|
| 931 |
-
```
|
| 932 |
-
|
| 933 |
-
Get your token from: https://huggingface.co/settings/tokens
|
| 934 |
-
|
| 935 |
-
**Usage Examples:**
|
| 936 |
-
- `push_to_hub="true"` - Push to Hub using project name as repo
|
| 937 |
-
- `hub_repo_id="my-org/my-model"` - Push to custom repository
|
| 938 |
-
|
| 939 |
-
### Connection to the MCP Server
|
| 940 |
-
|
| 941 |
-
Connect to it like this:
|
| 942 |
-
|
| 943 |
-
```javascript
|
| 944 |
-
{"mcpServers": {"autotrain": {"url": "http://SPACE_URL/gradio_api/mcp/sse",
|
| 945 |
-
"headers": {"Authorization": "Bearer <YOUR-HUGGING-FACE-TOKEN>"}
|
| 946 |
-
}
|
| 947 |
-
}
|
| 948 |
-
}
|
| 949 |
-
```
|
| 950 |
-
|
| 951 |
-
Or like this for Claude Desktop:
|
| 952 |
-
|
| 953 |
-
```javascript
|
| 954 |
-
{"mcpServers": {"autotrain": {"command": "npx",
|
| 955 |
-
"args": [
|
| 956 |
-
"mcp-remote",
|
| 957 |
-
"http://SPACE_URL/gradio_api/mcp/sse",
|
| 958 |
-
"--header",
|
| 959 |
-
"Authorization: Bearer <YOUR-HUGGING-FACE-TOKEN>"
|
| 960 |
-
]
|
| 961 |
-
}
|
| 962 |
-
}
|
| 963 |
-
}
|
| 964 |
-
```
|
| 965 |
-
|
| 966 |
-
### Current Stats:
|
| 967 |
-
|
| 968 |
-
Total Runs: {total_runs}
|
| 969 |
-
W&B Project: {WANDB_PROJECT}
|
| 970 |
-
W&B Auth: {wandb_auth}
|
| 971 |
-
Hub Auth: {hub_auth}
|
| 972 |
-
""")
|
| 973 |
|
| 974 |
# MCP Tools Tab
|
| 975 |
with gr.Tab("π§ MCP Tools"):
|
|
|
|
| 684 |
return pd.DataFrame(
|
| 685 |
{
|
| 686 |
"Status": [],
|
| 687 |
+
"W&B Link": [],
|
| 688 |
"Project": [],
|
| 689 |
"Task": [],
|
| 690 |
"Model": [],
|
| 691 |
"Created": [],
|
|
|
|
| 692 |
"Run ID": [],
|
| 693 |
}
|
| 694 |
)
|
|
|
|
| 697 |
for run in reversed(runs): # Newest first
|
| 698 |
wandb_link = ""
|
| 699 |
if run.get("wandb_url"):
|
| 700 |
+
wandb_link = f"[π W&B Run]({run['wandb_url']})"
|
|
|
|
|
|
|
| 701 |
|
| 702 |
data.append(
|
| 703 |
{
|
| 704 |
"Status": f"{get_status_emoji(run['status'])} {run['status'].title()}",
|
| 705 |
+
"W&B Link": wandb_link,
|
| 706 |
"Project": run["project_name"],
|
| 707 |
"Task": run["task"].replace("-", " ").title(),
|
| 708 |
"Model": run["base_model"],
|
| 709 |
"Created": run["created_at"][:16].replace("T", " "),
|
|
|
|
| 710 |
"Run ID": run["run_id"][:8] + "...",
|
| 711 |
}
|
| 712 |
)
|
| 713 |
|
| 714 |
+
return pd.DataFrame(data, datatype="markdown")
|
| 715 |
|
| 716 |
except Exception as e:
|
| 717 |
return pd.DataFrame({"Error": [f"Failed to fetch runs: {str(e)}"]})
|
|
|
|
| 806 |
# Dashboard Tab
|
| 807 |
with gr.Tab("π Dashboard"):
|
| 808 |
with gr.Row():
|
| 809 |
+
gr.Markdown("## Training Runs")
|
| 810 |
+
refresh_btn = g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