add footer & support

This commit is contained in:
if 2023-03-24 00:58:02 +03:00
parent e709d776e9
commit 5e92c3c8a2
8 changed files with 100 additions and 43 deletions

1
assets/icons/tg.svg Normal file
View File

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 48" width="24px" height="24px"><linearGradient id="BiF7D16UlC0RZ_VqXJHnXa" x1="9.858" x2="38.142" y1="9.858" y2="38.142" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#33bef0"/><stop offset="1" stop-color="#0a85d9"/></linearGradient><path fill="url(#BiF7D16UlC0RZ_VqXJHnXa)" d="M44,24c0,11.045-8.955,20-20,20S4,35.045,4,24S12.955,4,24,4S44,12.955,44,24z"/><path d="M10.119,23.466c8.155-3.695,17.733-7.704,19.208-8.284c3.252-1.279,4.67,0.028,4.448,2.113 c-0.273,2.555-1.567,9.99-2.363,15.317c-0.466,3.117-2.154,4.072-4.059,2.863c-1.445-0.917-6.413-4.17-7.72-5.282 c-0.891-0.758-1.512-1.608-0.88-2.474c0.185-0.253,0.658-0.763,0.921-1.017c1.319-1.278,1.141-1.553-0.454-0.412 c-0.19,0.136-1.292,0.935-1.745,1.237c-1.11,0.74-2.131,0.78-3.862,0.192c-1.416-0.481-2.776-0.852-3.634-1.223 C8.794,25.983,8.34,24.272,10.119,23.466z" opacity=".05"/><path d="M10.836,23.591c7.572-3.385,16.884-7.264,18.246-7.813c3.264-1.318,4.465-0.536,4.114,2.011 c-0.326,2.358-1.483,9.654-2.294,14.545c-0.478,2.879-1.874,3.513-3.692,2.337c-1.139-0.734-5.723-3.754-6.835-4.633 c-0.86-0.679-1.751-1.463-0.71-2.598c0.348-0.379,2.27-2.234,3.707-3.614c0.833-0.801,0.536-1.196-0.469-0.508 c-1.843,1.263-4.858,3.262-5.396,3.625c-1.025,0.69-1.988,0.856-3.664,0.329c-1.321-0.416-2.597-0.819-3.262-1.078 C9.095,25.618,9.075,24.378,10.836,23.591z" opacity=".07"/><path fill="#fff" d="M11.553,23.717c6.99-3.075,16.035-6.824,17.284-7.343c3.275-1.358,4.28-1.098,3.779,1.91 c-0.36,2.162-1.398,9.319-2.226,13.774c-0.491,2.642-1.593,2.955-3.325,1.812c-0.833-0.55-5.038-3.331-5.951-3.984 c-0.833-0.595-1.982-1.311-0.541-2.721c0.513-0.502,3.874-3.712,6.493-6.21c0.343-0.328-0.088-0.867-0.484-0.604 c-3.53,2.341-8.424,5.59-9.047,6.013c-0.941,0.639-1.845,0.932-3.467,0.466c-1.226-0.352-2.423-0.772-2.889-0.932 C9.384,25.282,9.81,24.484,11.553,23.717z"/></svg>

After

Width:  |  Height:  |  Size: 1.8 KiB

54
chat.py
View File

