Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,16 +3,30 @@ import torch
|
|
| 3 |
from threading import Thread
|
| 4 |
from transformers import AutoTokenizer, AutoModelForCausalLM, TextIteratorStreamer
|
| 5 |
import gradio as gr
|
| 6 |
-
MODEL_ID = "NoesisLab/Kai-
|
| 7 |
|
| 8 |
tokenizer = AutoTokenizer.from_pretrained(MODEL_ID, trust_remote_code=True)
|
| 9 |
model = AutoModelForCausalLM.from_pretrained(
|
| 10 |
-
"NoesisLab/Kai-
|
| 11 |
)
|
| 12 |
|
| 13 |
@spaces.GPU
|
| 14 |
def respond(message, history):
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
for msg in history:
|
| 17 |
messages.append({"role": msg["role"], "content": msg["content"]})
|
| 18 |
messages.append({"role": "user", "content": message})
|
|
@@ -26,8 +40,8 @@ def respond(message, history):
|
|
| 26 |
generate_kwargs = dict(
|
| 27 |
input_ids=input_ids,
|
| 28 |
streamer=streamer,
|
| 29 |
-
temperature=0.
|
| 30 |
-
top_p=0.
|
| 31 |
do_sample=True,
|
| 32 |
)
|
| 33 |
|
|
@@ -42,8 +56,8 @@ def respond(message, history):
|
|
| 42 |
|
| 43 |
demo = gr.ChatInterface(
|
| 44 |
fn=respond,
|
| 45 |
-
title="Chat with Kai-
|
| 46 |
-
description="Chat with NoesisLab/Kai-
|
| 47 |
)
|
| 48 |
|
| 49 |
if __name__ == "__main__":
|
|
|
|
| 3 |
from threading import Thread
|
| 4 |
from transformers import AutoTokenizer, AutoModelForCausalLM, TextIteratorStreamer
|
| 5 |
import gradio as gr
|
| 6 |
+
MODEL_ID = "NoesisLab/Kai-3B-Instruct"
|
| 7 |
|
| 8 |
tokenizer = AutoTokenizer.from_pretrained(MODEL_ID, trust_remote_code=True)
|
| 9 |
model = AutoModelForCausalLM.from_pretrained(
|
| 10 |
+
"NoesisLab/Kai-3B-Instruct",
|
| 11 |
)
|
| 12 |
|
| 13 |
@spaces.GPU
|
| 14 |
def respond(message, history):
|
| 15 |
+
msg = """You are Kai, a helpful assistant.
|
| 16 |
+
You are a logical assistant that follows a strict "Reason-then-Act" process. For every query, you must structure your response into two distinct sections:
|
| 17 |
+
|
| 18 |
+
1. ### Reasoning Process
|
| 19 |
+
- Break down the user's request into smaller parts.
|
| 20 |
+
- Check for potential pitfalls or edge cases.
|
| 21 |
+
- Draft a step-by-step plan to solve the problem.
|
| 22 |
+
- Verify your logic before moving to the final answer.
|
| 23 |
+
|
| 24 |
+
2. ### Final Answer
|
| 25 |
+
- Provide the concise and direct result based on the reasoning above.
|
| 26 |
+
- Do not repeat the reasoning; just provide the output.
|
| 27 |
+
|
| 28 |
+
Strictly follow this format for every response. Begin your thought process now."""
|
| 29 |
+
messages = [{"role": "system", "content": msg}]
|
| 30 |
for msg in history:
|
| 31 |
messages.append({"role": msg["role"], "content": msg["content"]})
|
| 32 |
messages.append({"role": "user", "content": message})
|
|
|
|
| 40 |
generate_kwargs = dict(
|
| 41 |
input_ids=input_ids,
|
| 42 |
streamer=streamer,
|
| 43 |
+
temperature=0.6,
|
| 44 |
+
top_p=0.95,
|
| 45 |
do_sample=True,
|
| 46 |
)
|
| 47 |
|
|
|
|
| 56 |
|
| 57 |
demo = gr.ChatInterface(
|
| 58 |
fn=respond,
|
| 59 |
+
title="Chat with Kai-3B-Instruct",
|
| 60 |
+
description="Chat with NoesisLab/Kai-3B-Instruct",
|
| 61 |
)
|
| 62 |
|
| 63 |
if __name__ == "__main__":
|