Update app.py
Browse files
app.py
CHANGED
|
@@ -39,24 +39,6 @@ from dotenv import load_dotenv
|
|
| 39 |
|
| 40 |
load_dotenv()
|
| 41 |
|
| 42 |
-
# -----------------------------------------------------------------------------
|
| 43 |
-
# Hugging Face repo id for THIS space
|
| 44 |
-
# (hard-coded so we don't fight with reserved env vars)
|
| 45 |
-
# -----------------------------------------------------------------------------
|
| 46 |
-
SPACE_REPO_ID = "MCP-1st-Birthday/OmniMind-Orchestrator"
|
| 47 |
-
|
| 48 |
-
# Optional: HF upload support
|
| 49 |
-
try:
|
| 50 |
-
from huggingface_hub import (
|
| 51 |
-
HfApi,
|
| 52 |
-
CommitOperationAdd,
|
| 53 |
-
hf_hub_url,
|
| 54 |
-
)
|
| 55 |
-
except Exception:
|
| 56 |
-
HfApi = None
|
| 57 |
-
CommitOperationAdd = None
|
| 58 |
-
hf_hub_url = None
|
| 59 |
-
|
| 60 |
|
| 61 |
# ============================================================================
|
| 62 |
# Helpers
|
|
@@ -104,57 +86,26 @@ def create_download_zip(server_metadata: Dict[str, Any]) -> Optional[str]:
|
|
| 104 |
|
| 105 |
def push_zip_to_space_repo(zip_path: Path) -> Optional[str]:
|
| 106 |
"""
|
| 107 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
|
| 109 |
-
|
| 110 |
-
|
|
|
|
|
|
|
| 111 |
|
| 112 |
Returns:
|
| 113 |
-
|
| 114 |
"""
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
print("[HF] HF_WRITE_TOKEN / HF_TOKEN not set - skipping Space upload.")
|
| 122 |
-
return None
|
| 123 |
-
|
| 124 |
-
api = HfApi(token=token)
|
| 125 |
-
|
| 126 |
-
zip_path = Path(zip_path)
|
| 127 |
-
if not zip_path.exists():
|
| 128 |
-
print(f"[HF] ZIP path does not exist: {zip_path}")
|
| 129 |
-
return None
|
| 130 |
-
|
| 131 |
-
path_in_repo = f"generated_mcps/{zip_path.name}"
|
| 132 |
-
|
| 133 |
-
try:
|
| 134 |
-
# Explicit commit with file add
|
| 135 |
-
ops = [
|
| 136 |
-
CommitOperationAdd(path_in_repo=path_in_repo, path_or_fileobj=str(zip_path))
|
| 137 |
-
]
|
| 138 |
-
|
| 139 |
-
api.create_commit(
|
| 140 |
-
repo_id=SPACE_REPO_ID,
|
| 141 |
-
repo_type="space",
|
| 142 |
-
revision="main",
|
| 143 |
-
operations=ops,
|
| 144 |
-
commit_message=f"Upload {path_in_repo} with huggingface_hub",
|
| 145 |
-
)
|
| 146 |
-
|
| 147 |
-
url = hf_hub_url(
|
| 148 |
-
repo_id=SPACE_REPO_ID,
|
| 149 |
-
filename=path_in_repo,
|
| 150 |
-
repo_type="space",
|
| 151 |
-
revision="main",
|
| 152 |
-
)
|
| 153 |
-
print(f"[HF] Uploaded ZIP to Hub at: {url}")
|
| 154 |
-
return url
|
| 155 |
-
except Exception as e:
|
| 156 |
-
print(f"[HF][ERROR] Failed to create commit with ZIP: {e}")
|
| 157 |
-
return None
|
| 158 |
|
| 159 |
|
| 160 |
# ============================================================================
|
|
@@ -380,7 +331,7 @@ Respond in JSON:
|
|
| 380 |
|
| 381 |
output += f"**Files saved to:** `{server_metadata['directory']}`\n\n"
|
| 382 |
|
| 383 |
-
# ZIP + Hub upload
|
| 384 |
zip_path = create_download_zip(server_metadata)
|
| 385 |
if zip_path:
|
| 386 |
server_metadata["zip_path"] = zip_path
|
|
@@ -392,8 +343,9 @@ Respond in JSON:
|
|
| 392 |
output += f"🔗 **Saved to Hub:** {hub_url}\n\n"
|
| 393 |
else:
|
| 394 |
output += (
|
| 395 |
-
"
|
| 396 |
-
"
|
|
|
|
| 397 |
)
|
| 398 |
|
| 399 |
agent_state["nodes"][-1]["type"] = "completed"
|
|
|
|
| 39 |
|
| 40 |
load_dotenv()
|
| 41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
# ============================================================================
|
| 44 |
# Helpers
|
|
|
|
| 86 |
|
| 87 |
def push_zip_to_space_repo(zip_path: Path) -> Optional[str]:
|
| 88 |
"""
|
| 89 |
+
Stub for Hub upload.
|
| 90 |
+
|
| 91 |
+
We intentionally DO NOT commit to the Space repository from inside
|
| 92 |
+
the running app, because that triggers an automatic redeploy and
|
| 93 |
+
causes the UI to refresh mid-run.
|
| 94 |
|
| 95 |
+
Workflow for the hackathon:
|
| 96 |
+
- Use the **Download Generated MCP Server** button.
|
| 97 |
+
- Then manually upload the ZIP to generated_mcps/ in the Files tab
|
| 98 |
+
if you want it stored on the Hub.
|
| 99 |
|
| 100 |
Returns:
|
| 101 |
+
Always None (no automatic Hub URL).
|
| 102 |
"""
|
| 103 |
+
print(
|
| 104 |
+
"[HF] Auto-upload to Space repo is disabled to avoid self-redeploy.\n"
|
| 105 |
+
" Use the download button, then upload the ZIP manually to "
|
| 106 |
+
"generated_mcps/ in the Files tab if you want it on the Hub."
|
| 107 |
+
)
|
| 108 |
+
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
|
| 110 |
|
| 111 |
# ============================================================================
|
|
|
|
| 331 |
|
| 332 |
output += f"**Files saved to:** `{server_metadata['directory']}`\n\n"
|
| 333 |
|
| 334 |
+
# ZIP + (disabled) Hub upload
|
| 335 |
zip_path = create_download_zip(server_metadata)
|
| 336 |
if zip_path:
|
| 337 |
server_metadata["zip_path"] = zip_path
|
|
|
|
| 343 |
output += f"🔗 **Saved to Hub:** {hub_url}\n\n"
|
| 344 |
else:
|
| 345 |
output += (
|
| 346 |
+
"ℹ️ Auto-upload to the Hub repo is disabled.\n"
|
| 347 |
+
" Use the download button, then upload the ZIP manually\n"
|
| 348 |
+
" to `generated_mcps/` in the Files tab if you want it stored.\n\n"
|
| 349 |
)
|
| 350 |
|
| 351 |
agent_state["nodes"][-1]["type"] = "completed"
|