@ -1,8 +1,9 @@
from streamlit_option_menu import option_menu from streamlit_option_menu import option_menu
from pathlib import Path from pathlib import Path
from src.styles.menu_styles import HEADER_STYLES, FOOTER_STYLES
from src.utils.lang import en, ru from src.utils.lang import en, ru
from src.utils.donates import show_donates from src.utils.footer import show_donates, show_info
from src.utils.conversation import get_user_input, show_chat_buttons, show_conversation from src.utils.conversation import get_user_input, show_chat_buttons, show_conversation
import streamlit as st import streamlit as st
@ -10,8 +11,10 @@ import streamlit as st
# --- PATH SETTINGS --- # --- PATH SETTINGS ---
current_dir = Path(__file__).parent if "__file__" in locals() else Path.cwd() current_dir = Path(__file__).parent if "__file__" in locals() else Path.cwd()
css_file = current_dir / "src/styles/.css" css_file = current_dir / "src/styles/.css"
assets_dir = current_dir / "src/assets" assets_dir = current_dir / "assets"
icons_dir = assets_dir / "icons" icons_dir = assets_dir / "icons"
tg_svg = icons_dir / "telegram.svg"
tg_svg = icons_dir / "tg.svg"
# --- GENERAL SETTINGS --- # --- GENERAL SETTINGS ---
PAGE_TITLE = "AI Talks" PAGE_TITLE = "AI Talks"
@ -31,35 +34,11 @@ with open(css_file) as f:
selected_lang = option_menu( selected_lang = option_menu(
menu_title=None, menu_title=None,
options=["En", "Ru", ], options=["En", "Ru", ],
icons=["flag_en", "flag_ru"], icons=["globe2", "globe"],
menu_icon="cast", menu_icon="cast",
default_index=0, default_index=1,
orientation="horizontal", orientation="horizontal",
styles={ styles=HEADER_STYLES
"container": {
"padding": "0px",
"display": "grid",
"margin": "0!important",
"background-color": "#2C3333"
},
"icon": {"color": "#CBE4DE", "font-size": "14px"},
"nav-link": {
"font-size": "14px",
"text-align": "center",
"margin": "auto",
"background-color": "#2C3333",
"height": "30px",
"width": "7rem",
"color": "#CBE4DE",
"border-radius": "5px"
},
"nav-link-selected": {
"background-color": "#2E4F4F",
"font-weight": "300",
"color": "#f5f5f5",
"border": "1px solid #0E8388"
}
}
) )
# Storing The Context # Storing The Context
@ -100,4 +79,21 @@ if __name__ == "__main__":
main() main()
st.markdown("---") st.markdown("---")
st.image("assets/ai.jpg") st.image("assets/ai.jpg")
st.markdown("---")
selected_footer = option_menu(
menu_title=None,
options=["Info", "Donates", ],
icons=["info-circle", "piggy-bank"],
menu_icon="cast",
default_index=0,
orientation="horizontal",
styles=FOOTER_STYLES
)
st.markdown("---")
match selected_footer:
case "Info":
show_info(tg_svg)
case "Donates":
show_donates() show_donates()
case _:
show_info(tg_svg)

0
src/styles/__init__.py Normal file
View File

31
src/styles/menu_styles.py Normal file
View File

@ -0,0 +1,31 @@
from typing import Dict
HEADER_STYLES: Dict[str, Dict] = {
"container": {
"padding": "0px",
"display": "grid",
"margin": "0!important",
"background-color": "#2C3333"
},
"icon": {"color": "#CBE4DE", "font-size": "14px"},
"nav-link": {
"font-size": "14px",
"text-align": "center",
"margin": "auto",
"background-color": "#2C3333",
"height": "30px",
"width": "7rem",
"color": "#CBE4DE",
"border-radius": "5px"
},
"nav-link-selected": {
"background-color": "#2E4F4F",
"font-weight": "300",
"color": "#f5f5f5",
"border": "1px solid #0E8388"
}
}
FOOTER_STYLES: Dict[str, Dict] = {
}

View File

@ -21,9 +21,9 @@ def get_user_input() -> str:
def show_chat_buttons() -> None: def show_chat_buttons() -> None:
b0, b1, b2 = st.columns(3) b0, b1, b2 = st.columns(3)
with b0, b1, b2: with b0, b1, b2:
b0.button(st.session_state.locale.chat_btn0) b0.button(st.session_state.locale.chat_run_btn)
b1.button(st.session_state.locale.chat_btn1, on_click=st.cache_data.clear) b1.button(st.session_state.locale.chat_rerun_btn, on_click=st.cache_data.clear)
b2.button(st.session_state.locale.chat_btn2, on_click=clear_chat) b2.button(st.session_state.locale.chat_clear_btn, on_click=clear_chat)
def show_chat(ai_content: str, user_text: str) -> None: def show_chat(ai_content: str, user_text: str) -> None:

View File

