Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -42,30 +42,41 @@ assistant_id = os.getenv("ASSISTANT_ID")
|
|
| 42 |
client = OpenAI(api_key=openai_key)
|
| 43 |
|
| 44 |
# π Streamlit Config
|
| 45 |
-
st.set_page_config(page_title="
|
| 46 |
|
| 47 |
# π― Session + User ID
|
| 48 |
if "user_id" not in st.session_state:
|
| 49 |
st.session_state["user_id"] = str(uuid.uuid4())
|
| 50 |
user_id = st.session_state["user_id"]
|
| 51 |
|
| 52 |
-
# πΌοΈ
|
| 53 |
st.markdown("""
|
| 54 |
<style>
|
| 55 |
.block-container {padding-top: 1rem; padding-bottom: 0rem;}
|
| 56 |
header {visibility: hidden;}
|
| 57 |
-
.stChatMessage { max-width: 85%; border-radius: 12px; padding:
|
| 58 |
-
.stChatMessage[data-testid="stChatMessage-user"] {
|
| 59 |
-
|
| 60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
</style>
|
| 62 |
""", unsafe_allow_html=True)
|
| 63 |
|
| 64 |
st.markdown("""
|
| 65 |
<div style='text-align: center; margin-top: 20px; margin-bottom: -10px;'>
|
| 66 |
<span style='display: inline-flex; align-items: center; gap: 8px;'>
|
| 67 |
-
<
|
| 68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
</span>
|
| 70 |
</div>
|
| 71 |
""", unsafe_allow_html=True)
|
|
@@ -92,13 +103,12 @@ def save_message(role, content):
|
|
| 92 |
# π¬ Display chat history
|
| 93 |
def display_chat_history():
|
| 94 |
messages = db.collection("users").document(user_id).collection("messages").order_by("timestamp").stream()
|
| 95 |
-
assistant_icon_html = "<img src='https://lortechnologies.com/wp-content/uploads/2023/03/LOR-Online-Logo.svg' width='20' style='vertical-align:middle;'/>"
|
| 96 |
for msg in list(messages)[::-1]:
|
| 97 |
data = msg.to_dict()
|
| 98 |
if data["role"] == "user":
|
| 99 |
st.markdown(f"<div class='stChatMessage' data-testid='stChatMessage-user'>π€ <strong>You:</strong> {data['content']}</div>", unsafe_allow_html=True)
|
| 100 |
else:
|
| 101 |
-
st.markdown(f"<div class='stChatMessage' data-testid='stChatMessage-assistant'
|
| 102 |
|
| 103 |
# π Main Chat UI
|
| 104 |
input_col, clear_col = st.columns([9, 1])
|
|
@@ -121,7 +131,6 @@ thread_id = get_or_create_thread_id()
|
|
| 121 |
display_chat_history()
|
| 122 |
|
| 123 |
if user_input:
|
| 124 |
-
# Send user message to OpenAI thread
|
| 125 |
client.beta.threads.messages.create(thread_id=thread_id, role="user", content=user_input)
|
| 126 |
save_message("user", user_input)
|
| 127 |
|
|
@@ -139,4 +148,4 @@ if user_input:
|
|
| 139 |
|
| 140 |
save_message("assistant", assistant_message)
|
| 141 |
time.sleep(0.5)
|
| 142 |
-
st.rerun()
|
|
|
|
| 42 |
client = OpenAI(api_key=openai_key)
|
| 43 |
|
| 44 |
# π Streamlit Config
|
| 45 |
+
st.set_page_config(page_title="Motus AI Assistant", layout="wide")
|
| 46 |
|
| 47 |
# π― Session + User ID
|
| 48 |
if "user_id" not in st.session_state:
|
| 49 |
st.session_state["user_id"] = str(uuid.uuid4())
|
| 50 |
user_id = st.session_state["user_id"]
|
| 51 |
|
| 52 |
+
# πΌοΈ Motus Branding + Styling
|
| 53 |
st.markdown("""
|
| 54 |
<style>
|
| 55 |
.block-container {padding-top: 1rem; padding-bottom: 0rem;}
|
| 56 |
header {visibility: hidden;}
|
| 57 |
+
.stChatMessage { max-width: 85%; border-radius: 12px; padding: 10px; margin-bottom: 12px; }
|
| 58 |
+
.stChatMessage[data-testid="stChatMessage-user"] {
|
| 59 |
+
background: #f4f4f4; color: #000000;
|
| 60 |
+
}
|
| 61 |
+
.stChatMessage[data-testid="stChatMessage-assistant"] {
|
| 62 |
+
background: #013D52; color: #ffffff;
|
| 63 |
+
}
|
| 64 |
+
.stChatMessage strong { color: #E2003C; }
|
| 65 |
</style>
|
| 66 |
""", unsafe_allow_html=True)
|
| 67 |
|
| 68 |
st.markdown("""
|
| 69 |
<div style='text-align: center; margin-top: 20px; margin-bottom: -10px;'>
|
| 70 |
<span style='display: inline-flex; align-items: center; gap: 8px;'>
|
| 71 |
+
<svg xmlns="http://www.w3.org/2000/svg" width="160" height="50" viewBox="0 0 173.457 54.497">
|
| 72 |
+
<g id="g-motus">
|
| 73 |
+
<path d="M41.31,87.813A13.457,13.457,0,1,1,54.767,101.27..." fill="#013d52"></path>
|
| 74 |
+
</g>
|
| 75 |
+
<g id="g-icon">
|
| 76 |
+
<path d="M463.17,17.088,439,37.37,455.636,0l9.321,12.3L469.314.641l8.131,10.734L459.291,27.47Z" transform="translate(-303.988)" fill="#E2003C"></path>
|
| 77 |
+
</g>
|
| 78 |
+
</svg>
|
| 79 |
+
<span style='font-size: 12px; color: gray;'>Powered by Motus Holdings</span>
|
| 80 |
</span>
|
| 81 |
</div>
|
| 82 |
""", unsafe_allow_html=True)
|
|
|
|
| 103 |
# π¬ Display chat history
|
| 104 |
def display_chat_history():
|
| 105 |
messages = db.collection("users").document(user_id).collection("messages").order_by("timestamp").stream()
|
|
|
|
| 106 |
for msg in list(messages)[::-1]:
|
| 107 |
data = msg.to_dict()
|
| 108 |
if data["role"] == "user":
|
| 109 |
st.markdown(f"<div class='stChatMessage' data-testid='stChatMessage-user'>π€ <strong>You:</strong> {data['content']}</div>", unsafe_allow_html=True)
|
| 110 |
else:
|
| 111 |
+
st.markdown(f"<div class='stChatMessage' data-testid='stChatMessage-assistant'><strong>Motus Assistant:</strong> {data['content']}</div>", unsafe_allow_html=True)
|
| 112 |
|
| 113 |
# π Main Chat UI
|
| 114 |
input_col, clear_col = st.columns([9, 1])
|
|
|
|
| 131 |
display_chat_history()
|
| 132 |
|
| 133 |
if user_input:
|
|
|
|
| 134 |
client.beta.threads.messages.create(thread_id=thread_id, role="user", content=user_input)
|
| 135 |
save_message("user", user_input)
|
| 136 |
|
|
|
|
| 148 |
|
| 149 |
save_message("assistant", assistant_message)
|
| 150 |
time.sleep(0.5)
|
| 151 |
+
st.rerun()
|