Spaces:
Build error
Build error
jakewatson commited on
Commit ·
cfcf9ff
1
Parent(s): 8654a29
trying some variation of setting message
Browse files
app.py
CHANGED
|
@@ -195,7 +195,7 @@ Your responses should be concise, no more than 3 quotes, and consist only of fam
|
|
| 195 |
def respond(
|
| 196 |
message,
|
| 197 |
history: list[tuple[str, str]],
|
| 198 |
-
|
| 199 |
max_tokens=512,
|
| 200 |
temperature=0.7,
|
| 201 |
top_p=0.95,
|
|
@@ -204,7 +204,14 @@ def respond(
|
|
| 204 |
):
|
| 205 |
global stop_inference
|
| 206 |
stop_inference = False # Reset cancellation flag
|
| 207 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 208 |
# Initialize history if it's None
|
| 209 |
if history is None:
|
| 210 |
history = []
|
|
@@ -224,7 +231,6 @@ def respond(
|
|
| 224 |
messages,
|
| 225 |
max_new_tokens=max_tokens,
|
| 226 |
temperature=temperature,
|
| 227 |
-
practicality=practicality,
|
| 228 |
do_sample=True,
|
| 229 |
top_p=top_p,
|
| 230 |
):
|
|
@@ -252,7 +258,6 @@ def respond(
|
|
| 252 |
max_tokens=max_tokens,
|
| 253 |
stream=True,
|
| 254 |
temperature=temperature,
|
| 255 |
-
practicality=practicality,
|
| 256 |
top_p=top_p,
|
| 257 |
):
|
| 258 |
if stop_inference:
|
|
@@ -317,10 +322,11 @@ with gr.Blocks(css=custom_css) as demo:
|
|
| 317 |
gr.Markdown("Want to know the secret to life? Ask away!")
|
| 318 |
|
| 319 |
with gr.Row():
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
|
|
|
|
| 324 |
, label="System message"
|
| 325 |
, visible=False)
|
| 326 |
use_local_model = gr.Checkbox(label="Use Local Model", value=False)
|
|
@@ -336,16 +342,19 @@ with gr.Blocks(css=custom_css) as demo:
|
|
| 336 |
user_input = gr.Textbox(show_label=False, placeholder="Type your message here...")
|
| 337 |
|
| 338 |
cancel_button = gr.Button("Cancel Inference", variant="danger")
|
| 339 |
-
|
| 340 |
-
# if practicality > 0.5:
|
| 341 |
-
# system_message = f"{system_message}. Provide actionable advice or direct instructions."
|
| 342 |
-
# else:
|
| 343 |
-
# append_message = f"{system_message}. Provide theoretical concepts or abstract quotes."
|
| 344 |
-
|
| 345 |
# Adjusted to ensure history is maintained and passed correctly
|
| 346 |
-
user_input.submit(respond,
|
|
|
|
|
|
|
| 347 |
|
| 348 |
cancel_button.click(cancel_inference)
|
| 349 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 350 |
if __name__ == "__main__":
|
|
|
|
| 351 |
demo.launch(share=False) # Remove share=True because it's not supported on HF Spaces
|
|
|
|
| 195 |
def respond(
|
| 196 |
message,
|
| 197 |
history: list[tuple[str, str]],
|
| 198 |
+
system_message_val,
|
| 199 |
max_tokens=512,
|
| 200 |
temperature=0.7,
|
| 201 |
top_p=0.95,
|
|
|
|
| 204 |
):
|
| 205 |
global stop_inference
|
| 206 |
stop_inference = False # Reset cancellation flag
|
| 207 |
+
|
| 208 |
+
if practicality > 0.5:
|
| 209 |
+
system_message = f"{system_message_val}. Provide actionable advice or direct instructions."
|
| 210 |
+
else:
|
| 211 |
+
system_message = f"{system_message_val}. Provide theoretical concepts or abstract quotes."
|
| 212 |
+
|
| 213 |
+
system_message_update = gr.Textbox.update(value=system_message)
|
| 214 |
+
|
| 215 |
# Initialize history if it's None
|
| 216 |
if history is None:
|
| 217 |
history = []
|
|
|
|
| 231 |
messages,
|
| 232 |
max_new_tokens=max_tokens,
|
| 233 |
temperature=temperature,
|
|
|
|
| 234 |
do_sample=True,
|
| 235 |
top_p=top_p,
|
| 236 |
):
|
|
|
|
| 258 |
max_tokens=max_tokens,
|
| 259 |
stream=True,
|
| 260 |
temperature=temperature,
|
|
|
|
| 261 |
top_p=top_p,
|
| 262 |
):
|
| 263 |
if stop_inference:
|
|
|
|
| 322 |
gr.Markdown("Want to know the secret to life? Ask away!")
|
| 323 |
|
| 324 |
with gr.Row():
|
| 325 |
+
system_message_box = gr.Textbox(value=base_message
|
| 326 |
+
# """You are a chatbot that responds with famous quotes from books, movies, philsophers, and business leaders.
|
| 327 |
+
# Provide no advice, commentary, or additional context.
|
| 328 |
+
# Your responses should be concise, no more than 3 quotes, and consist only of famous motivational quotes.
|
| 329 |
+
# """
|
| 330 |
, label="System message"
|
| 331 |
, visible=False)
|
| 332 |
use_local_model = gr.Checkbox(label="Use Local Model", value=False)
|
|
|
|
| 342 |
user_input = gr.Textbox(show_label=False, placeholder="Type your message here...")
|
| 343 |
|
| 344 |
cancel_button = gr.Button("Cancel Inference", variant="danger")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 345 |
# Adjusted to ensure history is maintained and passed correctly
|
| 346 |
+
user_input.submit(respond,
|
| 347 |
+
inputs=[user_input, chat_history, system_message_box, max_tokens, temperature, top_p, use_local_model],
|
| 348 |
+
outputs=[chat_history, system_message_box])
|
| 349 |
|
| 350 |
cancel_button.click(cancel_inference)
|
| 351 |
|
| 352 |
+
# Test the local model
|
| 353 |
+
def test_local_model():
|
| 354 |
+
prompt = "What is the meaning of life?"
|
| 355 |
+
response = pipe(prompt, max_new_tokens=50)
|
| 356 |
+
print(response)
|
| 357 |
+
|
| 358 |
if __name__ == "__main__":
|
| 359 |
+
test_local_model
|
| 360 |
demo.launch(share=False) # Remove share=True because it's not supported on HF Spaces
|