@ -1,8 +1,19 @@
from pathlib import Path
import streamlit as st import streamlit as st
from src.utils.helpers import render_svg
def show_info(icon: Path) -> None:
st.markdown(f"""
### :page_with_curl: {st.session_state.locale.footer_title}
- {render_svg(icon)} [{st.session_state.locale.footer_chat}](https://t.me/talks_ai)
- {render_svg(icon)} [{st.session_state.locale.footer_channel}](https://t.me/talks_aii)
""", unsafe_allow_html=True)
def show_donates() -> None: def show_donates() -> None:
st.markdown("---")
st.markdown(f""" st.markdown(f"""
### :moneybag: {st.session_state.locale.donates} ### :moneybag: {st.session_state.locale.donates}
**{st.session_state.locale.donates1}:** **{st.session_state.locale.donates1}:**

9
src/utils/helpers.py Normal file
View File

@ -0,0 +1,9 @@
import base64
from pathlib import Path
def render_svg(svg: Path) -> str:
"""Renders the given svg string."""
with open(svg) as file:
b64 = base64.b64encode(file.read().encode("utf-8")).decode("utf-8")
return f"<img src='data:image/svg+xml;base64,{b64}'/>"

View File

@ -14,12 +14,15 @@ class Locale:
donates1: str donates1: str
donates2: str donates2: str
chat_placeholder: str chat_placeholder: str
chat_btn0: str chat_run_btn: str
chat_btn1: str chat_rerun_btn: str
chat_btn2: str chat_clear_btn: str
select_placeholder1: str select_placeholder1: str
select_placeholder2: str select_placeholder2: str
stt_placeholder: str stt_placeholder: str
footer_title: str
footer_chat: str
footer_channel: str
# Child data class for English # Child data class for English
@ -33,12 +36,15 @@ class EnLocale(Locale):
donates1: str = "Russia" donates1: str = "Russia"
donates2: str = "World" donates2: str = "World"
chat_placeholder: str = "Start Your Conversation With AI:" chat_placeholder: str = "Start Your Conversation With AI:"
chat_btn0: str = "Run" chat_run_btn: str = "Run"
chat_btn1: str = "Rerun" chat_rerun_btn: str = "Rerun"
chat_btn2: str = "Clear Conversation" chat_clear_btn: str = "Clear Conversation"
select_placeholder1: str = "Select AI Model" select_placeholder1: str = "Select AI Model"
select_placeholder2: str = "Select AI Role" select_placeholder2: str = "Select AI Role"
stt_placeholder: str = "To Hear The Voice Of AI, Press Play" stt_placeholder: str = "To Hear The Voice Of AI, Press Play"
footer_title: str = "Support & Feedback"
footer_chat: str = "AI Talks Chat"
footer_channel: str = "AI Talks Channel"
# Child data class for Russian # Child data class for Russian
@ -52,12 +58,15 @@ class RuLocale(Locale):
donates1: str = "Россия" donates1: str = "Россия"
donates2: str = "Остальной Мир" donates2: str = "Остальной Мир"
chat_placeholder: str = "Начните Вашу Беседу с ИИ:" chat_placeholder: str = "Начните Вашу Беседу с ИИ:"
chat_btn0: str = "Запустить" chat_run_btn: str = "Запустить"
chat_btn1: str = "Перезапустить" chat_rerun_btn: str = "Перезапустить"
chat_btn2: str = "Очистить Беседу" chat_clear_btn: str = "Очистить Беседу"
select_placeholder1: str = "Выберите Модель ИИ" select_placeholder1: str = "Выберите Модель ИИ"
select_placeholder2: str = "Выберите Роль ИИ" select_placeholder2: str = "Выберите Роль ИИ"
stt_placeholder: str = "Чтобы Услышать ИИ Нажми Кнопку Проигрывателя" stt_placeholder: str = "Чтобы Услышать ИИ Нажми Кнопку Проигрывателя"
footer_title: str = "Поддержка и Обратная Связь"
footer_chat: str = "Чат Разговорчики с ИИ"
footer_channel: str = "Канал Разговорчики с ИИ"
AI_ROLE_OPTIONS_EN = [ AI_ROLE_OPTIONS_EN = [