AMUseBot/chat.py

104 lines
2.9 KiB
Python
Raw Normal View History

2023-03-22 17:13:02 +01:00
from streamlit_option_menu import option_menu
2023-03-02 15:32:39 +01:00
from pathlib import Path
2023-03-22 17:13:02 +01:00
from src.utils.lang import en, ru
2023-03-20 12:50:21 +01:00
from src.utils.donates import show_donates
2023-03-22 17:13:02 +01:00
from src.utils.conversation import get_user_input, show_chat_buttons, show_conversation
2023-03-02 18:39:03 +01:00
2023-03-02 15:32:39 +01:00
import streamlit as st
# --- PATH SETTINGS ---
current_dir = Path(__file__).parent if "__file__" in locals() else Path.cwd()
css_file = current_dir / "src/styles/.css"
assets_dir = current_dir / "src/assets"
icons_dir = assets_dir / "icons"
# --- GENERAL SETTINGS ---
PAGE_TITLE = "AI Talks"
2023-03-02 18:34:01 +01:00
PAGE_ICON = "🤖"
2023-03-22 17:13:02 +01:00
AI_MODEL_OPTIONS = [
"gpt-3.5-turbo",
"gpt-4",
"gpt-4-32k",
]
2023-03-02 15:32:39 +01:00
st.set_page_config(page_title=PAGE_TITLE, page_icon=PAGE_ICON)
# --- LOAD CSS ---
with open(css_file) as f:
st.markdown("<style>{}</style>".format(f.read()), unsafe_allow_html=True)
2023-03-22 17:13:02 +01:00
selected_lang = option_menu(
menu_title=None,
options=["En", "Ru", ],
icons=["flag_en", "flag_ru"],
menu_icon="cast",
default_index=0,
orientation="horizontal",
styles={
2023-03-22 17:32:33 +01:00
"container": {
"padding": "0px",
"display": "grid",
"margin": "0!important",
"background-color": "#2C3333"
},
"icon": {"color": "#CBE4DE", "font-size": "14px"},
2023-03-22 17:13:02 +01:00
"nav-link": {
"font-size": "14px",
"text-align": "center",
"margin": "auto",
2023-03-22 17:32:33 +01:00
"background-color": "#2C3333",
2023-03-22 17:13:02 +01:00
"height": "30px",
"width": "13rem",
2023-03-22 17:32:33 +01:00
"color": "#CBE4DE",
2023-03-22 17:13:02 +01:00
"border-radius": "5px"
},
"nav-link-selected": {
2023-03-22 17:32:33 +01:00
"background-color": "#2E4F4F",
2023-03-22 17:13:02 +01:00
"font-weight": "300",
2023-03-22 17:32:33 +01:00
"color": "#f5f5f5",
"border": "1px solid #0E8388"
2023-03-22 17:13:02 +01:00
}
}
)
2023-03-02 15:32:39 +01:00
2023-03-11 15:39:23 +01:00
# Storing The Context
if "generated" not in st.session_state:
st.session_state["generated"] = []
if "past" not in st.session_state:
st.session_state["past"] = []
if "messages" not in st.session_state:
st.session_state["messages"] = []
if "user_text" not in st.session_state:
st.session_state["user_text"] = ""
2023-03-02 19:32:09 +01:00
def main() -> None:
2023-03-11 15:39:23 +01:00
user_content = get_user_input()
2023-03-22 17:13:02 +01:00
show_chat_buttons()
2023-03-02 19:32:09 +01:00
2023-03-22 17:13:02 +01:00
c1, c2 = st.columns(2)
with c1, c2:
model = c1.selectbox(label=st.session_state.locale.select_placeholder1, options=AI_MODEL_OPTIONS)
role = c2.selectbox(label=st.session_state.locale.select_placeholder2,
options=st.session_state.locale.ai_role_options)
2023-03-06 14:27:43 +01:00
2023-03-11 15:39:23 +01:00
if user_content:
2023-03-22 17:13:02 +01:00
show_conversation(user_content, model, role)
2023-03-02 19:32:09 +01:00
if __name__ == "__main__":
2023-03-22 17:13:02 +01:00
match selected_lang:
case "En":
st.session_state.locale = en
case "Ru":
st.session_state.locale = ru
case _:
locale = en
st.markdown(f"<h1 style='text-align: center;'>{st.session_state.locale.title}</h1>", unsafe_allow_html=True)
st.markdown("---")
2023-03-02 19:32:09 +01:00
main()
2023-03-20 12:50:21 +01:00
st.markdown("---")
2023-03-16 11:24:27 +01:00
st.image("assets/ai.jpg")
2023-03-20 12:50:21 +01:00
show_donates()