File size: 2,666 Bytes
844b1b3
 
755fbc6
844b1b3
 
 
1c327ab
 
 
844b1b3
1c327ab
 
 
 
 
 
755fbc6
 
844b1b3
25551b0
1c327ab
25551b0
5812120
25551b0
 
 
1c327ab
25551b0
5812120
1c327ab
 
25551b0
 
 
 
 
5812120
25551b0
 
 
1c327ab
 
 
 
 
 
 
 
 
 
5812120
1c327ab
 
25551b0
9beded6
25551b0
 
1c327ab
 
9beded6
1c327ab
 
 
 
 
 
 
844b1b3
1c327ab
844b1b3
a664f14
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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)