Spaces:
Configuration error
Configuration error
sillynugget
commited on
Commit
•
17ffc4f
1
Parent(s):
bbd3ff9
Upload 4 files
Browse files- README.md +1 -13
- chat_bot.py +33 -0
- chat_bot_v2.py +12 -0
- chat_generate.py +23 -0
README.md
CHANGED
@@ -1,13 +1 @@
|
|
1 |
-
|
2 |
-
title: Ultimate 96B Chat
|
3 |
-
emoji: 🐢
|
4 |
-
colorFrom: yellow
|
5 |
-
colorTo: yellow
|
6 |
-
sdk: gradio
|
7 |
-
sdk_version: 4.12.0
|
8 |
-
app_file: app.py
|
9 |
-
pinned: false
|
10 |
-
license: mit
|
11 |
-
---
|
12 |
-
|
13 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
1 |
+
# chat-hugginface
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
chat_bot.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import torch
|
3 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
4 |
+
# os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
|
5 |
+
|
6 |
+
# モデルとトークナイザーのロード
|
7 |
+
model_name = "cyberagent/open-calm-large"
|
8 |
+
# model_name = "cyberagent/open-calm-3b"
|
9 |
+
model = AutoModelForCausalLM.from_pretrained(model_name).to(torch.device("cuda" if torch.cuda.is_available() else "cpu"))
|
10 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
11 |
+
|
12 |
+
# チャットの開始
|
13 |
+
print("ボット: こんにちは! 何か質問がありますか?")
|
14 |
+
|
15 |
+
while True:
|
16 |
+
# ユーザからの入力を受け取る
|
17 |
+
user_input = input("あなた: ")
|
18 |
+
|
19 |
+
# ユーザの入力をエンコードしてテンソルに変換
|
20 |
+
input_ids = tokenizer.encode(user_input, return_tensors='pt')
|
21 |
+
attention_mask = (input_ids != tokenizer.pad_token_id if tokenizer.pad_token_id is not None else 0).int()
|
22 |
+
|
23 |
+
# 入力データを適切なデバイスに送る
|
24 |
+
input_ids = input_ids.to(model.device)
|
25 |
+
attention_mask = attention_mask.to(model.device)
|
26 |
+
|
27 |
+
# モデルによる応答の生成
|
28 |
+
output = model.generate(input_ids, attention_mask=attention_mask, max_length=300, num_return_sequences=1, no_repeat_ngram_size=2, pad_token_id=model.config.eos_token_id)
|
29 |
+
|
30 |
+
# 生成されたテキストのデコード
|
31 |
+
output_text = tokenizer.decode(output[:, input_ids.shape[-1]:][0], skip_special_tokens=True)
|
32 |
+
|
33 |
+
print("ボット: " + output_text)
|
chat_bot_v2.py
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# from cybermodel.model import set_model
|
2 |
+
# from cybermodel.chatbot import run_bot
|
3 |
+
from cybermodel import set_model, run_bot
|
4 |
+
|
5 |
+
|
6 |
+
if __name__ == "__main__":
|
7 |
+
model_name = "cyberagent/open-calm-large"
|
8 |
+
model, tokenizer = set_model(model_name=model_name)
|
9 |
+
|
10 |
+
first_text = "ボット: ハロー!なんだい?"
|
11 |
+
you_text = "あなた:"
|
12 |
+
run_bot(model, tokenizer, first_text, you_text, max_count=1)
|
chat_generate.py
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
3 |
+
|
4 |
+
# モデルとトークナイザーのロード
|
5 |
+
model_name = "cyberagent/open-calm-large"
|
6 |
+
# model_name = "cyberagent/open-calm-3b"
|
7 |
+
model = AutoModelForCausalLM.from_pretrained(model_name).to(torch.device("cuda" if torch.cuda.is_available() else "cpu"))
|
8 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
9 |
+
|
10 |
+
inputs = tokenizer("Clinical AIは、", return_tensors="pt").to(model.device)
|
11 |
+
with torch.no_grad():
|
12 |
+
tokens = model.generate(
|
13 |
+
**inputs,
|
14 |
+
max_new_tokens=64,
|
15 |
+
do_sample=True,
|
16 |
+
temperature=0.7,
|
17 |
+
top_p=0.9,
|
18 |
+
repetition_penalty=1.05,
|
19 |
+
pad_token_id=tokenizer.pad_token_id,
|
20 |
+
)
|
21 |
+
|
22 |
+
output = tokenizer.decode(tokens[0], skip_special_tokens=True)
|
23 |
+
print(output)
|