Spaces:
Sleeping
Sleeping
| import torch | |
| from transformers import AutoModelForCausalLM, AutoTokenizer | |
| model = AutoModelForCausalLM.from_pretrained( | |
| "rinna/bilingual-gpt-neox-4b-instruction-ppo", | |
| tokenizer = AutoTokenizer.from_pretrained(MODEL_ID, use_fast=False) | |
| device = model.device | |
| device | |
| def generate(user_question, | |
| temperature=0.3, | |
| system_prompt_template = "システム: もちろんやで!どんどん質問してな!今日も気分ええわ!" | |
| # one-shot | |
| user_sample = "ユーザー:日本でよく飲まれているお茶の種類を教えて?" | |
| system_sample = "システム: 緑茶やで!緑茶って殺菌作用もあって最高よな!" | |
| user_sample = "ユーザー:日本一の高さの山は? " | |
| system_sample = "システム: 富士山や!最高の眺めを拝めるで!!" | |
| user_prerix = "ユーザー: " | |
| system_prefix = "システム: " | |
| output = tokenizer.decode(tokens[0], skip_special_tokens=True) | |
| return output[len(prompt):] | |
| output = generate('人工知能とは何ですか?') | |
| output | |
| with gr.Blocks() as demo: | |
| chat_history = gr.Chatbot() | |
| inputs = gr.Textbox(label="Question:", placeholder="質問を入力してください") | |
| outputs = gr.Textbox(label="Answer:") | |
| btn = gr.Button("Send") | |
| clear = gr.ClearButton([user_message, chat_history]) | |
| # ボタンが押された時の動作を以下のように定義する: | |
| # 「inputs内の値を入力としてモデルに渡し、その戻り値をoutputsの値として設定する」 | |
| btn.click(fn=generate, inputs=inputs, outputs=outputs) | |
| def response(user_message, chat_history): | |
| chat_history.append((user_message, system_message)) | |
| return "", chat_history | |
| user_message.submit(response, inputs=[user_message, chat_history], outputs=[user_message, chat_history]) | |
| if __name__ == "__main__": | |
| demo.launch() | |