Spaces:
Running
Running
Commit
·
032e12f
1
Parent(s):
d704768
Update app.py
Browse files
app.py
CHANGED
|
@@ -22,14 +22,23 @@ def _concat_messages(messages):
|
|
| 22 |
endpoint_url = os.environ.get("ENDPOINT_URL")
|
| 23 |
client = Client(endpoint_url, timeout=120)
|
| 24 |
|
| 25 |
-
def generate_response(user_input, max_new_token
|
| 26 |
msg = _concat_messages([
|
| 27 |
{"role": "system", "content": "你是一個由國立台灣大學的MiuLab實驗室開發的大型語言模型。你基於Transformer架構被訓練,並已經經過大量的台灣中文語料庫的訓練。你的設計目標是理解和生成優雅的繁體中文,並具有跨語境和跨領域的對話能力。使用者可以向你提問任何問題或提出任何話題,並期待從你那裡得到高質量的回答。你應該要盡量幫助使用者解決問題,提供他們需要的資訊,並在適當時候給予建議。"},
|
| 28 |
{"role": "user", "content": user_input},
|
| 29 |
])
|
| 30 |
msg += "<|assistant|>\n"
|
| 31 |
-
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
return [("assistant", res.generated_text)]
|
| 34 |
|
| 35 |
with gr.Blocks() as demo:
|
|
@@ -47,9 +56,9 @@ with gr.Blocks() as demo:
|
|
| 47 |
with gr.Column(scale=1):
|
| 48 |
emptyBtn = gr.Button("Clear History")
|
| 49 |
max_new_token = gr.Slider(
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
value=
|
| 53 |
step=1.0,
|
| 54 |
label="Maximum New Token Length",
|
| 55 |
interactive=True)
|
|
@@ -89,23 +98,17 @@ with gr.Blocks() as demo:
|
|
| 89 |
|
| 90 |
submitBtn.click(
|
| 91 |
generate_response,
|
| 92 |
-
[user_input],
|
| 93 |
[chatbot],
|
| 94 |
-
queue=False
|
| 95 |
-
|
| 96 |
-
None,
|
| 97 |
-
[user_input],
|
| 98 |
-
queue=False)
|
| 99 |
|
| 100 |
user_input.submit(
|
| 101 |
generate_response,
|
| 102 |
-
[user_input],
|
| 103 |
[chatbot],
|
| 104 |
-
queue=False
|
| 105 |
-
|
| 106 |
-
None,
|
| 107 |
-
[user_input],
|
| 108 |
-
queue=False)
|
| 109 |
|
| 110 |
submitBtn.click(lambda: None, [], [user_input])
|
| 111 |
|
|
|
|
| 22 |
endpoint_url = os.environ.get("ENDPOINT_URL")
|
| 23 |
client = Client(endpoint_url, timeout=120)
|
| 24 |
|
| 25 |
+
def generate_response(user_input, max_new_token, top_p, top_k, temperature, do_sample, repetition_penalty):
|
| 26 |
msg = _concat_messages([
|
| 27 |
{"role": "system", "content": "你是一個由國立台灣大學的MiuLab實驗室開發的大型語言模型。你基於Transformer架構被訓練,並已經經過大量的台灣中文語料庫的訓練。你的設計目標是理解和生成優雅的繁體中文,並具有跨語境和跨領域的對話能力。使用者可以向你提問任何問題或提出任何話題,並期待從你那裡得到高質量的回答。你應該要盡量幫助使用者解決問題,提供他們需要的資訊,並在適當時候給予建議。"},
|
| 28 |
{"role": "user", "content": user_input},
|
| 29 |
])
|
| 30 |
msg += "<|assistant|>\n"
|
| 31 |
+
|
| 32 |
+
res = client.generate(
|
| 33 |
+
msg,
|
| 34 |
+
stop_sequences=["<|assistant|>", eos_token, "<|system|>", "<|user|>"],
|
| 35 |
+
max_new_tokens=max_new_token,
|
| 36 |
+
top_p=top_p,
|
| 37 |
+
top_k=top_k,
|
| 38 |
+
do_sample=do_sample,
|
| 39 |
+
temperature=temperature,
|
| 40 |
+
repetition_penalty=repetition_penalty,
|
| 41 |
+
)
|
| 42 |
return [("assistant", res.generated_text)]
|
| 43 |
|
| 44 |
with gr.Blocks() as demo:
|
|
|
|
| 56 |
with gr.Column(scale=1):
|
| 57 |
emptyBtn = gr.Button("Clear History")
|
| 58 |
max_new_token = gr.Slider(
|
| 59 |
+
1,
|
| 60 |
+
1024,
|
| 61 |
+
value=128,
|
| 62 |
step=1.0,
|
| 63 |
label="Maximum New Token Length",
|
| 64 |
interactive=True)
|
|
|
|
| 98 |
|
| 99 |
submitBtn.click(
|
| 100 |
generate_response,
|
| 101 |
+
[user_input, max_new_token, top_p, top_k, temperature, do_sample, repetition_penalty],
|
| 102 |
[chatbot],
|
| 103 |
+
queue=False
|
| 104 |
+
)
|
|
|
|
|
|
|
|
|
|
| 105 |
|
| 106 |
user_input.submit(
|
| 107 |
generate_response,
|
| 108 |
+
[user_input, max_new_token, top_p, top_k, temperature, do_sample, repetition_penalty],
|
| 109 |
[chatbot],
|
| 110 |
+
queue=False
|
| 111 |
+
)
|
|
|
|
|
|
|
|
|
|
| 112 |
|
| 113 |
submitBtn.click(lambda: None, [], [user_input])
|
| 114 |
|