Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,57 +10,57 @@ def prepare_model():
|
|
| 10 |
token = os.getenv("HF_TOKEN")
|
| 11 |
|
| 12 |
if not os.path.exists(model_path):
|
| 13 |
-
print("🚀 NI-v1 マージ開始
|
| 14 |
env = os.environ.copy()
|
| 15 |
if token:
|
| 16 |
env["HF_TOKEN"] = token
|
| 17 |
|
| 18 |
try:
|
|
|
|
| 19 |
subprocess.run(
|
| 20 |
["mergekit-yaml", "config.yaml", model_path, "--allow-crimes"],
|
| 21 |
check=True,
|
| 22 |
env=env
|
| 23 |
)
|
| 24 |
-
print("✨ マージ成功
|
| 25 |
except subprocess.CalledProcessError as e:
|
| 26 |
-
print(f"❌ マージ
|
| 27 |
raise e
|
| 28 |
|
| 29 |
-
print("🧠 NI-v1
|
| 30 |
-
tokenizer = AutoTokenizer.from_pretrained(model_path)
|
| 31 |
model = AutoModelForCausalLM.from_pretrained(
|
| 32 |
model_path,
|
| 33 |
torch_dtype=torch.bfloat16,
|
| 34 |
-
device_map="auto"
|
|
|
|
| 35 |
)
|
| 36 |
return pipeline("text-generation", model=model, tokenizer=tokenizer)
|
| 37 |
|
| 38 |
# 初期化
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
def chat_fn(message, history):
|
| 42 |
-
|
| 43 |
-
|
|
|
|
|
|
|
| 44 |
outputs = pipe(prompt, max_new_tokens=512, do_sample=True, temperature=0.7)
|
| 45 |
-
response = outputs[0]['generated_text'].split("
|
| 46 |
return response
|
| 47 |
|
| 48 |
-
|
| 49 |
-
try:
|
| 50 |
-
api = HfApi()
|
| 51 |
-
api.create_repo(repo_id=repo_id, repo_type="model", exist_ok=True)
|
| 52 |
-
api.upload_folder(folder_path="./ni_v1_model", repo_id=repo_id, token=hf_token)
|
| 53 |
-
return f"🎉 {repo_id} に公開完了したぜ!"
|
| 54 |
-
except Exception as e:
|
| 55 |
-
return f"⚠ エラー: {str(e)}"
|
| 56 |
-
|
| 57 |
with gr.Blocks(title="NI-v1.0") as demo:
|
| 58 |
gr.Markdown("# 🤖 Noppo-Intelligence v1.0")
|
| 59 |
-
gr.Markdown("Llama 4 と Gemma 4
|
| 60 |
|
| 61 |
-
with gr.Tab("
|
| 62 |
-
chatbot = gr.Chatbot()
|
| 63 |
-
msg = gr.Textbox(label="
|
| 64 |
with gr.Row():
|
| 65 |
send = gr.Button("送信", variant="primary")
|
| 66 |
clear = gr.Button("クリア")
|
|
@@ -73,13 +73,22 @@ with gr.Blocks(title="NI-v1.0") as demo:
|
|
| 73 |
msg.submit(respond, [msg, chatbot], [msg, chatbot])
|
| 74 |
send.click(respond, [msg, chatbot], [msg, chatbot])
|
| 75 |
clear.click(lambda: None, None, chatbot, queue=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
|
| 77 |
-
|
| 78 |
-
gr.Markdown("### モデルを公開する")
|
| 79 |
-
repo_id = gr.Textbox(label="noppodev/NoppoIntelligence")
|
| 80 |
-
user_token = gr.Textbox(label="HF Write Token", type="password")
|
| 81 |
-
pub_btn = gr.Button("Hugging Faceへ転送")
|
| 82 |
-
status = gr.Textbox(label="ステータス", interactive=False)
|
| 83 |
-
pub_btn.click(upload_to_hub, [repo_id, user_token], status)
|
| 84 |
|
| 85 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
|
| 10 |
token = os.getenv("HF_TOKEN")
|
| 11 |
|
| 12 |
if not os.path.exists(model_path):
|
| 13 |
+
print("🚀 NI-v1 マージ開始:Llama 4 Scout x Gemma 4 E2E")
|
| 14 |
env = os.environ.copy()
|
| 15 |
if token:
|
| 16 |
env["HF_TOKEN"] = token
|
| 17 |
|
| 18 |
try:
|
| 19 |
+
# mergekitで本物の次世代機をマージ
|
| 20 |
subprocess.run(
|
| 21 |
["mergekit-yaml", "config.yaml", model_path, "--allow-crimes"],
|
| 22 |
check=True,
|
| 23 |
env=env
|
| 24 |
)
|
| 25 |
+
print("✨ マージ成功!のっぽ、Gemma 4の力、手に入れたぜ。")
|
| 26 |
except subprocess.CalledProcessError as e:
|
| 27 |
+
print(f"❌ マージエラー。モデル名かゲート設定を確認だ:{e}")
|
| 28 |
raise e
|
| 29 |
|
| 30 |
+
print("🧠 NI-v1 意識を同期中...")
|
| 31 |
+
tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)
|
| 32 |
model = AutoModelForCausalLM.from_pretrained(
|
| 33 |
model_path,
|
| 34 |
torch_dtype=torch.bfloat16,
|
| 35 |
+
device_map="auto",
|
| 36 |
+
trust_remote_code=True
|
| 37 |
)
|
| 38 |
return pipeline("text-generation", model=model, tokenizer=tokenizer)
|
| 39 |
|
| 40 |
# 初期化
|
| 41 |
+
try:
|
| 42 |
+
pipe = prepare_model()
|
| 43 |
+
except Exception as e:
|
| 44 |
+
print(f"起動エラー: {e}")
|
| 45 |
+
pipe = None
|
| 46 |
|
| 47 |
def chat_fn(message, history):
|
| 48 |
+
if pipe is None: return "知能がまだ眠ってるみたいだ(起動失敗)。"
|
| 49 |
+
|
| 50 |
+
# Gemma 4 / Scout 向けのプロンプト形式
|
| 51 |
+
prompt = f"<|im_start|>user\n{message}<|im_end|>\n<|im_start|>assistant\n"
|
| 52 |
outputs = pipe(prompt, max_new_tokens=512, do_sample=True, temperature=0.7)
|
| 53 |
+
response = outputs[0]['generated_text'].split("assistant\n")[-1].replace("<|im_end|>", "")
|
| 54 |
return response
|
| 55 |
|
| 56 |
+
# --- UI (Noppo Style) ---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
with gr.Blocks(title="NI-v1.0") as demo:
|
| 58 |
gr.Markdown("# 🤖 Noppo-Intelligence v1.0")
|
| 59 |
+
gr.Markdown("Llama 4 Scout と Gemma 4 E2E の融合。これぞ NoppoStudio の真骨頂。")
|
| 60 |
|
| 61 |
+
with gr.Tab("チャット"):
|
| 62 |
+
chatbot = gr.Chatbot(label="NI-v1 Session")
|
| 63 |
+
msg = gr.Textbox(label="問いかけ", placeholder="Gemma 4の知能を試してみるか?")
|
| 64 |
with gr.Row():
|
| 65 |
send = gr.Button("送信", variant="primary")
|
| 66 |
clear = gr.Button("クリア")
|
|
|
|
| 73 |
msg.submit(respond, [msg, chatbot], [msg, chatbot])
|
| 74 |
send.click(respond, [msg, chatbot], [msg, chatbot])
|
| 75 |
clear.click(lambda: None, None, chatbot, queue=False)
|
| 76 |
+
|
| 77 |
+
with gr.Tab("公開"):
|
| 78 |
+
gr.Markdown("### 完成した知能を世界に公開するぜ")
|
| 79 |
+
repo_id = gr.Textbox(label="Repo ID", placeholder="noppodev/NoppoIntelligence")
|
| 80 |
+
user_token = gr.Textbox(label="Write Token", type="password")
|
| 81 |
+
pub_btn = gr.Button("Hugging Faceへアップロード")
|
| 82 |
+
status = gr.Textbox(label="Status")
|
| 83 |
+
|
| 84 |
+
def upload(r, t):
|
| 85 |
+
try:
|
| 86 |
+
api = HfApi()
|
| 87 |
+
api.create_repo(repo_id=r, repo_type="model", exist_ok=True)
|
| 88 |
+
api.upload_folder(folder_path="./ni_v1_model", repo_id=r, token=t)
|
| 89 |
+
return "✅ 成功!のっぽ、やったな!"
|
| 90 |
+
except Exception as e: return f"❌ エラー: {e}"
|
| 91 |
|
| 92 |
+
pub_btn.click(upload, [repo_id, user_token], status)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
|
| 94 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|