Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,7 +2,6 @@ import streamlit as st
|
|
| 2 |
import streamlit_chat
|
| 3 |
import json
|
| 4 |
import os
|
| 5 |
-
import datetime
|
| 6 |
from pymongo import MongoClient
|
| 7 |
from bson import ObjectId
|
| 8 |
from dotenv import load_dotenv
|
|
@@ -14,6 +13,8 @@ import re
|
|
| 14 |
st.set_page_config(layout="wide", page_title="IOCL Chatbot", page_icon="📄")
|
| 15 |
load_dotenv()
|
| 16 |
import logging
|
|
|
|
|
|
|
| 17 |
|
| 18 |
logging.basicConfig(
|
| 19 |
level=logging.DEBUG, # This is for your application logs
|
|
@@ -55,8 +56,13 @@ if 'regenerate' not in st.session_state:
|
|
| 55 |
|
| 56 |
# Function to create a new chat session in MongoDB
|
| 57 |
def create_new_chat_session():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
new_session = {
|
| 59 |
-
"created_at":
|
| 60 |
"messages": [] # Empty at first
|
| 61 |
}
|
| 62 |
session_id = chat_sessions.insert_one(new_session).inserted_id
|
|
@@ -250,10 +256,13 @@ if st.sidebar.button("New Chat"):
|
|
| 250 |
existing_sessions = chat_sessions.find().sort("created_at", -1)
|
| 251 |
for session in existing_sessions:
|
| 252 |
session_id = str(session['_id'])
|
| 253 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 254 |
col1, col2 = st.sidebar.columns([8, 1])
|
| 255 |
-
|
| 256 |
-
# Display session name
|
| 257 |
with col1:
|
| 258 |
if st.button(f"Session {session_date}", key=session_id):
|
| 259 |
st.session_state['current_chat_id'] = session_id
|
|
|
|
| 2 |
import streamlit_chat
|
| 3 |
import json
|
| 4 |
import os
|
|
|
|
| 5 |
from pymongo import MongoClient
|
| 6 |
from bson import ObjectId
|
| 7 |
from dotenv import load_dotenv
|
|
|
|
| 13 |
st.set_page_config(layout="wide", page_title="IOCL Chatbot", page_icon="📄")
|
| 14 |
load_dotenv()
|
| 15 |
import logging
|
| 16 |
+
from pytz import timezone, utc
|
| 17 |
+
from datetime import datetime
|
| 18 |
|
| 19 |
logging.basicConfig(
|
| 20 |
level=logging.DEBUG, # This is for your application logs
|
|
|
|
| 56 |
|
| 57 |
# Function to create a new chat session in MongoDB
|
| 58 |
def create_new_chat_session():
|
| 59 |
+
# Get the current time in IST
|
| 60 |
+
ind_time = datetime.now(timezone("Asia/Kolkata"))
|
| 61 |
+
# Convert IST time to UTC for storing in MongoDB
|
| 62 |
+
utc_time = ind_time.astimezone(utc)
|
| 63 |
+
|
| 64 |
new_session = {
|
| 65 |
+
"created_at": utc_time, # Store in UTC
|
| 66 |
"messages": [] # Empty at first
|
| 67 |
}
|
| 68 |
session_id = chat_sessions.insert_one(new_session).inserted_id
|
|
|
|
| 256 |
existing_sessions = chat_sessions.find().sort("created_at", -1)
|
| 257 |
for session in existing_sessions:
|
| 258 |
session_id = str(session['_id'])
|
| 259 |
+
|
| 260 |
+
# Retrieve stored UTC time and convert it to IST for display
|
| 261 |
+
utc_time = session['created_at']
|
| 262 |
+
ist_time = utc_time.replace(tzinfo=utc).astimezone(timezone("Asia/Kolkata"))
|
| 263 |
+
session_date = ist_time.strftime("%Y-%m-%d %H:%M:%S") # Format for display
|
| 264 |
+
|
| 265 |
col1, col2 = st.sidebar.columns([8, 1])
|
|
|
|
|
|
|
| 266 |
with col1:
|
| 267 |
if st.button(f"Session {session_date}", key=session_id):
|
| 268 |
st.session_state['current_chat_id'] = session_id
|