Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -48,15 +48,8 @@ def respond(message, max_tokens, temperature, top_p):
|
|
| 48 |
thread = threading.Thread(target=run)
|
| 49 |
thread.start()
|
| 50 |
|
| 51 |
-
response = ""
|
| 52 |
for new_text in streamer:
|
| 53 |
-
|
| 54 |
-
# wrap model name and response in HTML
|
| 55 |
-
bubble = (
|
| 56 |
-
f"<div style='background:#eef2f5;padding:4px;border-radius:4px;font-size:small;max-width:fit-content;margin-bottom:4px;'>"
|
| 57 |
-
f"Model: {current_model_name}</div>" + response
|
| 58 |
-
)
|
| 59 |
-
yield bubble
|
| 60 |
|
| 61 |
# User input handler
|
| 62 |
def user(message, chat_history):
|
|
@@ -64,12 +57,18 @@ def user(message, chat_history):
|
|
| 64 |
return "", chat_history
|
| 65 |
|
| 66 |
# Bot response handler
|
| 67 |
-
def bot(
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
|
| 74 |
# Model selector handler
|
| 75 |
def update_model(model_name):
|
|
|
|
| 48 |
thread = threading.Thread(target=run)
|
| 49 |
thread.start()
|
| 50 |
|
|
|
|
| 51 |
for new_text in streamer:
|
| 52 |
+
yield new_text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
# User input handler
|
| 55 |
def user(message, chat_history):
|
|
|
|
| 57 |
return "", chat_history
|
| 58 |
|
| 59 |
# Bot response handler
|
| 60 |
+
def bot(chat_history, max_tokens, temperature, top_p):
|
| 61 |
+
# Insert model name bubble and placeholder for output
|
| 62 |
+
chat_history.append([None, f"**Model:** {current_model_name}"])
|
| 63 |
+
chat_history.append([None, ""])
|
| 64 |
+
# Render model name immediately
|
| 65 |
+
yield chat_history
|
| 66 |
+
|
| 67 |
+
# Stream generation into the last bubble
|
| 68 |
+
message = chat_history[-3][0] # Original user message
|
| 69 |
+
for chunk in respond(message, max_tokens, temperature, top_p):
|
| 70 |
+
chat_history[-1][1] += chunk
|
| 71 |
+
yield chat_history
|
| 72 |
|
| 73 |
# Model selector handler
|
| 74 |
def update_model(model_name):
|