Skip to content

Commit

Permalink
changed text_input to text_area to support multiple lines; restructur…
Browse files Browse the repository at this point in the history
…ed src.header; updated README.md
  • Loading branch information
3x3cut0r committed Nov 14, 2023
1 parent e5a22e7 commit 435a077
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 66 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,13 @@ pip install -r requirements.txt
"enable_context": "True",
"stream": "True",
"max_tokens": "256",
...
"temperature": "0.2",
"top_p": "0.95",
"top_k": "40",
"repeat_penalty": "1.1",
"stop": "###",
"system_content": "User asks Questions to the AI. AI is helpful, kind, obedient, honest, and knows its own limits.",
"prompt": "### Instructions:\n{prompt}\n\n### Response:\n"
}
```

Expand Down
1 change: 1 addition & 0 deletions src/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def render(container): # container = st.container()
for element in st.session_state['context']:

# if question
# todo: still vulnerable to code (html) injection, e.g.: <script> ... </script>
if 'question' in element:
q = element['question']
st.markdown(
Expand Down
69 changes: 15 additions & 54 deletions src/header.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,63 +2,15 @@
import streamlit as st
from PIL import Image
favicon = Image.open('static/favicon.png')
import src.logo as logo
import src.styles as styles
import src.session as session
import src.sidebar as sidebar

# load title from config-file
with open("src/config.json", "r", encoding="utf-8") as file:
config = json.load(file)

# adds the logo to the sidebar
def logo():

# render logo
st.markdown(
f"""
<style>
[data-testid="stSidebar"] {{
background-image: url(app/static/logo.png);
background-repeat: no-repeat;
background-position: 20px 20px;
background-size: auto 80px;
}}
[data-testid="stSidebar"] [data-testid="stVerticalBlock"] {{
padding-top: 20px;
}}
[data-testid="stForm"] {{
border: none;
padding-left: 0px;
}}
[data-testid="stMarkdownContainer"] {{
font-weight: normal;
}}
[data-testid="stMarkdown"] p,
[data-testid="stMarkdown"] ol {{
background-color: #444654;
color: #ced2d8;
margin: 0px;
padding: 20px;
}}
[data-testid="stMarkdown"] [data-testid="stCodeBlock"] {{
background-color: #444654;
color: #ced2d8;
margin: 0px;
padding-left: 10px;
padding-right: 10px;
}}
[data-testid="stCodeBlock"] {{
margin: 0px;
padding-left: 10px;
}}
</style>
""",
unsafe_allow_html=True,
)

# call render method to set the header on every page
def render(page_title = None):

Expand All @@ -77,8 +29,17 @@ def render(page_title = None):
initial_sidebar_state='expanded',
)

# logo
logo()
# render logo
logo.render()

# apply styles
styles.render()

# load config
session.load()

# render sidebar
sidebar.render()

# title
st.title(page_title)
17 changes: 17 additions & 0 deletions src/logo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import streamlit as st

# render logo
def render():
st.markdown(
f"""
<style>
[data-testid="stSidebar"] {{
background-image: url(app/static/logo.png);
background-repeat: no-repeat;
background-position: 20px 20px;
background-size: auto 80px;
}}
</style>
""",
unsafe_allow_html=True,
)
48 changes: 48 additions & 0 deletions src/styles.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import streamlit as st

# render styles
def render():
st.markdown(
f"""
<style>
[data-testid="stSidebar"] [data-testid="stVerticalBlock"] {{
padding-top: 20px;
}}
[data-testid="stForm"] {{
border: none;
padding-left: 0px;
}}
[data-testid="stMarkdownContainer"] {{
font-weight: normal;
}}
[data-testid="stMarkdown"] p,
[data-testid="stMarkdown"] ol {{
background-color: #444654;
color: #ced2d8;
margin: 0px;
padding: 20px;
}}
[data-testid="stMarkdown"] [data-testid="stCodeBlock"] {{
background-color: #444654;
color: #ced2d8;
margin: 0px;
padding-left: 10px;
padding-right: 10px;
}}
[data-testid="stCodeBlock"] {{
margin: 0px;
padding-left: 10px;
}}
.st-es {{
min-height: 55px;
}}
</style>
""",
unsafe_allow_html=True,
)
14 changes: 3 additions & 11 deletions streamlit_app.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
import streamlit as st
import src.header as header
import src.session as session
import src.sidebar as sidebar
import src.request as request
import src.context as context

# render header
header.render()

# load config
session.load()

# render sidebar
sidebar.render()
header.render()

# render content_container
content_container = st.empty()
Expand All @@ -21,12 +13,12 @@
if 'context' in st.session_state:
context.render(content_container)

# render message-text_input + generate-submit_button
# render message-text_area + generate-submit_button
with st.form("Prompt Form", clear_on_submit=True):
col1, col2 = st.columns([2,1])

with col1:
user_content = st.text_input(label="Enter your message", value="", label_visibility="collapsed", placeholder="Enter your message")
user_content = st.text_area(label="Enter your message", value="", height=55, label_visibility="collapsed", placeholder="Enter your message")

with col2:
generate_button = st.form_submit_button('Generate')
Expand Down

0 comments on commit 435a077

Please sign in to comment.