|
import streamlit as st |
|
import datetime as DT |
|
import pytz |
|
import requests |
|
|
|
FONTS = [ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"Whisper", |
|
|
|
|
|
|
|
"Open+Sans:ital,wght@0,300..800;1,300..800", |
|
"Nunito+Sans:ital,opsz,wght@0,6..12,200..1000;1,6..12,200..1000", |
|
"Ubuntu:ital,wght@0,300;0,400;0,500;0,700;1,300;1,400;1,500;1,700", |
|
] |
|
|
|
|
|
def __nowInIST() -> DT.datetime: |
|
return DT.datetime.now(pytz.timezone("Asia/Kolkata")) |
|
|
|
|
|
def pprint(log: str): |
|
now = __nowInIST() |
|
now = now.strftime("%Y-%m-%d %H:%M:%S") |
|
print(f"[{now}] [{st.session_state.ipAddress}] {log}") |
|
|
|
|
|
def __getFontsUrl(): |
|
baseLink = "https://fonts.googleapis.com/css2" |
|
params = "&".join([f"family={font}" for font in FONTS]) |
|
params = f"{params}&display=swap" |
|
fontsUrl = f"{baseLink}?{params}" |
|
|
|
return fontsUrl |
|
|
|
|
|
def applyCommonStyles(): |
|
st.markdown( |
|
f""" |
|
<head> |
|
<link href="{__getFontsUrl()}" rel="stylesheet"> |
|
</head> |
|
""" """ |
|
<style> |
|
h1 { |
|
font-family: 'Whisper'; |
|
} |
|
|
|
|
|
h3, div[data-testid="stMarkdownContainer"], .stChatInput textarea, .stButton p { |
|
font-family: 'Ubuntu'; |
|
# font-weight: 300; |
|
} |
|
div[data-testid="stMarkdownContainer"] *:not(h1):not(h2):not(h3):not(h4):not(h5):not(h6) { |
|
font-size: 0.9rem; |
|
} |
|
.stButton p { |
|
font-size: 0.9rem !important; |
|
} |
|
|
|
@keyframes blinker { |
|
0% { |
|
opacity: 1; |
|
} |
|
50% { |
|
opacity: 0.2; |
|
} |
|
100% { |
|
opacity: 1; |
|
} |
|
} |
|
|
|
.blinking { |
|
animation: blinker 3s ease-out infinite; |
|
} |
|
|
|
.code { |
|
color: green; |
|
border-radius: 3px; |
|
padding: 2px 4px; /* Padding around the text */ |
|
font-family: 'Courier New', Courier, monospace; /* Monospace font */ |
|
} |
|
|
|
.large { |
|
font-size: 15px; |
|
} |
|
|
|
.bold { |
|
font-weight: bold; |
|
} |
|
|
|
div[aria-label="dialog"] { |
|
width: 80vw; |
|
height: 620px; |
|
} |
|
|
|
div.stSpinner { |
|
margin-left: auto; |
|
margin-right: auto; |
|
margin-top: 1rem; |
|
width: fit-content; |
|
} |
|
|
|
div.stAlert { |
|
margin-top: 1rem; |
|
} |
|
|
|
section[data-testid="stSidebar"] { |
|
background-color: #1a1c23 !important; |
|
} |
|
|
|
div[data-testid="stSidebarUserContent"] { |
|
padding-bottom: 1rem !important; |
|
} |
|
|
|
div[data-testid="stMarkdownContainer"] > hr { |
|
margin-top: 0.5rem; |
|
margin-bottom: 1rem; |
|
} |
|
|
|
</style> |
|
""", |
|
unsafe_allow_html=True |
|
) |
|
|
|
|
|
def isValidImageUrl(url): |
|
if not url: |
|
return False |
|
try: |
|
imageResponse = requests.head(url, timeout=5) |
|
contentType = imageResponse.headers.get('Content-Type', '') |
|
return imageResponse.status_code == 200 and contentType.startswith('image/') |
|
except Exception: |
|
return False |
|
|