Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -18,6 +18,10 @@ st.set_page_config(
|
|
| 18 |
initial_sidebar_state="expanded"
|
| 19 |
)
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
# Define personality questions - reduced to general ones
|
| 22 |
PERSONALITY_QUESTIONS = [
|
| 23 |
"What is [name]'s personality like?",
|
|
@@ -27,11 +31,266 @@ PERSONALITY_QUESTIONS = [
|
|
| 27 |
"Tell me about [name]"
|
| 28 |
]
|
| 29 |
|
| 30 |
-
# Enhanced CSS styling
|
| 31 |
-
|
|
|
|
|
|
|
| 32 |
<style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
/* NEW CHAT BUTTON - Black background */
|
| 69 |
.stButton > button[kind="primary"] {
|
| 70 |
background-color: #000000 !important;
|
|
@@ -146,7 +425,10 @@ st.markdown("""
|
|
| 146 |
color: #4a148c;
|
| 147 |
}
|
| 148 |
</style>
|
| 149 |
-
"""
|
|
|
|
|
|
|
|
|
|
| 150 |
|
| 151 |
# File paths
|
| 152 |
HISTORY_FILE = "rag_chat_history.json"
|
|
@@ -765,9 +1047,18 @@ if "session_id" not in st.session_state:
|
|
| 765 |
# Initialize RAG system
|
| 766 |
rag_system = initialize_rag_system()
|
| 767 |
|
| 768 |
-
# Header
|
| 769 |
-
st.
|
| 770 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 771 |
|
| 772 |
# Sidebar
|
| 773 |
with st.sidebar:
|
|
@@ -778,6 +1069,17 @@ with st.sidebar:
|
|
| 778 |
|
| 779 |
st.divider()
|
| 780 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 781 |
# Personality Questions Section
|
| 782 |
st.header("π Personality Questions")
|
| 783 |
|
|
@@ -1261,4 +1563,5 @@ if rag_system and rag_system.model:
|
|
| 1261 |
token_mode = "π₯ Unlimited" if unlimited_tokens else "π° Conservative"
|
| 1262 |
github_status = check_github_status()
|
| 1263 |
github_icon = "π’" if github_status["status"] == "connected" else "π΄"
|
| 1264 |
-
|
|
|
|
|
|
| 18 |
initial_sidebar_state="expanded"
|
| 19 |
)
|
| 20 |
|
| 21 |
+
# Initialize dark mode state
|
| 22 |
+
if 'dark_mode' not in st.session_state:
|
| 23 |
+
st.session_state.dark_mode = False
|
| 24 |
+
|
| 25 |
# Define personality questions - reduced to general ones
|
| 26 |
PERSONALITY_QUESTIONS = [
|
| 27 |
"What is [name]'s personality like?",
|
|
|
|
| 31 |
"Tell me about [name]"
|
| 32 |
]
|
| 33 |
|
| 34 |
+
# Enhanced CSS styling with dark mode support
|
| 35 |
+
def get_css_styles():
|
| 36 |
+
if st.session_state.dark_mode:
|
| 37 |
+
return """
|
| 38 |
<style>
|
| 39 |
+
/* Dark Mode Styles */
|
| 40 |
+
.stApp {
|
| 41 |
+
background: #0e1117;
|
| 42 |
+
color: #fafafa;
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
.main .block-container {
|
| 46 |
+
max-width: 900px;
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
#MainMenu {visibility: hidden;}
|
| 50 |
+
footer {visibility: hidden;}
|
| 51 |
+
header {visibility: hidden;}
|
| 52 |
+
.stDeployButton {display: none;}
|
| 53 |
+
|
| 54 |
+
/* Sidebar dark mode */
|
| 55 |
+
.css-1d391kg {
|
| 56 |
+
background-color: #1e1e1e !important;
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
.css-1cypcdb {
|
| 60 |
+
background-color: #1e1e1e !important;
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
/* Chat messages dark mode */
|
| 64 |
+
.stChatMessage {
|
| 65 |
+
background-color: #262730 !important;
|
| 66 |
+
border: 1px solid #404040 !important;
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
/* Input fields dark mode */
|
| 70 |
+
.stTextInput > div > div > input {
|
| 71 |
+
background-color: #262730 !important;
|
| 72 |
+
color: #fafafa !important;
|
| 73 |
+
border-color: #404040 !important;
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
.stTextArea > div > div > textarea {
|
| 77 |
+
background-color: #262730 !important;
|
| 78 |
+
color: #fafafa !important;
|
| 79 |
+
border-color: #404040 !important;
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
.model-id {
|
| 83 |
+
color: #4ade80;
|
| 84 |
+
font-family: monospace;
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
.model-attribution {
|
| 88 |
+
color: #4ade80;
|
| 89 |
+
font-size: 0.8em;
|
| 90 |
+
font-style: italic;
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
.rag-attribution {
|
| 94 |
+
color: #a78bfa;
|
| 95 |
+
font-size: 0.8em;
|
| 96 |
+
font-style: italic;
|
| 97 |
+
background: #1f2937;
|
| 98 |
+
padding: 8px;
|
| 99 |
+
border-radius: 4px;
|
| 100 |
+
border-left: 3px solid #a78bfa;
|
| 101 |
+
margin-top: 8px;
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
/* Dark mode toggle button */
|
| 105 |
+
.dark-mode-toggle {
|
| 106 |
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
| 107 |
+
color: white;
|
| 108 |
+
padding: 8px 16px;
|
| 109 |
+
margin: 4px 0;
|
| 110 |
+
border-radius: 8px;
|
| 111 |
+
border: none;
|
| 112 |
+
cursor: pointer;
|
| 113 |
+
transition: all 0.3s ease;
|
| 114 |
+
font-size: 0.9em;
|
| 115 |
+
width: 100%;
|
| 116 |
+
text-align: center;
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
.dark-mode-toggle:hover {
|
| 120 |
+
transform: translateY(-1px);
|
| 121 |
+
box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
/* NEW CHAT BUTTON - Black background for dark mode */
|
| 125 |
+
.stButton > button[kind="primary"] {
|
| 126 |
+
background-color: #1f2937 !important;
|
| 127 |
+
border-color: #374151 !important;
|
| 128 |
+
color: #fafafa !important;
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
.stButton > button[kind="primary"]:hover {
|
| 132 |
+
background-color: #374151 !important;
|
| 133 |
+
border-color: #4b5563 !important;
|
| 134 |
+
color: #fafafa !important;
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
/* Regular buttons dark mode */
|
| 138 |
+
.stButton > button {
|
| 139 |
+
background-color: #374151 !important;
|
| 140 |
+
border-color: #4b5563 !important;
|
| 141 |
+
color: #fafafa !important;
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
.stButton > button:hover {
|
| 145 |
+
background-color: #4b5563 !important;
|
| 146 |
+
border-color: #6b7280 !important;
|
| 147 |
+
color: #fafafa !important;
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
/* Personality Questions Styling Dark Mode */
|
| 151 |
+
.personality-question {
|
| 152 |
+
background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
|
| 153 |
+
color: white;
|
| 154 |
+
padding: 8px 12px;
|
| 155 |
+
margin: 4px 0;
|
| 156 |
+
border-radius: 8px;
|
| 157 |
+
border: none;
|
| 158 |
+
cursor: pointer;
|
| 159 |
+
transition: all 0.3s ease;
|
| 160 |
+
font-size: 0.85em;
|
| 161 |
+
width: 100%;
|
| 162 |
+
text-align: left;
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
.personality-question:hover {
|
| 166 |
+
transform: translateY(-2px);
|
| 167 |
+
box-shadow: 0 4px 12px rgba(79, 70, 229, 0.4);
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
.personality-section {
|
| 171 |
+
background: #1f2937;
|
| 172 |
+
color: #e5e7eb;
|
| 173 |
+
padding: 12px;
|
| 174 |
+
border-radius: 8px;
|
| 175 |
+
border-left: 4px solid #4f46e5;
|
| 176 |
+
margin: 10px 0;
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
/* Chat history styling dark mode */
|
| 180 |
+
.chat-history-item {
|
| 181 |
+
padding: 8px 12px;
|
| 182 |
+
margin: 4px 0;
|
| 183 |
+
border-radius: 8px;
|
| 184 |
+
border: 1px solid #374151;
|
| 185 |
+
background: #1f2937;
|
| 186 |
+
color: #e5e7eb;
|
| 187 |
+
cursor: pointer;
|
| 188 |
+
transition: all 0.2s;
|
| 189 |
+
}
|
| 190 |
+
|
| 191 |
+
.chat-history-item:hover {
|
| 192 |
+
background: #374151;
|
| 193 |
+
border-color: #4ade80;
|
| 194 |
+
}
|
| 195 |
+
|
| 196 |
+
.document-status {
|
| 197 |
+
background: #1e3a8a;
|
| 198 |
+
color: #bfdbfe;
|
| 199 |
+
padding: 10px;
|
| 200 |
+
border-radius: 8px;
|
| 201 |
+
border-left: 4px solid #3b82f6;
|
| 202 |
+
margin: 10px 0;
|
| 203 |
+
}
|
| 204 |
+
|
| 205 |
+
.github-status {
|
| 206 |
+
background: #581c87;
|
| 207 |
+
color: #e9d5ff;
|
| 208 |
+
padding: 10px;
|
| 209 |
+
border-radius: 8px;
|
| 210 |
+
border-left: 4px solid #a78bfa;
|
| 211 |
+
margin: 10px 0;
|
| 212 |
+
}
|
| 213 |
+
|
| 214 |
+
.rag-stats {
|
| 215 |
+
background: #581c87;
|
| 216 |
+
color: #e9d5ff;
|
| 217 |
+
padding: 8px;
|
| 218 |
+
border-radius: 6px;
|
| 219 |
+
font-size: 0.85em;
|
| 220 |
+
}
|
| 221 |
+
|
| 222 |
+
/* Expander dark mode */
|
| 223 |
+
.streamlit-expanderHeader {
|
| 224 |
+
background-color: #1f2937 !important;
|
| 225 |
+
color: #fafafa !important;
|
| 226 |
+
}
|
| 227 |
+
|
| 228 |
+
.streamlit-expanderContent {
|
| 229 |
+
background-color: #111827 !important;
|
| 230 |
+
color: #fafafa !important;
|
| 231 |
+
}
|
| 232 |
+
|
| 233 |
+
/* Checkbox dark mode */
|
| 234 |
+
.stCheckbox {
|
| 235 |
+
color: #fafafa !important;
|
| 236 |
+
}
|
| 237 |
+
|
| 238 |
+
/* Select box dark mode */
|
| 239 |
+
.stSelectbox > div > div {
|
| 240 |
+
background-color: #262730 !important;
|
| 241 |
+
color: #fafafa !important;
|
| 242 |
+
}
|
| 243 |
+
|
| 244 |
+
/* File uploader dark mode */
|
| 245 |
+
.stFileUploader {
|
| 246 |
+
background-color: #1f2937 !important;
|
| 247 |
+
border-color: #374151 !important;
|
| 248 |
+
}
|
| 249 |
+
|
| 250 |
+
/* Progress bar dark mode */
|
| 251 |
+
.stProgress .st-bo {
|
| 252 |
+
background-color: #374151 !important;
|
| 253 |
+
}
|
| 254 |
+
|
| 255 |
+
/* Success/Error/Warning messages dark mode */
|
| 256 |
+
.stSuccess {
|
| 257 |
+
background-color: #064e3b !important;
|
| 258 |
+
color: #6ee7b7 !important;
|
| 259 |
+
}
|
| 260 |
+
|
| 261 |
+
.stError {
|
| 262 |
+
background-color: #7f1d1d !important;
|
| 263 |
+
color: #fca5a5 !important;
|
| 264 |
+
}
|
| 265 |
+
|
| 266 |
+
.stWarning {
|
| 267 |
+
background-color: #78350f !important;
|
| 268 |
+
color: #fcd34d !important;
|
| 269 |
+
}
|
| 270 |
+
|
| 271 |
+
.stInfo {
|
| 272 |
+
background-color: #1e3a8a !important;
|
| 273 |
+
color: #93c5fd !important;
|
| 274 |
+
}
|
| 275 |
+
|
| 276 |
+
/* Caption text dark mode */
|
| 277 |
+
.caption {
|
| 278 |
+
color: #9ca3af !important;
|
| 279 |
+
}
|
| 280 |
+
|
| 281 |
+
/* Divider dark mode */
|
| 282 |
+
hr {
|
| 283 |
+
border-color: #374151 !important;
|
| 284 |
+
}
|
| 285 |
+
</style>
|
| 286 |
+
"""
|
| 287 |
+
else:
|
| 288 |
+
return """
|
| 289 |
+
<style>
|
| 290 |
+
/* Light Mode Styles */
|
| 291 |
.stApp {
|
| 292 |
background: white;
|
| 293 |
+
color: #000000;
|
| 294 |
}
|
| 295 |
|
| 296 |
.main .block-container {
|
|
|
|
| 324 |
margin-top: 8px;
|
| 325 |
}
|
| 326 |
|
| 327 |
+
/* Light mode toggle button */
|
| 328 |
+
.dark-mode-toggle {
|
| 329 |
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
| 330 |
+
color: white;
|
| 331 |
+
padding: 8px 16px;
|
| 332 |
+
margin: 4px 0;
|
| 333 |
+
border-radius: 8px;
|
| 334 |
+
border: none;
|
| 335 |
+
cursor: pointer;
|
| 336 |
+
transition: all 0.3s ease;
|
| 337 |
+
font-size: 0.9em;
|
| 338 |
+
width: 100%;
|
| 339 |
+
text-align: center;
|
| 340 |
+
}
|
| 341 |
+
|
| 342 |
+
.dark-mode-toggle:hover {
|
| 343 |
+
transform: translateY(-1px);
|
| 344 |
+
box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
|
| 345 |
+
}
|
| 346 |
+
|
| 347 |
/* NEW CHAT BUTTON - Black background */
|
| 348 |
.stButton > button[kind="primary"] {
|
| 349 |
background-color: #000000 !important;
|
|
|
|
| 425 |
color: #4a148c;
|
| 426 |
}
|
| 427 |
</style>
|
| 428 |
+
"""
|
| 429 |
+
|
| 430 |
+
# Apply CSS styles
|
| 431 |
+
st.markdown(get_css_styles(), unsafe_allow_html=True)
|
| 432 |
|
| 433 |
# File paths
|
| 434 |
HISTORY_FILE = "rag_chat_history.json"
|
|
|
|
| 1047 |
# Initialize RAG system
|
| 1048 |
rag_system = initialize_rag_system()
|
| 1049 |
|
| 1050 |
+
# Header with dark mode toggle
|
| 1051 |
+
col1, col2 = st.columns([4, 1])
|
| 1052 |
+
with col1:
|
| 1053 |
+
st.title("RAG Chat Flow β")
|
| 1054 |
+
st.caption("Ask questions about your documents with AI-powered retrieval")
|
| 1055 |
+
|
| 1056 |
+
with col2:
|
| 1057 |
+
# Dark mode toggle button
|
| 1058 |
+
mode_text = "π Light" if st.session_state.dark_mode else "π Dark"
|
| 1059 |
+
if st.button(mode_text, use_container_width=True):
|
| 1060 |
+
st.session_state.dark_mode = not st.session_state.dark_mode
|
| 1061 |
+
st.rerun()
|
| 1062 |
|
| 1063 |
# Sidebar
|
| 1064 |
with st.sidebar:
|
|
|
|
| 1069 |
|
| 1070 |
st.divider()
|
| 1071 |
|
| 1072 |
+
# Dark Mode Toggle in Sidebar too
|
| 1073 |
+
st.header("π¨ Theme")
|
| 1074 |
+
theme_status = "Dark Mode β¨" if st.session_state.dark_mode else "Light Mode βοΈ"
|
| 1075 |
+
if st.button(f"π Switch to {'Light' if st.session_state.dark_mode else 'Dark'} Mode", use_container_width=True):
|
| 1076 |
+
st.session_state.dark_mode = not st.session_state.dark_mode
|
| 1077 |
+
st.rerun()
|
| 1078 |
+
|
| 1079 |
+
st.info(f"Current: {theme_status}")
|
| 1080 |
+
|
| 1081 |
+
st.divider()
|
| 1082 |
+
|
| 1083 |
# Personality Questions Section
|
| 1084 |
st.header("π Personality Questions")
|
| 1085 |
|
|
|
|
| 1563 |
token_mode = "π₯ Unlimited" if unlimited_tokens else "π° Conservative"
|
| 1564 |
github_status = check_github_status()
|
| 1565 |
github_icon = "π’" if github_status["status"] == "connected" else "π΄"
|
| 1566 |
+
theme_icon = "π" if st.session_state.dark_mode else "βοΈ"
|
| 1567 |
+
st.caption(f"π Knowledge Base: {doc_count} indexed chunks | π RAG System Active | {token_mode} Token Mode | {github_icon} GitHub {github_status['status'].title()} | {theme_icon} {theme_status}")
|