Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
import torch
|
2 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
|
|
3 |
|
4 |
model = AutoModelForCausalLM.from_pretrained(
|
5 |
"rinna/bilingual-gpt-neox-4b-instruction-ppo",
|
@@ -11,7 +12,6 @@ MODEL_ID = "rinna/bilingual-gpt-neox-4b-instruction-ppo"
|
|
11 |
tokenizer = AutoTokenizer.from_pretrained(MODEL_ID, use_fast=False)
|
12 |
|
13 |
device = model.device
|
14 |
-
device
|
15 |
|
16 |
def generate(user_question,
|
17 |
temperature=0.3,
|
@@ -25,13 +25,9 @@ def generate(user_question,
|
|
25 |
system_prompt_template = "システム: もちろんやで!どんどん質問してな!今日も気分ええわ!"
|
26 |
|
27 |
# one-shot
|
28 |
-
user_sample = "ユーザー:日本でよく飲まれているお茶の種類を教えて?"
|
29 |
-
system_sample = "システム: 緑茶やで!緑茶って殺菌作用もあって最高よな!"
|
30 |
-
|
31 |
user_sample = "ユーザー:日本一の高さの山は? "
|
32 |
system_sample = "システム: 富士山や!最高の眺めを拝めるで!!"
|
33 |
|
34 |
-
|
35 |
user_prerix = "ユーザー: "
|
36 |
system_prefix = "システム: "
|
37 |
|
@@ -56,19 +52,14 @@ def generate(user_question,
|
|
56 |
output = tokenizer.decode(tokens[0], skip_special_tokens=True)
|
57 |
return output[len(prompt):]
|
58 |
|
59 |
-
|
60 |
-
output = generate('人工知能とは何ですか?')
|
61 |
-
output
|
62 |
-
|
63 |
with gr.Blocks() as demo:
|
64 |
chat_history = gr.Chatbot()
|
65 |
inputs = gr.Textbox(label="Question:", placeholder="質問を入力してください")
|
66 |
outputs = gr.Textbox(label="Answer:")
|
67 |
btn = gr.Button("Send")
|
68 |
-
clear = gr.ClearButton([
|
69 |
|
70 |
-
# ボタンが押された時の動作を以下のように定義する:
|
71 |
-
# 「inputs内の値を入力としてモデルに渡し、その戻り値をoutputsの値として設定する」
|
72 |
btn.click(fn=generate, inputs=inputs, outputs=outputs)
|
73 |
|
74 |
def response(user_message, chat_history):
|
@@ -76,9 +67,7 @@ with gr.Blocks() as demo:
|
|
76 |
chat_history.append((user_message, system_message))
|
77 |
return "", chat_history
|
78 |
|
79 |
-
|
80 |
|
81 |
if __name__ == "__main__":
|
82 |
demo.launch()
|
83 |
-
|
84 |
-
|
|
|
1 |
import torch
|
2 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
3 |
+
import gradio as gr
|
4 |
|
5 |
model = AutoModelForCausalLM.from_pretrained(
|
6 |
"rinna/bilingual-gpt-neox-4b-instruction-ppo",
|
|
|
12 |
tokenizer = AutoTokenizer.from_pretrained(MODEL_ID, use_fast=False)
|
13 |
|
14 |
device = model.device
|
|
|
15 |
|
16 |
def generate(user_question,
|
17 |
temperature=0.3,
|
|
|
25 |
system_prompt_template = "システム: もちろんやで!どんどん質問してな!今日も気分ええわ!"
|
26 |
|
27 |
# one-shot
|
|
|
|
|
|
|
28 |
user_sample = "ユーザー:日本一の高さの山は? "
|
29 |
system_sample = "システム: 富士山や!最高の眺めを拝めるで!!"
|
30 |
|
|
|
31 |
user_prerix = "ユーザー: "
|
32 |
system_prefix = "システム: "
|
33 |
|
|
|
52 |
output = tokenizer.decode(tokens[0], skip_special_tokens=True)
|
53 |
return output[len(prompt):]
|
54 |
|
|
|
|
|
|
|
|
|
55 |
with gr.Blocks() as demo:
|
56 |
chat_history = gr.Chatbot()
|
57 |
inputs = gr.Textbox(label="Question:", placeholder="質問を入力してください")
|
58 |
outputs = gr.Textbox(label="Answer:")
|
59 |
btn = gr.Button("Send")
|
60 |
+
clear = gr.ClearButton([inputs, chat_history])
|
61 |
|
62 |
+
# ボタンが押された時の動作を以下のように定義する:
|
|
|
63 |
btn.click(fn=generate, inputs=inputs, outputs=outputs)
|
64 |
|
65 |
def response(user_message, chat_history):
|
|
|
67 |
chat_history.append((user_message, system_message))
|
68 |
return "", chat_history
|
69 |
|
70 |
+
inputs.submit(response, inputs=[inputs, chat_history], outputs=[inputs, chat_history])
|
71 |
|
72 |
if __name__ == "__main__":
|
73 |
demo.launch()
|
|
|
|