Spaces:
Sleeping
Sleeping
trying to fix deployment [v8]
Browse files
app.py
CHANGED
|
@@ -14,14 +14,18 @@ import torch.nn.functional as F
|
|
| 14 |
import gradio as gr
|
| 15 |
from huggingface_hub import hf_hub_download
|
| 16 |
|
| 17 |
-
# Monkey-patch Gradio's buggy schema parser
|
|
|
|
| 18 |
import gradio_client.utils as _gcu
|
| 19 |
-
|
| 20 |
-
def
|
| 21 |
if isinstance(schema, bool):
|
| 22 |
-
return "
|
| 23 |
-
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 27 |
# β Download Model from HuggingFace Hub β
|
|
@@ -196,12 +200,14 @@ def respond(message, chat_history):
|
|
| 196 |
if not message.strip():
|
| 197 |
return "", chat_history
|
| 198 |
|
| 199 |
-
# Build prompt
|
| 200 |
ids = [BOS]
|
| 201 |
-
for
|
| 202 |
-
|
| 203 |
-
if
|
| 204 |
-
ids += [
|
|
|
|
|
|
|
| 205 |
ids += [USER_START] + enc.encode_ordinary(message) + [USER_END]
|
| 206 |
ids.append(ASST_START)
|
| 207 |
|
|
@@ -213,7 +219,8 @@ def respond(message, chat_history):
|
|
| 213 |
generated.append(token)
|
| 214 |
|
| 215 |
response = enc.decode(generated)
|
| 216 |
-
chat_history.append(
|
|
|
|
| 217 |
return "", chat_history
|
| 218 |
|
| 219 |
with gr.Blocks(
|
|
@@ -222,7 +229,7 @@ with gr.Blocks(
|
|
| 222 |
) as demo:
|
| 223 |
gr.Markdown("# π³ Treevik-1 500M Instruct\n**By PlusB Intelligence Lab** β’ Created by Sayan Chowdhury")
|
| 224 |
|
| 225 |
-
chatbot = gr.Chatbot(height=500, label="Chat with Treevik-1")
|
| 226 |
msg = gr.Textbox(placeholder="Type a message and press Enter...", label="Message", lines=1)
|
| 227 |
clear = gr.Button("ποΈ Clear Chat")
|
| 228 |
|
|
|
|
| 14 |
import gradio as gr
|
| 15 |
from huggingface_hub import hf_hub_download
|
| 16 |
|
| 17 |
+
# Monkey-patch Gradio's buggy schema parser β
|
| 18 |
+
# _json_schema_to_python_type crashes when additionalProperties is `True` (bool).
|
| 19 |
import gradio_client.utils as _gcu
|
| 20 |
+
_orig_jstpt = _gcu._json_schema_to_python_type
|
| 21 |
+
def _safe_jstpt(schema, defs=None):
|
| 22 |
if isinstance(schema, bool):
|
| 23 |
+
return "Any"
|
| 24 |
+
try:
|
| 25 |
+
return _orig_jstpt(schema, defs)
|
| 26 |
+
except _gcu.APIInfoParseError:
|
| 27 |
+
return "Any"
|
| 28 |
+
_gcu._json_schema_to_python_type = _safe_jstpt
|
| 29 |
|
| 30 |
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 31 |
# β Download Model from HuggingFace Hub β
|
|
|
|
| 200 |
if not message.strip():
|
| 201 |
return "", chat_history
|
| 202 |
|
| 203 |
+
# Build prompt from messages-format history
|
| 204 |
ids = [BOS]
|
| 205 |
+
for entry in chat_history:
|
| 206 |
+
role, content = entry["role"], entry["content"]
|
| 207 |
+
if role == "user":
|
| 208 |
+
ids += [USER_START] + enc.encode_ordinary(content) + [USER_END]
|
| 209 |
+
elif role == "assistant":
|
| 210 |
+
ids += [ASST_START] + enc.encode_ordinary(content) + [ASST_END]
|
| 211 |
ids += [USER_START] + enc.encode_ordinary(message) + [USER_END]
|
| 212 |
ids.append(ASST_START)
|
| 213 |
|
|
|
|
| 219 |
generated.append(token)
|
| 220 |
|
| 221 |
response = enc.decode(generated)
|
| 222 |
+
chat_history.append({"role": "user", "content": message})
|
| 223 |
+
chat_history.append({"role": "assistant", "content": response})
|
| 224 |
return "", chat_history
|
| 225 |
|
| 226 |
with gr.Blocks(
|
|
|
|
| 229 |
) as demo:
|
| 230 |
gr.Markdown("# π³ Treevik-1 500M Instruct\n**By PlusB Intelligence Lab** β’ Created by Sayan Chowdhury")
|
| 231 |
|
| 232 |
+
chatbot = gr.Chatbot(height=500, label="Chat with Treevik-1", type="messages")
|
| 233 |
msg = gr.Textbox(placeholder="Type a message and press Enter...", label="Message", lines=1)
|
| 234 |
clear = gr.Button("ποΈ Clear Chat")
|
| 235 |
|