Spaces:
Sleeping
Sleeping
trying ....
Browse files
app.py
CHANGED
|
@@ -181,13 +181,10 @@ ASST_END = enc.encode_single_token("<|assistant_end|>")
|
|
| 181 |
|
| 182 |
print(f"β
Loaded on {device} ({sum(p.numel() for p in model.parameters())/1e6:.0f}M params)")
|
| 183 |
|
| 184 |
-
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 185 |
-
# β Gradio Chat UI β
|
| 186 |
-
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 187 |
-
|
| 188 |
def respond(message, chat_history):
|
| 189 |
if not message.strip():
|
| 190 |
-
|
|
|
|
| 191 |
|
| 192 |
# Build prompt from messages-format history
|
| 193 |
ids = [BOS]
|
|
@@ -200,7 +197,7 @@ def respond(message, chat_history):
|
|
| 200 |
ids += [USER_START] + enc.encode_ordinary(message) + [USER_END]
|
| 201 |
ids.append(ASST_START)
|
| 202 |
|
| 203 |
-
# Generate full response
|
| 204 |
generated = []
|
| 205 |
for token in model.generate(ids, max_tokens=512, temperature=0.7, top_k=50):
|
| 206 |
if token == ASST_END:
|
|
@@ -208,24 +205,16 @@ def respond(message, chat_history):
|
|
| 208 |
generated.append(token)
|
| 209 |
|
| 210 |
response = enc.decode(generated)
|
| 211 |
-
|
| 212 |
-
chat_history.append({"role": "assistant", "content": response})
|
| 213 |
-
return "", chat_history
|
| 214 |
|
| 215 |
-
|
| 216 |
-
|
|
|
|
|
|
|
|
|
|
| 217 |
theme=gr.themes.Soft(primary_hue="indigo", secondary_hue="blue"),
|
| 218 |
-
)
|
| 219 |
-
gr.
|
| 220 |
-
|
| 221 |
-
chatbot = gr.Chatbot(height=500, label="Chat with Treevik-1", type="messages")
|
| 222 |
-
msg = gr.Textbox(placeholder="Type a message and press Enter...", label="Message", lines=1)
|
| 223 |
-
clear = gr.Button("ποΈ Clear Chat")
|
| 224 |
-
|
| 225 |
-
msg.submit(respond, [msg, chatbot], [msg, chatbot])
|
| 226 |
-
clear.click(lambda: (None, []), outputs=[msg, chatbot])
|
| 227 |
-
|
| 228 |
-
gr.Markdown("---\n*500M parameter model β may produce incorrect information. Built with β€οΈ at PlusB Intelligence Lab, India.*")
|
| 229 |
|
| 230 |
-
demo.queue()
|
| 231 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
|
| 181 |
|
| 182 |
print(f"β
Loaded on {device} ({sum(p.numel() for p in model.parameters())/1e6:.0f}M params)")
|
| 183 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 184 |
def respond(message, chat_history):
|
| 185 |
if not message.strip():
|
| 186 |
+
yield ""
|
| 187 |
+
return
|
| 188 |
|
| 189 |
# Build prompt from messages-format history
|
| 190 |
ids = [BOS]
|
|
|
|
| 197 |
ids += [USER_START] + enc.encode_ordinary(message) + [USER_END]
|
| 198 |
ids.append(ASST_START)
|
| 199 |
|
| 200 |
+
# Generate full response
|
| 201 |
generated = []
|
| 202 |
for token in model.generate(ids, max_tokens=512, temperature=0.7, top_k=50):
|
| 203 |
if token == ASST_END:
|
|
|
|
| 205 |
generated.append(token)
|
| 206 |
|
| 207 |
response = enc.decode(generated)
|
| 208 |
+
yield response
|
|
|
|
|
|
|
| 209 |
|
| 210 |
+
demo = gr.ChatInterface(
|
| 211 |
+
respond,
|
| 212 |
+
type="messages",
|
| 213 |
+
title="π³ Treevik-1 500M Instruct",
|
| 214 |
+
description="**By PlusB Intelligence Lab** β’ Created by Sayan Chowdhury\n\n*500M parameter model β may produce incorrect information.*",
|
| 215 |
theme=gr.themes.Soft(primary_hue="indigo", secondary_hue="blue"),
|
| 216 |
+
chatbot=gr.Chatbot(height=500),
|
| 217 |
+
textbox=gr.Textbox(placeholder="Type a message and press Enter...", container=False, scale=7),
|
| 218 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 219 |
|
|
|
|
| 220 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|