-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import streamlit as st | ||
import streamlit.components.v1 as components | ||
|
||
|
||
def load_tab_css(): | ||
with open("static/tab.css", "r") as f: | ||
css = f"<style>{f.read()}</style>" | ||
st.markdown(css, unsafe_allow_html=True) | ||
|
||
|
||
def initialize_session_state(): | ||
if "history" not in st.session_state: | ||
st.session_state.history = [] | ||
if "search_keywords" not in st.session_state: | ||
st.session_state.search_keywords = [] | ||
if "doc_sources" not in st.session_state: | ||
st.session_state.doc_sources = [] | ||
if "google_sources" not in st.session_state: | ||
st.session_state.google_sources = [] | ||
if "token_count" not in st.session_state: | ||
st.session_state.token_count = 0 | ||
if "chat_placeholder" not in st.session_state: | ||
st.session_state.chat_placeholder = None | ||
if "chat_output" not in st.session_state: | ||
st.session_state.chat_output = None | ||
if "chat_text" not in st.session_state: | ||
st.session_state.text = None | ||
|
||
|
||
def run_html(): | ||
return components.html(""" | ||
<script> | ||
const streamlitDoc = window.parent.document; | ||
const buttons = Array.from( | ||
streamlitDoc.querySelectorAll('.stButton > button') | ||
); | ||
const submitButton = buttons.find( | ||
el => el.innerText === 'Submit' | ||
); | ||
streamlitDoc.addEventListener('keydown', function(e) { | ||
switch (e.key) { | ||
case 'Enter': | ||
submitButton.click(); | ||
break; | ||
} | ||
}); | ||
</script> | ||
""", | ||
height=0, | ||
width=0, | ||
) |