Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,40 +1,35 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
#
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
@chat.on_user_submit
|
| 37 |
-
async def _():
|
| 38 |
-
messages = chat.messages(format="langchain")
|
| 39 |
-
response = llm.astream(messages)
|
| 40 |
-
await chat.append_message_stream(response)
|
|
|
|
| 1 |
+
from shiny.express import ui
|
| 2 |
+
|
| 3 |
+
# Set some Shiny page options
|
| 4 |
+
ui.page_opts(
|
| 5 |
+
title="Hello Shiny Chat",
|
| 6 |
+
fillable=True,
|
| 7 |
+
fillable_mobile=True,
|
| 8 |
+
)
|
| 9 |
+
|
| 10 |
+
# Create a welcome message
|
| 11 |
+
welcome = ui.markdown(
|
| 12 |
+
"""
|
| 13 |
+
Hi! This is a simple Shiny `Chat` UI. Enter a message below and I will
|
| 14 |
+
simply repeat it back to you. For more examples, see this
|
| 15 |
+
[folder of examples](https://github.com/posit-dev/py-shiny/tree/main/examples/chat).
|
| 16 |
+
"""
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
# Create a chat instance
|
| 20 |
+
chat = ui.Chat(
|
| 21 |
+
id="chat",
|
| 22 |
+
messages=[welcome],
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
# Display it
|
| 26 |
+
chat.ui()
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
# Define a callback to run when the user submits a message
|
| 30 |
+
@chat.on_user_submit
|
| 31 |
+
async def _():
|
| 32 |
+
# Get the user's input
|
| 33 |
+
user = chat.user_input()
|
| 34 |
+
# Append a response to the chat
|
| 35 |
+
await chat.append_message(f"You said: {user}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|