Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,24 +10,24 @@ def prepare_model():
|
|
| 10 |
token = os.getenv("HF_TOKEN")
|
| 11 |
|
| 12 |
if not os.path.exists(model_path):
|
| 13 |
-
print("🚀 NI-v1 マージ開始:Llama
|
| 14 |
env = os.environ.copy()
|
| 15 |
if token:
|
| 16 |
env["HF_TOKEN"] = token
|
| 17 |
|
| 18 |
try:
|
| 19 |
-
#
|
| 20 |
subprocess.run(
|
| 21 |
["mergekit-yaml", "config.yaml", model_path, "--allow-crimes"],
|
| 22 |
check=True,
|
| 23 |
env=env
|
| 24 |
)
|
| 25 |
-
print("✨ マージ成功
|
| 26 |
except subprocess.CalledProcessError as e:
|
| 27 |
-
print(f"❌ マージエラー。モデル名かゲート設定を確認
|
| 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,
|
|
@@ -45,22 +45,18 @@ except Exception as 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 |
-
|
| 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("
|
| 60 |
|
| 61 |
with gr.Tab("チャット"):
|
| 62 |
-
chatbot = gr.Chatbot(
|
| 63 |
-
msg = gr.Textbox(
|
| 64 |
with gr.Row():
|
| 65 |
send = gr.Button("送信", variant="primary")
|
| 66 |
clear = gr.Button("クリア")
|
|
@@ -75,10 +71,9 @@ with gr.Blocks(title="NI-v1.0") as demo:
|
|
| 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("
|
| 82 |
status = gr.Textbox(label="Status")
|
| 83 |
|
| 84 |
def upload(r, t):
|
|
@@ -86,7 +81,7 @@ with gr.Blocks(title="NI-v1.0") as demo:
|
|
| 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)
|
|
|
|
| 10 |
token = os.getenv("HF_TOKEN")
|
| 11 |
|
| 12 |
if not os.path.exists(model_path):
|
| 13 |
+
print("🚀 NI-v1 マージ開始:Llama-4-Maverick-17B-128E-Instruct x gemma-4-E4B-it")
|
| 14 |
env = os.environ.copy()
|
| 15 |
if token:
|
| 16 |
env["HF_TOKEN"] = token
|
| 17 |
|
| 18 |
try:
|
| 19 |
+
# スクショにある正確なモデル名。ミスは許されない。
|
| 20 |
subprocess.run(
|
| 21 |
["mergekit-yaml", "config.yaml", model_path, "--allow-crimes"],
|
| 22 |
check=True,
|
| 23 |
env=env
|
| 24 |
)
|
| 25 |
+
print("✨ マージ成功。のっぽ、今度は本物だ。")
|
| 26 |
except subprocess.CalledProcessError as e:
|
| 27 |
+
print(f"❌ マージエラー。モデル名かゲート設定を確認。")
|
| 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,
|
|
|
|
| 45 |
pipe = None
|
| 46 |
|
| 47 |
def chat_fn(message, history):
|
| 48 |
+
if pipe is None: return "知能ユニット起動失敗。ログを見てくれ。"
|
|
|
|
|
|
|
| 49 |
prompt = f"<|im_start|>user\n{message}<|im_end|>\n<|im_start|>assistant\n"
|
| 50 |
outputs = pipe(prompt, max_new_tokens=512, do_sample=True, temperature=0.7)
|
| 51 |
+
return outputs[0]['generated_text'].split("assistant\n")[-1].replace("<|im_end|>", "")
|
|
|
|
| 52 |
|
|
|
|
| 53 |
with gr.Blocks(title="NI-v1.0") as demo:
|
| 54 |
gr.Markdown("# 🤖 Noppo-Intelligence v1.0")
|
| 55 |
+
gr.Markdown("Maverick-17B と Gemma-4-E4B を融合した、のっぽ指定の真のマージAIだ。")
|
| 56 |
|
| 57 |
with gr.Tab("チャット"):
|
| 58 |
+
chatbot = gr.Chatbot()
|
| 59 |
+
msg = gr.Textbox(placeholder="最新モデルの力を見せてくれ。")
|
| 60 |
with gr.Row():
|
| 61 |
send = gr.Button("送信", variant="primary")
|
| 62 |
clear = gr.Button("クリア")
|
|
|
|
| 71 |
clear.click(lambda: None, None, chatbot, queue=False)
|
| 72 |
|
| 73 |
with gr.Tab("公開"):
|
|
|
|
| 74 |
repo_id = gr.Textbox(label="Repo ID", placeholder="noppodev/NoppoIntelligence")
|
| 75 |
user_token = gr.Textbox(label="Write Token", type="password")
|
| 76 |
+
pub_btn = gr.Button("アップロード")
|
| 77 |
status = gr.Textbox(label="Status")
|
| 78 |
|
| 79 |
def upload(r, t):
|
|
|
|
| 81 |
api = HfApi()
|
| 82 |
api.create_repo(repo_id=r, repo_type="model", exist_ok=True)
|
| 83 |
api.upload_folder(folder_path="./ni_v1_model", repo_id=r, token=t)
|
| 84 |
+
return "✅ 完了したぜ。"
|
| 85 |
except Exception as e: return f"❌ エラー: {e}"
|
| 86 |
|
| 87 |
pub_btn.click(upload, [repo_id, user_token], status)
|