Spaces:
Build error
Build error
initial
Browse files- .chainlit/config.toml +81 -0
- .gitattributes β .gitattributes copy +0 -0
- .gitignore +2 -0
- Dockerfile +11 -0
- README copy.md +12 -0
- app.py +103 -0
- chainlit.md +2 -0
- public/custom_styles.css +8 -0
- requirements.txt +7 -0
.chainlit/config.toml
ADDED
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
[project]
|
2 |
+
# Whether to enable telemetry (default: true). No personal data is collected.
|
3 |
+
enable_telemetry = true
|
4 |
+
|
5 |
+
# List of environment variables to be provided by each user to use the app.
|
6 |
+
user_env = []
|
7 |
+
|
8 |
+
# Duration (in seconds) during which the session is saved when the connection is lost
|
9 |
+
session_timeout = 3600
|
10 |
+
|
11 |
+
# Enable third parties caching (e.g LangChain cache)
|
12 |
+
cache = false
|
13 |
+
|
14 |
+
# Follow symlink for asset mount (see https://github.com/Chainlit/chainlit/issues/317)
|
15 |
+
# follow_symlink = false
|
16 |
+
|
17 |
+
[features]
|
18 |
+
# Show the prompt playground
|
19 |
+
prompt_playground = true
|
20 |
+
|
21 |
+
# Process and display HTML in messages. This can be a security risk (see https://stackoverflow.com/questions/19603097/why-is-it-dangerous-to-render-user-generated-html-or-javascript)
|
22 |
+
unsafe_allow_html = false
|
23 |
+
|
24 |
+
# Process and display mathematical expressions. This can clash with "$" characters in messages.
|
25 |
+
latex = false
|
26 |
+
|
27 |
+
# Authorize users to upload files with messages
|
28 |
+
multi_modal = true
|
29 |
+
|
30 |
+
# Allows user to use speech to text
|
31 |
+
[features.speech_to_text]
|
32 |
+
enabled = true
|
33 |
+
# See all languages here https://github.com/JamesBrill/react-speech-recognition/blob/HEAD/docs/API.md#language-string
|
34 |
+
language = "en-US"
|
35 |
+
|
36 |
+
[UI]
|
37 |
+
# Name of the app and chatbot.
|
38 |
+
name = "Chainlit TutorialChatbot"
|
39 |
+
|
40 |
+
# Show the readme while the conversation is empty.
|
41 |
+
show_readme_as_default = true
|
42 |
+
|
43 |
+
# Description of the app and chatbot. This is used for HTML tags.
|
44 |
+
# description = ""
|
45 |
+
|
46 |
+
# Large size content are by default collapsed for a cleaner ui
|
47 |
+
default_collapse_content = true
|
48 |
+
|
49 |
+
# The default value for the expand messages settings.
|
50 |
+
default_expand_messages = false
|
51 |
+
|
52 |
+
# Hide the chain of thought details from the user in the UI.
|
53 |
+
hide_cot = false
|
54 |
+
|
55 |
+
# Link to your github repo. This will add a github button in the UI's header.
|
56 |
+
# github = ""
|
57 |
+
|
58 |
+
# Specify a CSS file that can be used to customize the user interface.
|
59 |
+
# The CSS file can be served from the public directory or via an external link.
|
60 |
+
# custom_css = "/public/test.css"
|
61 |
+
custom_css = "/public/custom_styles.css"
|
62 |
+
# Override default MUI light theme. (Check theme.ts)
|
63 |
+
[UI.theme.light]
|
64 |
+
background = "#E0F7FA" # Light Cyan for a refreshing background
|
65 |
+
paper = "#FFFFFF" # Keep the paper white for contrast
|
66 |
+
|
67 |
+
[UI.theme.light.primary]
|
68 |
+
main = "#0288D1" # A vibrant blue as the primary color
|
69 |
+
dark = "#01579B" # A deeper blue for darker elements
|
70 |
+
light = "#B3E5FC" # A light blue for accents and highlights
|
71 |
+
[UI.theme.dark]
|
72 |
+
background = "#1E3A5F" # A deep, rich blue for the background
|
73 |
+
paper = "#2C3E50" # Slightly lighter for paper elements
|
74 |
+
|
75 |
+
[UI.theme.dark.primary]
|
76 |
+
main = "#0288D1" # Same vibrant blue for consistency
|
77 |
+
dark = "#01579B" # A rich dark blue
|
78 |
+
light = "#4FC3F7" # A lighter blue for accents
|
79 |
+
|
80 |
+
[meta]
|
81 |
+
generated_by = "0.7.700"
|
.gitattributes β .gitattributes copy
RENAMED
File without changes
|
.gitignore
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
.env
|
2 |
+
__pycache__/
|
Dockerfile
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM python:3.9
|
2 |
+
RUN useradd -m -u 1000 user
|
3 |
+
USER user
|
4 |
+
ENV HOME=/home/user \
|
5 |
+
PATH=/home/user/.local/bin:$PATH
|
6 |
+
WORKDIR $HOME/app
|
7 |
+
COPY --chown=user . $HOME/app
|
8 |
+
COPY ./requirements.txt ~/app/requirements.txt
|
9 |
+
RUN pip install -r requirements.txt
|
10 |
+
COPY . .
|
11 |
+
CMD ["chainlit", "run", "app.py", "--port", "7860"]
|
README copy.md
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: Chainlit Tutorial
|
3 |
+
emoji: π
|
4 |
+
colorFrom: pink
|
5 |
+
colorTo: blue
|
6 |
+
sdk: docker
|
7 |
+
pinned: false
|
8 |
+
license: mit
|
9 |
+
short_description: Apps to showcase different Chainlit features
|
10 |
+
---
|
11 |
+
|
12 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import chainlit as cl
|
2 |
+
import os
|
3 |
+
from dotenv import load_dotenv
|
4 |
+
from langchain_core.prompts import ChatPromptTemplate
|
5 |
+
from langchain_core.runnables.config import RunnableConfig
|
6 |
+
from langchain_openai import ChatOpenAI
|
7 |
+
|
8 |
+
load_dotenv()
|
9 |
+
openai_api_key = os.getenv("OPENAI_API_KEY")
|
10 |
+
|
11 |
+
@cl.action_callback("hide_button")
|
12 |
+
async def on_action(action):
|
13 |
+
await cl.Message(content=f"Hiding the button").send()
|
14 |
+
await action.remove()
|
15 |
+
|
16 |
+
@cl.action_callback("show_text")
|
17 |
+
async def on_action(action):
|
18 |
+
cl.user_session.set("language", "english")
|
19 |
+
await cl.Message(content="The button was clicked and this text was shown").send()
|
20 |
+
|
21 |
+
@cl.action_callback("english")
|
22 |
+
async def on_action(action):
|
23 |
+
cl.user_session.set("language", "english")
|
24 |
+
await cl.Message(content="Responses from the Chatbot will be in English").send()
|
25 |
+
|
26 |
+
@cl.action_callback("icelandic")
|
27 |
+
async def on_action(action):
|
28 |
+
cl.user_session.set("language", "icelandic")
|
29 |
+
await cl.Message(content="Responses from the Chatbot will be in Icelandic").send()
|
30 |
+
|
31 |
+
user_template = """
|
32 |
+
Question:
|
33 |
+
{question}
|
34 |
+
|
35 |
+
Language:
|
36 |
+
{language}
|
37 |
+
"""
|
38 |
+
|
39 |
+
system_template = """
|
40 |
+
You are a helpful assistant who always speaks in a pleasant tone!
|
41 |
+
Do your best to answer the question succinctly and truthfully.
|
42 |
+
Think through your answers carefully.
|
43 |
+
Respond in the language provided below. If no language is provided, use Italian.
|
44 |
+
"""
|
45 |
+
|
46 |
+
#############################################
|
47 |
+
### On Chat Start (Session Start) Section ###
|
48 |
+
#############################################
|
49 |
+
@cl.on_chat_start
|
50 |
+
async def on_chat_start():
|
51 |
+
# create a chain
|
52 |
+
chat_prompt = ChatPromptTemplate.from_messages([
|
53 |
+
("system", system_template),
|
54 |
+
("human", user_template)
|
55 |
+
])
|
56 |
+
chat_model = ChatOpenAI(model="gpt-4o-mini")
|
57 |
+
simple_chain = chat_prompt | chat_model
|
58 |
+
cl.user_session.set("chain", simple_chain)
|
59 |
+
|
60 |
+
response = await cl.AskActionMessage(
|
61 |
+
content="Do you want to see the buttons?",
|
62 |
+
actions=[
|
63 |
+
cl.Action(name="yes", value="yes", label="β
Yes"),
|
64 |
+
cl.Action(name="no", value="no", label="β No"),
|
65 |
+
],
|
66 |
+
).send()
|
67 |
+
if response and response.get("value") == "yes":
|
68 |
+
actions = [
|
69 |
+
cl.Action(name="hide_button", value="hide-button", description="Hide this button"),
|
70 |
+
cl.Action(name="show_text", value="show_text", description="Show text")
|
71 |
+
]
|
72 |
+
|
73 |
+
await cl.Message(content="Different actions", actions=actions).send()
|
74 |
+
else:
|
75 |
+
await cl.Message(content="No buttons for you").send()
|
76 |
+
|
77 |
+
await cl.Message(content="Lets see how to change the language of the responses from the LLM").send()
|
78 |
+
|
79 |
+
actions = [
|
80 |
+
cl.Action(name="english", value="english", description="English"),
|
81 |
+
cl.Action(name="icelandic", value="icelandic", description="Icelandic")
|
82 |
+
]
|
83 |
+
|
84 |
+
await cl.Message(content="Languages", actions=actions).send()
|
85 |
+
|
86 |
+
await cl.Message(content="Ask the chatbot a question. Then click the Icelandic button and ask again.").send()
|
87 |
+
|
88 |
+
|
89 |
+
@cl.on_message
|
90 |
+
async def main(message: cl.Message):
|
91 |
+
chain = cl.user_session.get("chain")
|
92 |
+
language = cl.user_session.get("language", "english")
|
93 |
+
question = message.content
|
94 |
+
|
95 |
+
msg = cl.Message(content="")
|
96 |
+
# handle streaming of LLM responses
|
97 |
+
async for chunk in chain.astream(
|
98 |
+
{"question": question, "language": language},
|
99 |
+
config=RunnableConfig(callbacks=[cl.LangchainCallbackHandler()]),
|
100 |
+
):
|
101 |
+
await msg.stream_token(chunk.content)
|
102 |
+
|
103 |
+
await msg.send()
|
chainlit.md
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
# Sideckick POC
|
2 |
+
|
public/custom_styles.css
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
.message {
|
2 |
+
background-color: #E3F2FD !important; /* Light Blue background */
|
3 |
+
color: #1A237E !important; /* Dark Indigo text */
|
4 |
+
}
|
5 |
+
|
6 |
+
.MuiToolbar-root {
|
7 |
+
background-color: #b7dcf1 !important; /* Medium Blue background */
|
8 |
+
}
|
requirements.txt
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
chainlit==0.7.700
|
2 |
+
openai>=1.26.0
|
3 |
+
langchain==0.3.0
|
4 |
+
langchain-core==0.3.1
|
5 |
+
langchain-community==0.3.0
|
6 |
+
langchain-openai==0.2.0
|
7 |
+
|