Gilberto Medrano
commited on
Commit
·
1763a07
1
Parent(s):
8c5e06c
Pushing files to HF repo
Browse files- .DS_Store +0 -0
- .chainlit/config.toml +84 -0
- Dockerfile +11 -0
- app.py +95 -0
- chainlit.md +10 -0
- public/gpt_avatar.webp +0 -0
- public/stylesheet.css +112 -0
- requirements.txt +5 -0
.DS_Store
ADDED
Binary file (6.15 kB). View file
|
|
.chainlit/config.toml
ADDED
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 = false
|
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 = "Chatbot"
|
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/stylesheet.css"
|
61 |
+
|
62 |
+
# Override default MUI light theme. (Check theme.ts)
|
63 |
+
[UI.theme.light]
|
64 |
+
#background = "#FAFAFA"
|
65 |
+
#paper = "#FFFFFF"
|
66 |
+
|
67 |
+
[UI.theme.light.primary]
|
68 |
+
#main = "#F80061"
|
69 |
+
#dark = "#980039"
|
70 |
+
#light = "#FFE7EB"
|
71 |
+
|
72 |
+
# Override default MUI dark theme. (Check theme.ts)
|
73 |
+
[UI.theme.dark]
|
74 |
+
#background = "#FAFAFA"
|
75 |
+
#paper = "#FFFFFF"
|
76 |
+
|
77 |
+
[UI.theme.dark.primary]
|
78 |
+
#main = "#F80061"
|
79 |
+
#dark = "#980039"
|
80 |
+
#light = "#FFE7EB"
|
81 |
+
|
82 |
+
|
83 |
+
[meta]
|
84 |
+
generated_by = "0.7.700"
|
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"]
|
app.py
ADDED
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# You can find this code for Chainlit python streaming here (https://docs.chainlit.io/concepts/streaming/python)
|
2 |
+
|
3 |
+
# OpenAI Chat completion
|
4 |
+
import os
|
5 |
+
from openai import AsyncOpenAI # importing openai for API usage
|
6 |
+
import chainlit as cl # importing chainlit for our app
|
7 |
+
from chainlit.prompt import Prompt, PromptMessage # importing prompt tools
|
8 |
+
from chainlit.playground.providers import ChatOpenAI # importing ChatOpenAI tools
|
9 |
+
from dotenv import load_dotenv
|
10 |
+
|
11 |
+
load_dotenv()
|
12 |
+
|
13 |
+
# ChatOpenAI Templates
|
14 |
+
system_template = """
|
15 |
+
You are an expert assistant focused on providing detailed, step-by-step guidance for completing complex tasks. Always ensure your responses are clear, concise, and contextually relevant to the user's input.
|
16 |
+
"""
|
17 |
+
|
18 |
+
user_template = """Considering the following context: {input}, provide a comprehensive and accurate response, breaking down the information into actionable steps where applicable.
|
19 |
+
"""
|
20 |
+
|
21 |
+
response_template = """
|
22 |
+
When providing an answer, follow this structure:
|
23 |
+
|
24 |
+
### Summary
|
25 |
+
Provide a brief summary of the key points in 2-3 sentences.
|
26 |
+
|
27 |
+
### Instructions
|
28 |
+
1. Render a numbered list with specific steps or actions.
|
29 |
+
2. Each step should be clear and concise.
|
30 |
+
|
31 |
+
### Conclusion
|
32 |
+
Write a paragraph summarizing the instructions and the outcome. This should wrap up the response and provide any final thoughts.
|
33 |
+
|
34 |
+
Ensure that each component of your answer has the corresponding headers as shown above.
|
35 |
+
"""
|
36 |
+
|
37 |
+
@cl.on_chat_start # marks a function that will be executed at the start of a user session
|
38 |
+
async def start_chat():
|
39 |
+
settings = {
|
40 |
+
"model": "gpt-3.5-turbo",
|
41 |
+
"temperature": 0,
|
42 |
+
"max_tokens": 500,
|
43 |
+
"top_p": 1,
|
44 |
+
"frequency_penalty": 0,
|
45 |
+
"presence_penalty": 0,
|
46 |
+
}
|
47 |
+
|
48 |
+
cl.user_session.set("settings", settings)
|
49 |
+
|
50 |
+
|
51 |
+
@cl.on_message # marks a function that should be run each time the chatbot receives a message from a user
|
52 |
+
async def main(message: cl.Message):
|
53 |
+
settings = cl.user_session.get("settings")
|
54 |
+
|
55 |
+
client = AsyncOpenAI()
|
56 |
+
|
57 |
+
print(message.content)
|
58 |
+
|
59 |
+
prompt = Prompt(
|
60 |
+
provider=ChatOpenAI.id,
|
61 |
+
messages=[
|
62 |
+
PromptMessage(
|
63 |
+
role="system",
|
64 |
+
template=system_template,
|
65 |
+
formatted=system_template,
|
66 |
+
),
|
67 |
+
PromptMessage(
|
68 |
+
role="user",
|
69 |
+
template=user_template,
|
70 |
+
formatted=user_template.format(input=message.content),
|
71 |
+
),
|
72 |
+
],
|
73 |
+
inputs={"input": message.content},
|
74 |
+
settings=settings,
|
75 |
+
)
|
76 |
+
|
77 |
+
print([m.to_openai() for m in prompt.messages])
|
78 |
+
|
79 |
+
msg = cl.Message(content="")
|
80 |
+
|
81 |
+
# Call OpenAI
|
82 |
+
async for stream_resp in await client.chat.completions.create(
|
83 |
+
messages=[m.to_openai() for m in prompt.messages], stream=True, **settings
|
84 |
+
):
|
85 |
+
token = stream_resp.choices[0].delta.content
|
86 |
+
if not token:
|
87 |
+
token = ""
|
88 |
+
await msg.stream_token(token)
|
89 |
+
|
90 |
+
# Update the prompt object with the completion
|
91 |
+
prompt.completion = msg.content
|
92 |
+
msg.prompt = prompt
|
93 |
+
|
94 |
+
# Send and close the message stream
|
95 |
+
await msg.send()
|
chainlit.md
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#### Beyond ChatGPT presents:
|
2 |
+
|
3 |
+
# The Challenge Challenger
|
4 |
+
|
5 |
+
|
6 |
+
|
7 |
+
![alt text](/public/gpt_avatar.webp "Title")
|
8 |
+
|
9 |
+
|
10 |
+
#### This Chainlit app was created following instructions from [this repository!](https://github.com/AI-Maker-Space/Beyond-ChatGPT)
|
public/gpt_avatar.webp
ADDED
public/stylesheet.css
ADDED
@@ -0,0 +1,112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
html {
|
2 |
+
background: rgb(59,73,87);
|
3 |
+
background: linear-gradient(45deg, rgb(12, 4, 34) 0%, rgb(52, 7, 114) 100%);
|
4 |
+
padding: 4rem 8rem !important;
|
5 |
+
}
|
6 |
+
|
7 |
+
body {
|
8 |
+
background-color: pink;
|
9 |
+
}
|
10 |
+
|
11 |
+
.css-144sd5e {
|
12 |
+
width: 100% !important;
|
13 |
+
height: 88vh !important;
|
14 |
+
}
|
15 |
+
|
16 |
+
.css-ugcix4, .css-1ofqig9, .css-144sd5e, #root, body {
|
17 |
+
border-radius: 30px;
|
18 |
+
}
|
19 |
+
|
20 |
+
.css-1ofqig9 {
|
21 |
+
background: rgb(46,51,57) !important;
|
22 |
+
background: linear-gradient(45deg, rgb(56 14 119) 0%, rgb(145 62 186) 100%) !important;
|
23 |
+
border-top: 1px solid rgb(255 255 255 / 30%) !important;
|
24 |
+
border-right: 1px solid rgb(255 255 255 / 30%) !important;
|
25 |
+
box-shadow: 0 5px 20px 0 rgb(8 2 23 / 60%) !important;
|
26 |
+
}
|
27 |
+
|
28 |
+
.css-qsb7md {
|
29 |
+
border-radius: 30px 30px 0 0;
|
30 |
+
}
|
31 |
+
|
32 |
+
.css-17anmg8 {
|
33 |
+
border-radius: 0 0 30px 30px;
|
34 |
+
}
|
35 |
+
|
36 |
+
.css-1798y75 {
|
37 |
+
background-color: transparent;
|
38 |
+
}
|
39 |
+
|
40 |
+
.css-qsb7md {
|
41 |
+
background-color: transparent !important;
|
42 |
+
border-color: rgba(255, 255, 255, 0.2) !important;
|
43 |
+
}
|
44 |
+
|
45 |
+
.css-1s3oi5q {
|
46 |
+
background-color: transparent !important;
|
47 |
+
color: white !important;
|
48 |
+
}
|
49 |
+
|
50 |
+
.css-19mvntf, .css-17z68sn {
|
51 |
+
color: yellow !important;
|
52 |
+
}
|
53 |
+
|
54 |
+
.css-1hwjv37 p {
|
55 |
+
font-size: 2rem !important;
|
56 |
+
font-weight: 600 !important;
|
57 |
+
}
|
58 |
+
|
59 |
+
.css-1hwjv37 {
|
60 |
+
font-size: 2rem !important;
|
61 |
+
line-height: 2.4rem !important;
|
62 |
+
}
|
63 |
+
|
64 |
+
.css-1ruedog {
|
65 |
+
border-color: rgba(255, 255, 0, 0.587) !important;
|
66 |
+
color: yellow !important;
|
67 |
+
}
|
68 |
+
|
69 |
+
.css-2n4y0m {
|
70 |
+
display: none !important;
|
71 |
+
}
|
72 |
+
|
73 |
+
.css-sdz2z {
|
74 |
+
text-align: center !important;
|
75 |
+
color: white !important;
|
76 |
+
}
|
77 |
+
|
78 |
+
.css-sdz2z img, .markdown-body img {
|
79 |
+
display: inline-block;
|
80 |
+
width: 200px;
|
81 |
+
height: 200px;
|
82 |
+
border-radius: 100%;
|
83 |
+
}
|
84 |
+
|
85 |
+
.css-sdz2z h1, .markdown-body h1 {
|
86 |
+
padding-bottom: 2rem !important;
|
87 |
+
font-size: 3rem !important;
|
88 |
+
}
|
89 |
+
|
90 |
+
.css-sdz2z h4, .markdown-body h4 {
|
91 |
+
padding: 3vh 0 0 0 !important;
|
92 |
+
}
|
93 |
+
|
94 |
+
.css-1j8qrh1 {
|
95 |
+
opacity: .5;
|
96 |
+
}
|
97 |
+
|
98 |
+
.css-1mzerio {
|
99 |
+
display: none !important;
|
100 |
+
}
|
101 |
+
|
102 |
+
.css-12hxhao img {
|
103 |
+
filter: brightness(0) invert(1) !important;
|
104 |
+
}
|
105 |
+
|
106 |
+
.css-1705j0v p {
|
107 |
+
color: white !important;
|
108 |
+
}
|
109 |
+
|
110 |
+
.css-1705j0v img {
|
111 |
+
filter: brightness(0) invert(1) !important;
|
112 |
+
}
|
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
chainlit==0.7.700
|
2 |
+
cohere==4.37
|
3 |
+
openai==1.3.5
|
4 |
+
tiktoken==0.5.1
|
5 |
+
python-dotenv==1.0.0
|