Spaces:
Sleeping
Sleeping
| import os | |
| import subprocess | |
| import shutil | |
| import gradio as gr | |
| from huggingface_hub import HfApi | |
| def run_factory(repo_id, token): | |
| if not repo_id or not token: | |
| return "❌ Repo IDとTokenを入れてくれ!" | |
| model_path = "./ni_v1_model" | |
| env = os.environ.copy() | |
| env["HF_TOKEN"] = token | |
| try: | |
| # 古い残骸を掃除 | |
| if os.path.exists(model_path): | |
| shutil.rmtree(model_path) | |
| # 認証 (2026年最新の hf コマンド) | |
| print("🚀 認証中...") | |
| try: | |
| # 認証に失敗しても環境変数で動く可能性があるので続行 | |
| subprocess.run(["hf", "auth", "login", "--token", token], check=True) | |
| except: | |
| print("⚠️ 認証コマンドでエラーが出たけど、環境変数があるから続行するぜ。") | |
| # マージ実行 | |
| # status 2 を回避するため、引数を「絶対に動くはずの最小構成」に変更 | |
| print("🚀 マージ開始...") | |
| subprocess.run( | |
| [ | |
| "mergekit-yaml", | |
| "config.yaml", | |
| model_path, | |
| "--allow-crimes", | |
| "--lazy-unpickle" | |
| ], | |
| check=True, | |
| env=env | |
| ) | |
| # アップロード実行 | |
| print("🚀 アップロード開始...") | |
| api = HfApi() | |
| api.create_repo(repo_id=repo_id, repo_type="model", exist_ok=True) | |
| api.upload_folder( | |
| folder_path=model_path, | |
| repo_id=repo_id, | |
| token=token, | |
| commit_message="NI-v1.0: BeyondIntelligence Build" | |
| ) | |
| return f"✅ 成功したぜ!\nリポジトリ: https://huggingface.co/{repo_id}\nColabへ急ごうぜ!" | |
| except subprocess.CalledProcessError as e: | |
| return f"❌ コマンドエラー: {e}\n(config.yamlの記述ミスか、引数の競合の可能性があるぜ。)" | |
| except Exception as e: | |
| return f"❌ エラー発生: {str(e)}" | |
| with gr.Blocks(title="NI-v1 Factory") as demo: | |
| gr.Markdown("# 🏭 Noppo-Intelligence v1.0 Factory") | |
| with gr.Column(): | |
| repo = gr.Textbox(label="転送先 Repo ID", value="noppodev/NoppoIntelligence") | |
| token = gr.Textbox(label="Hugging Face Write Token", type="password") | |
| start_btn = gr.Button("マージ&アップロード開始", variant="primary") | |
| output = gr.Textbox(label="ログ / 結果", interactive=False) | |
| start_btn.click(run_factory, [repo, token], output) | |
| if __name__ == "__main__": | |
| demo.launch(server_name="0.0.0.0", server_port=7860) |