Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,10 +1,32 @@
|
|
1 |
-
import streamlit as st
|
2 |
from openai import OpenAI
|
3 |
import time
|
4 |
import os
|
5 |
import uuid
|
6 |
import firebase_admin
|
7 |
from firebase_admin import credentials, firestore
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
# π Firebase setup
|
10 |
if not firebase_admin._apps:
|
@@ -15,7 +37,7 @@ db = firestore.client()
|
|
15 |
|
16 |
# π OpenAI setup
|
17 |
openai_key = os.getenv("openai_key")
|
18 |
-
assistant_id = os.getenv("
|
19 |
client = OpenAI(api_key=openai_key)
|
20 |
|
21 |
# π Streamlit Config
|
@@ -26,7 +48,7 @@ if "user_id" not in st.session_state:
|
|
26 |
st.session_state["user_id"] = str(uuid.uuid4())
|
27 |
user_id = st.session_state["user_id"]
|
28 |
|
29 |
-
# πΌοΈ
|
30 |
st.markdown("""
|
31 |
<style>
|
32 |
.block-container {padding-top: 1rem; padding-bottom: 0rem;}
|
@@ -34,7 +56,7 @@ st.markdown("""
|
|
34 |
.stChatMessage { max-width: 85%; border-radius: 12px; padding: 8px; margin-bottom: 10px; }
|
35 |
.stChatMessage[data-testid="stChatMessage-user"] { background: #f0f0f0; color: #000000; }
|
36 |
.stChatMessage[data-testid="stChatMessage-assistant"] { background: #e3f2fd; color: #000000; }
|
37 |
-
.
|
38 |
</style>
|
39 |
""", unsafe_allow_html=True)
|
40 |
|
@@ -75,7 +97,7 @@ def display_chat_history():
|
|
75 |
if data["role"] == "user":
|
76 |
st.markdown(f"<div class='stChatMessage' data-testid='stChatMessage-user'>π€ <strong>You:</strong> {data['content']}</div>", unsafe_allow_html=True)
|
77 |
else:
|
78 |
-
st.markdown(f"<div class='stChatMessage' data-testid='stChatMessage-assistant'>{assistant_icon_html} <strong>
|
79 |
|
80 |
# π Main Chat UI
|
81 |
input_col, clear_col = st.columns([9, 1])
|
@@ -119,5 +141,3 @@ if user_input:
|
|
119 |
st.rerun()
|
120 |
|
121 |
|
122 |
-
|
123 |
-
|
|
|
1 |
+
import streamlit as st
|
2 |
from openai import OpenAI
|
3 |
import time
|
4 |
import os
|
5 |
import uuid
|
6 |
import firebase_admin
|
7 |
from firebase_admin import credentials, firestore
|
8 |
+
# ------------------ Authentication ------------------
|
9 |
+
VALID_USERS = {
|
10 |
+
"[email protected]": "Pass.123",
|
11 |
+
}
|
12 |
+
|
13 |
+
def login():
|
14 |
+
st.title("π Login Required")
|
15 |
+
email = st.text_input("Email")
|
16 |
+
password = st.text_input("Password", type="password")
|
17 |
+
if st.button("Login"):
|
18 |
+
if VALID_USERS.get(email) == password:
|
19 |
+
st.session_state.authenticated = True
|
20 |
+
st.rerun()
|
21 |
+
else:
|
22 |
+
st.error("β Incorrect email or password.")
|
23 |
+
|
24 |
+
if "authenticated" not in st.session_state:
|
25 |
+
st.session_state.authenticated = False
|
26 |
+
|
27 |
+
if not st.session_state.authenticated:
|
28 |
+
login()
|
29 |
+
st.stop()
|
30 |
|
31 |
# π Firebase setup
|
32 |
if not firebase_admin._apps:
|
|
|
37 |
|
38 |
# π OpenAI setup
|
39 |
openai_key = os.getenv("openai_key")
|
40 |
+
assistant_id = os.getenv("ASSISTANT_ID")
|
41 |
client = OpenAI(api_key=openai_key)
|
42 |
|
43 |
# π Streamlit Config
|
|
|
48 |
st.session_state["user_id"] = str(uuid.uuid4())
|
49 |
user_id = st.session_state["user_id"]
|
50 |
|
51 |
+
# πΌοΈ LORTech Branding + Styling
|
52 |
st.markdown("""
|
53 |
<style>
|
54 |
.block-container {padding-top: 1rem; padding-bottom: 0rem;}
|
|
|
56 |
.stChatMessage { max-width: 85%; border-radius: 12px; padding: 8px; margin-bottom: 10px; }
|
57 |
.stChatMessage[data-testid="stChatMessage-user"] { background: #f0f0f0; color: #000000; }
|
58 |
.stChatMessage[data-testid="stChatMessage-assistant"] { background: #e3f2fd; color: #000000; }
|
59 |
+
.lt-logo { vertical-align: middle; }
|
60 |
</style>
|
61 |
""", unsafe_allow_html=True)
|
62 |
|
|
|
97 |
if data["role"] == "user":
|
98 |
st.markdown(f"<div class='stChatMessage' data-testid='stChatMessage-user'>π€ <strong>You:</strong> {data['content']}</div>", unsafe_allow_html=True)
|
99 |
else:
|
100 |
+
st.markdown(f"<div class='stChatMessage' data-testid='stChatMessage-assistant'>{assistant_icon_html} <strong>LeaseTracker Assistant:</strong> {data['content']}</div>", unsafe_allow_html=True)
|
101 |
|
102 |
# π Main Chat UI
|
103 |
input_col, clear_col = st.columns([9, 1])
|
|
|
141 |
st.rerun()
|
142 |
|
143 |
|
|
|
|