Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +22 -197
src/streamlit_app.py
CHANGED
|
@@ -1,222 +1,47 @@
|
|
| 1 |
import streamlit as st
|
|
|
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
-
import json
|
| 4 |
|
| 5 |
-
# Force
|
| 6 |
st.set_page_config(page_title="SparkHelix AI", page_icon="🧬", layout="wide")
|
| 7 |
|
| 8 |
-
# Hide standard Streamlit header
|
| 9 |
-
st.markdown("
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
# Initialize Session Logs
|
| 12 |
if "messages" not in st.session_state:
|
| 13 |
st.session_state.messages = [{"role": "assistant", "content": "Hello! I am SparkHelix. How can I help you discover or build today?"}]
|
| 14 |
|
| 15 |
# =====================================================================
|
| 16 |
-
# 🎨
|
| 17 |
# =====================================================================
|
| 18 |
-
copilot_html = f"""
|
| 19 |
-
<style>
|
| 20 |
-
@import url('https://fonts.googleapis.com/css2?family=Segoe+UI:wght@400;500;600&display=swap');
|
| 21 |
-
|
| 22 |
-
body {{
|
| 23 |
-
background-color: #030508 !important;
|
| 24 |
-
font-family: 'Segoe UI', system-ui, sans-serif;
|
| 25 |
-
color: #f3f4f6;
|
| 26 |
-
margin: 0;
|
| 27 |
-
padding: 0;
|
| 28 |
-
}}
|
| 29 |
-
|
| 30 |
-
/* Layout Framework */
|
| 31 |
-
.copilot-container {{
|
| 32 |
-
display: flex;
|
| 33 |
-
height: 100vh;
|
| 34 |
-
width: 100vw;
|
| 35 |
-
background-color: #0b0d12;
|
| 36 |
-
}}
|
| 37 |
-
|
| 38 |
-
/* Sleek Left Sidebar */
|
| 39 |
-
.copilot-sidebar {{
|
| 40 |
-
width: 260px;
|
| 41 |
-
background-color: #0d1017;
|
| 42 |
-
border-right: 1px solid #1e2530;
|
| 43 |
-
display: flex;
|
| 44 |
-
flex-direction: column;
|
| 45 |
-
padding: 20px;
|
| 46 |
-
}}
|
| 47 |
-
|
| 48 |
-
.brand-title {{
|
| 49 |
-
font-size: 18px;
|
| 50 |
-
font-weight: 600;
|
| 51 |
-
display: flex;
|
| 52 |
-
align-items: center;
|
| 53 |
-
gap: 10px;
|
| 54 |
-
margin-bottom: 30px;
|
| 55 |
-
color: #ffffff;
|
| 56 |
-
}}
|
| 57 |
-
|
| 58 |
-
.new-chat-btn {{
|
| 59 |
-
background: linear-gradient(90deg, #4f46e5 0%, #7c3aed 100%);
|
| 60 |
-
border: none;
|
| 61 |
-
color: white;
|
| 62 |
-
padding: 12px;
|
| 63 |
-
border-radius: 10px;
|
| 64 |
-
font-weight: 500;
|
| 65 |
-
cursor: pointer;
|
| 66 |
-
text-align: center;
|
| 67 |
-
margin-bottom: 20px;
|
| 68 |
-
box-shadow: 0 4px 12px rgba(79, 70, 229, 0.2);
|
| 69 |
-
}}
|
| 70 |
-
|
| 71 |
-
/* Center Chat Stream */
|
| 72 |
-
.chat-workspace {{
|
| 73 |
-
flex: 1;
|
| 74 |
-
display: flex;
|
| 75 |
-
flex-direction: column;
|
| 76 |
-
height: 100%;
|
| 77 |
-
background-color: #0b0d12;
|
| 78 |
-
position: relative;
|
| 79 |
-
}}
|
| 80 |
-
|
| 81 |
-
.chat-header {{
|
| 82 |
-
padding: 20px 40px;
|
| 83 |
-
border-bottom: 1px solid #1e2530;
|
| 84 |
-
font-size: 16px;
|
| 85 |
-
font-weight: 500;
|
| 86 |
-
color: #9ca3af;
|
| 87 |
-
}}
|
| 88 |
-
|
| 89 |
-
.message-stream {{
|
| 90 |
-
flex: 1;
|
| 91 |
-
overflow-y: auto;
|
| 92 |
-
padding: 40px 10% 120px 10%;
|
| 93 |
-
display: flex;
|
| 94 |
-
flex-direction: column;
|
| 95 |
-
gap: 24px;
|
| 96 |
-
}}
|
| 97 |
-
|
| 98 |
-
/* Chat Bubble Speccing */
|
| 99 |
-
.chat-row {{
|
| 100 |
-
display: flex;
|
| 101 |
-
gap: 16px;
|
| 102 |
-
max-width: 800px;
|
| 103 |
-
width: 100%;
|
| 104 |
-
align-self: center;
|
| 105 |
-
}}
|
| 106 |
-
|
| 107 |
-
.chat-row.user-row {{
|
| 108 |
-
justify-content: flex-end;
|
| 109 |
-
}}
|
| 110 |
-
|
| 111 |
-
.avatar {{
|
| 112 |
-
width: 32px;
|
| 113 |
-
height: 32px;
|
| 114 |
-
border-radius: 50%;
|
| 115 |
-
display: flex;
|
| 116 |
-
align-items: center;
|
| 117 |
-
justify-content: center;
|
| 118 |
-
font-weight: 600;
|
| 119 |
-
font-size: 14px;
|
| 120 |
-
}}
|
| 121 |
-
|
| 122 |
-
.avatar.ai-avatar {{
|
| 123 |
-
background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
|
| 124 |
-
color: white;
|
| 125 |
-
}}
|
| 126 |
-
|
| 127 |
-
.avatar.user-avatar {{
|
| 128 |
-
background-color: #374151;
|
| 129 |
-
color: #f3f4f6;
|
| 130 |
-
}}
|
| 131 |
-
|
| 132 |
-
.bubble {{
|
| 133 |
-
padding: 14px 18px;
|
| 134 |
-
border-radius: 16px;
|
| 135 |
-
font-size: 15px;
|
| 136 |
-
line-height: 1.5;
|
| 137 |
-
max-width: 85%;
|
| 138 |
-
}}
|
| 139 |
-
|
| 140 |
-
.ai-bubble {{
|
| 141 |
-
background-color: transparent;
|
| 142 |
-
color: #e5e7eb;
|
| 143 |
-
}}
|
| 144 |
-
|
| 145 |
-
.user-bubble {{
|
| 146 |
-
background-color: #1e2533;
|
| 147 |
-
color: #ffffff;
|
| 148 |
-
border: 1px solid #2d3748;
|
| 149 |
-
border-radius: 16px 16px 4px 16px;
|
| 150 |
-
}}
|
| 151 |
-
</style>
|
| 152 |
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
<div style="color: #4b5563; font-size: 12px; margin-top: auto;">System Status: Connected</div>
|
| 158 |
-
</div>
|
| 159 |
-
|
| 160 |
-
<div class="chat-workspace">
|
| 161 |
-
<div class="chat-header">SparkHelix Workspace // Chat Context</div>
|
| 162 |
-
<div class="message-stream">
|
| 163 |
-
"""
|
| 164 |
|
| 165 |
-
#
|
| 166 |
for msg in st.session_state.messages:
|
| 167 |
if msg["role"] == "assistant":
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
<div class="avatar ai-avatar">🧬</div>
|
| 171 |
-
<div class="bubble ai-bubble">{msg['content']}</div>
|
| 172 |
-
</div>
|
| 173 |
-
"""
|
| 174 |
else:
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
<div class="bubble user-bubble">{msg['content']}</div>
|
| 178 |
-
<div class="avatar user-avatar">U</div>
|
| 179 |
-
</div>
|
| 180 |
-
"""
|
| 181 |
-
|
| 182 |
-
# Close the wrapper div
|
| 183 |
-
copilot_html += "</div></div></div>"
|
| 184 |
-
|
| 185 |
-
# Render the layout instantly
|
| 186 |
-
st.markdown(copilot_html, unsafe_allow_html=True)
|
| 187 |
-
|
| 188 |
-
# =====================================================================
|
| 189 |
-
# 📥 FLOATING BOTTOM INPUT CONTROLLER (HACKED INTO POSITION)
|
| 190 |
-
# =====================================================================
|
| 191 |
-
st.markdown("""
|
| 192 |
-
<style>
|
| 193 |
-
/* Pin the interactive chat input directly over the UI backdrop */
|
| 194 |
-
div[data-testid="stChatInput"] {
|
| 195 |
-
position: fixed !important;
|
| 196 |
-
bottom: 30px !important;
|
| 197 |
-
left: 53% !important;
|
| 198 |
-
transform: translateX(-50%) !important;
|
| 199 |
-
width: 55% !important;
|
| 200 |
-
max-width: 750px !important;
|
| 201 |
-
z-index: 999999 !important;
|
| 202 |
-
background-color: #151b26 !important;
|
| 203 |
-
border: 1px solid #2a3447 !important;
|
| 204 |
-
border-radius: 24px !important;
|
| 205 |
-
box-shadow: 0 10px 30px rgba(0,0,0,0.5) !important;
|
| 206 |
-
}
|
| 207 |
-
textarea {
|
| 208 |
-
color: #ffffff !important;
|
| 209 |
-
}
|
| 210 |
-
</style>
|
| 211 |
-
""", unsafe_allow_html=True)
|
| 212 |
|
|
|
|
| 213 |
user_input = st.chat_input("Ask SparkHelix anything...")
|
| 214 |
|
| 215 |
if user_input:
|
| 216 |
-
# Save input log
|
| 217 |
st.session_state.messages.append({"role": "user", "content": user_input})
|
| 218 |
|
| 219 |
-
# Process AI request using the correct conversational wrapper
|
| 220 |
try:
|
| 221 |
client = InferenceClient()
|
| 222 |
response = client.chat.completions.create(
|
|
@@ -228,6 +53,6 @@ if user_input:
|
|
| 228 |
ai_reply = response.choices[0].message.content
|
| 229 |
st.session_state.messages.append({"role": "assistant", "content": ai_reply})
|
| 230 |
except Exception as e:
|
| 231 |
-
st.session_state.messages.append({"role": "assistant", "content": f"System Alert:
|
| 232 |
|
| 233 |
st.rerun()
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import streamlit.components.v1 as components
|
| 3 |
from huggingface_hub import InferenceClient
|
|
|
|
| 4 |
|
| 5 |
+
# Force layout optimization
|
| 6 |
st.set_page_config(page_title="SparkHelix AI", page_icon="🧬", layout="wide")
|
| 7 |
|
| 8 |
+
# Hide standard Streamlit header frameworks
|
| 9 |
+
st.markdown("""
|
| 10 |
+
<style>
|
| 11 |
+
#MainMenu, footer, header {visibility: hidden;}
|
| 12 |
+
div.block-container {padding: 0rem !important; max-width: 100% !important;}
|
| 13 |
+
[data-testid="stSidebar"] {background-color: #0d1017 !important;}
|
| 14 |
+
</style>
|
| 15 |
+
""", unsafe_allow_html=True)
|
| 16 |
|
| 17 |
# Initialize Session Logs
|
| 18 |
if "messages" not in st.session_state:
|
| 19 |
st.session_state.messages = [{"role": "assistant", "content": "Hello! I am SparkHelix. How can I help you discover or build today?"}]
|
| 20 |
|
| 21 |
# =====================================================================
|
| 22 |
+
# 🎨 STREAMLINED COPILOT ARCHITECTURE
|
| 23 |
# =====================================================================
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
+
# Build clean container styles using native markdown components
|
| 26 |
+
st.title("🧬 SparkHelix Copilot")
|
| 27 |
+
st.caption("Next-gen companion agent connected to web engines and inference clusters.")
|
| 28 |
+
st.markdown("---")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
+
# Render elements using clear blocks
|
| 31 |
for msg in st.session_state.messages:
|
| 32 |
if msg["role"] == "assistant":
|
| 33 |
+
with st.chat_message("assistant", avatar="🧬"):
|
| 34 |
+
st.markdown(f"**SparkHelix**\n\n{msg['content']}")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
else:
|
| 36 |
+
with st.chat_message("user"):
|
| 37 |
+
st.markdown(msg['content'])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
+
# Pinned Interactive Chat Box
|
| 40 |
user_input = st.chat_input("Ask SparkHelix anything...")
|
| 41 |
|
| 42 |
if user_input:
|
|
|
|
| 43 |
st.session_state.messages.append({"role": "user", "content": user_input})
|
| 44 |
|
|
|
|
| 45 |
try:
|
| 46 |
client = InferenceClient()
|
| 47 |
response = client.chat.completions.create(
|
|
|
|
| 53 |
ai_reply = response.choices[0].message.content
|
| 54 |
st.session_state.messages.append({"role": "assistant", "content": ai_reply})
|
| 55 |
except Exception as e:
|
| 56 |
+
st.session_state.messages.append({"role": "assistant", "content": f"System Alert: Routing congestion. Details: {e}"})
|
| 57 |
|
| 58 |
st.rerun()
|