Skip to content

Commit

Permalink
added utils
Browse files Browse the repository at this point in the history
  • Loading branch information
aju22 authored Jul 5, 2023
1 parent 36a3094 commit e44f543
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions utils.py
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,
)

0 comments on commit e44f543

Please sign in to comment.