Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -16,15 +16,15 @@ def prepare_model():
|
|
| 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 ロード中...")
|
|
@@ -37,7 +37,7 @@ def prepare_model():
|
|
| 37 |
)
|
| 38 |
return pipeline("text-generation", model=model, tokenizer=tokenizer)
|
| 39 |
|
| 40 |
-
# 初期化
|
| 41 |
try:
|
| 42 |
pipe = prepare_model()
|
| 43 |
except Exception as e:
|
|
@@ -45,25 +45,33 @@ except Exception as e:
|
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
| 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 |
-
|
|
|
|
| 59 |
msg = gr.Textbox(placeholder="最新モデルの力を見せてくれ。")
|
| 60 |
with gr.Row():
|
| 61 |
send = gr.Button("送信", variant="primary")
|
| 62 |
clear = gr.Button("クリア")
|
| 63 |
|
| 64 |
def respond(message, chat_history):
|
|
|
|
|
|
|
| 65 |
bot_message = chat_fn(message, chat_history)
|
| 66 |
-
chat_history.append(
|
| 67 |
return "", chat_history
|
| 68 |
|
| 69 |
msg.submit(respond, [msg, chatbot], [msg, chatbot])
|
|
@@ -71,7 +79,7 @@ with gr.Blocks(title="NI-v1.0") as demo:
|
|
| 71 |
clear.click(lambda: None, None, chatbot, queue=False)
|
| 72 |
|
| 73 |
with gr.Tab("公開"):
|
| 74 |
-
repo_id = gr.Textbox(label="Repo ID"
|
| 75 |
user_token = gr.Textbox(label="Write Token", type="password")
|
| 76 |
pub_btn = gr.Button("アップロード")
|
| 77 |
status = gr.Textbox(label="Status")
|
|
@@ -86,4 +94,6 @@ with gr.Blocks(title="NI-v1.0") as demo:
|
|
| 86 |
|
| 87 |
pub_btn.click(upload, [repo_id, user_token], status)
|
| 88 |
|
| 89 |
-
|
|
|
|
|
|
|
|
|
| 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 ロード中...")
|
|
|
|
| 37 |
)
|
| 38 |
return pipeline("text-generation", model=model, tokenizer=tokenizer)
|
| 39 |
|
| 40 |
+
# グローバルでパイプラインを初期化
|
| 41 |
try:
|
| 42 |
pipe = prepare_model()
|
| 43 |
except Exception as e:
|
|
|
|
| 45 |
pipe = None
|
| 46 |
|
| 47 |
def chat_fn(message, history):
|
| 48 |
+
if pipe is None: return "知能ユニットが起動してないぜ。"
|
| 49 |
+
|
| 50 |
+
# プロンプト構築
|
| 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 |
+
# 応答を抽出
|
| 55 |
+
response = outputs[0]['generated_text'].split("assistant\n")[-1].replace("<|im_end|>", "")
|
| 56 |
+
return response
|
| 57 |
|
| 58 |
+
# --- UI設定 ---
|
| 59 |
with gr.Blocks(title="NI-v1.0") as demo:
|
| 60 |
gr.Markdown("# 🤖 Noppo-Intelligence v1.0")
|
|
|
|
| 61 |
|
| 62 |
with gr.Tab("チャット"):
|
| 63 |
+
# Docker環境で最新のGradioがインストールされることを想定し、辞書型(messages)を強制
|
| 64 |
+
chatbot = gr.Chatbot(type="messages")
|
| 65 |
msg = gr.Textbox(placeholder="最新モデルの力を見せてくれ。")
|
| 66 |
with gr.Row():
|
| 67 |
send = gr.Button("送信", variant="primary")
|
| 68 |
clear = gr.Button("クリア")
|
| 69 |
|
| 70 |
def respond(message, chat_history):
|
| 71 |
+
# 辞書形式で履歴を管理
|
| 72 |
+
chat_history.append({"role": "user", "content": message})
|
| 73 |
bot_message = chat_fn(message, chat_history)
|
| 74 |
+
chat_history.append({"role": "assistant", "content": bot_message})
|
| 75 |
return "", chat_history
|
| 76 |
|
| 77 |
msg.submit(respond, [msg, chatbot], [msg, chatbot])
|
|
|
|
| 79 |
clear.click(lambda: None, None, chatbot, queue=False)
|
| 80 |
|
| 81 |
with gr.Tab("公開"):
|
| 82 |
+
repo_id = gr.Textbox(label="Repo ID")
|
| 83 |
user_token = gr.Textbox(label="Write Token", type="password")
|
| 84 |
pub_btn = gr.Button("アップロード")
|
| 85 |
status = gr.Textbox(label="Status")
|
|
|
|
| 94 |
|
| 95 |
pub_btn.click(upload, [repo_id, user_token], status)
|
| 96 |
|
| 97 |
+
if __name__ == "__main__":
|
| 98 |
+
# Dockerコンテナ内で外部からアクセスできるように設定
|
| 99 |
+
demo.launch(server_name="0.0.0.0", server_port=7860)
|