Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added components/__pycache__/__init__.cpython-313.pyc
Binary file not shown.
Binary file not shown.
Binary file added components/__pycache__/header.cpython-313.pyc
Binary file not shown.
Binary file added components/__pycache__/sidebar.cpython-313.pyc
Binary file not shown.
38 changes: 38 additions & 0 deletions components/chat_interface.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,44 @@
import streamlit as st
from core.utils import get_current_time, get_ai_response

import streamlit.components.v1 as components
import streamlit as st
from datetime import datetime, timedelta
import json

def set_user_time_in_session():
if "user_time_offset" not in st.session_state:
# Embed JS to send local timezone offset in minutes
components.html("""
<script>
const offset = new Date().getTimezoneOffset(); // in minutes
const time = new Date().toLocaleString(); // full readable local time
const data = {offset: offset, time: time};
window.parent.postMessage({type: 'USER_TIME', data: data}, '*');
</script>
""", height=0)

st.markdown("""
<script>
window.addEventListener("message", (event) => {
if (event.data.type === "USER_TIME") {
const payload = JSON.stringify(event.data.data);
fetch("/", {
method: "POST",
headers: {"Content-Type": "application/json"},
body: payload
}).then(() => location.reload());
}
});
</script>
""", unsafe_allow_html=True)

else:
# Already set, do nothing
pass

set_user_time_in_session()

def render_chat_interface():
if st.session_state.active_conversation >= 0:
active_convo = st.session_state.conversations[st.session_state.active_conversation]
Expand Down
Binary file added core/__pycache__/__init__.cpython-313.pyc
Binary file not shown.
Binary file added core/__pycache__/config.cpython-313.pyc
Binary file not shown.
Binary file added core/__pycache__/utils.cpython-313.pyc
Binary file not shown.
2 changes: 1 addition & 1 deletion core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
def configure_gemini():
try:
api_key = st.secrets["GEMINI_API_KEY"]
genai.configure(api_key=api_key)
genai.configure(api_key="GEMINI_API_KEY")
model = genai.GenerativeModel('gemini-2.0-flash')
return model
except KeyError:
Expand Down
18 changes: 14 additions & 4 deletions core/utils.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
from datetime import datetime
from datetime import datetime, timedelta, timezone
import streamlit as st
import re

def get_current_time():
"""Returns the current time formatted as HH:MM AM/PM."""
now = datetime.now()
return now.strftime("%-I:%M %p") if hasattr(now, 'strftime') else now.strftime("%I:%M %p").lstrip('0')
"""Returns the user's local time formatted as HH:MM AM/PM."""
tz_offset = st.context.timezone_offset

if tz_offset is None:
# Default to UTC if timezone is not available (e.g., on Streamlit Cloud)
now = datetime.now()
else:
now_utc = datetime.now(timezone.utc)
now = now_utc + timedelta(minutes=-tz_offset)

return now.strftime("%I:%M %p").lstrip("0")



def create_new_conversation(initial_message=None):
"""
Expand Down
Binary file added css/__pycache__/styles.cpython-313.pyc
Binary file not shown.