Spaces:
Build error
Build error
Update ui_utils.py
Browse files- ui_utils.py +177 -217
ui_utils.py
CHANGED
|
@@ -10,227 +10,187 @@ from chatbot_new import IntelligentRAGChatbot, InitializationError
|
|
| 10 |
BASE_PATH = os.path.dirname(os.path.abspath(__file__))
|
| 11 |
VECTOR_STORE_PATH = os.path.join(BASE_PATH, "vector_stores")
|
| 12 |
|
| 13 |
-
# Diese Funktionen müssen VOR der IntelligentRAGChatbot-Klasse platziert werden
|
| 14 |
def apply_enhanced_custom_css():
|
| 15 |
-
dark_mode = st.checkbox("Dark Mode") # Checkbox für Dark Mode
|
| 16 |
-
|
| 17 |
-
background_dark = "#0a1930"
|
| 18 |
-
background_light = "#f8fafc" # Hintergrund für Light Mode
|
| 19 |
-
text_primary_dark = "#f8fafc"
|
| 20 |
-
text_primary_light = "#1e293b" # Textfarbe für Light Mode
|
| 21 |
-
surface_dark = "rgba(30, 27, 75, 0.5)"
|
| 22 |
-
surface_light = "rgba(248, 250, 252, 0.5)" # Oberfläche für Light Mode
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
if dark_mode: # CSS basierend auf dem Dark Mode Status dynamisch erstellen
|
| 26 |
-
bg_color = background_dark
|
| 27 |
-
text_color = text_primary_dark
|
| 28 |
-
surface_color = surface_dark
|
| 29 |
-
else:
|
| 30 |
-
bg_color = background_light
|
| 31 |
-
text_color = text_primary_light
|
| 32 |
-
surface_color = surface_light
|
| 33 |
-
|
| 34 |
-
|
| 35 |
st.markdown(
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
::-webkit-scrollbar {
|
| 213 |
-
width: 8px;
|
| 214 |
-
height: 8px;
|
| 215 |
-
}
|
| 216 |
-
|
| 217 |
-
::-webkit-scrollbar-track {
|
| 218 |
-
background: rgba(10, 25, 48, 0.1);
|
| 219 |
-
}
|
| 220 |
-
|
| 221 |
-
::-webkit-scrollbar-thumb {
|
| 222 |
-
background: var(--primary);
|
| 223 |
-
border-radius: 4px;
|
| 224 |
-
}
|
| 225 |
-
|
| 226 |
-
::-webkit-scrollbar-thumb:hover {
|
| 227 |
-
background: var(--primary-light);
|
| 228 |
-
}
|
| 229 |
-
</style>
|
| 230 |
-
""",
|
| 231 |
-
unsafe_allow_html=True
|
| 232 |
)
|
| 233 |
|
|
|
|
| 234 |
def add_copy_button(text: str, key: str):
|
| 235 |
if st.button("📋 Kopieren", key=f"copy_{key}"):
|
| 236 |
st.session_state[f"copied_{key}"] = True
|
|
|
|
| 10 |
BASE_PATH = os.path.dirname(os.path.abspath(__file__))
|
| 11 |
VECTOR_STORE_PATH = os.path.join(BASE_PATH, "vector_stores")
|
| 12 |
|
|
|
|
| 13 |
def apply_enhanced_custom_css():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
st.markdown(
|
| 15 |
+
"""
|
| 16 |
+
<style>
|
| 17 |
+
@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700&display=swap');
|
| 18 |
+
/* Color Variables */
|
| 19 |
+
:root {
|
| 20 |
+
--primary: #06b6d4;
|
| 21 |
+
--primary-light: #22d3ee;
|
| 22 |
+
--primary-dark: #0891b2;
|
| 23 |
+
--background-dark: #0a1930;
|
| 24 |
+
--background-light: #1a1f3c;
|
| 25 |
+
--surface: rgba(30, 27, 75, 0.5);
|
| 26 |
+
--text-primary: #f8fafc;
|
| 27 |
+
--text-secondary: #cbd5e1;
|
| 28 |
+
}
|
| 29 |
+
/* Base Styles & Navigation Bar Fix */
|
| 30 |
+
.stApp {
|
| 31 |
+
background: linear-gradient(145deg, var(--background-dark) 0%, #164e63 100%) !important;
|
| 32 |
+
color: var(--text-primary);
|
| 33 |
+
font-family: 'Plus Jakarta Sans', sans-serif;
|
| 34 |
+
line-height: 1.7;
|
| 35 |
+
}
|
| 36 |
+
/* Remove default header */
|
| 37 |
+
header[data-testid="stHeader"] {
|
| 38 |
+
display: none;
|
| 39 |
+
}
|
| 40 |
+
/* Clean up sidebar */
|
| 41 |
+
section[data-testid="stSidebar"] {
|
| 42 |
+
background: linear-gradient(180deg, var(--background-dark) 0%, #164e63 100%) !important;
|
| 43 |
+
border-right: 1px solid rgba(6, 182, 212, 0.1);
|
| 44 |
+
}
|
| 45 |
+
.stSidebar > div:first-child {
|
| 46 |
+
padding-top: 2rem;
|
| 47 |
+
}
|
| 48 |
+
/* Typography */
|
| 49 |
+
h1 {
|
| 50 |
+
color: var(--text-primary);
|
| 51 |
+
text-align: center;
|
| 52 |
+
font-size: 2.5rem;
|
| 53 |
+
font-weight: 700;
|
| 54 |
+
margin-bottom: 2.5rem;
|
| 55 |
+
letter-spacing: -0.02em;
|
| 56 |
+
background: linear-gradient(135deg, #22d3ee 0%, #06b6d4 50%, #0891b2 100%);
|
| 57 |
+
-webkit-background-clip: text;
|
| 58 |
+
-webkit-text-fill-color: transparent;
|
| 59 |
+
}
|
| 60 |
+
/* Chat Messages */
|
| 61 |
+
.stChatMessage {
|
| 62 |
+
background: rgba(30, 27, 75, 0.3) !important;
|
| 63 |
+
backdrop-filter: blur(12px);
|
| 64 |
+
border: 1px solid rgba(6, 182, 212, 0.1);
|
| 65 |
+
border-radius: 16px;
|
| 66 |
+
padding: 1.5rem;
|
| 67 |
+
margin: 1.5rem 0;
|
| 68 |
+
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
|
| 69 |
+
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
| 70 |
+
}
|
| 71 |
+
/* User and Assistant Messages */
|
| 72 |
+
.stChatMessage[data-testid="user-message"],
|
| 73 |
+
.stChatMessage[data-testid="assistant-message"] {
|
| 74 |
+
color: #ffffff !important; /* Weiß */
|
| 75 |
+
}
|
| 76 |
+
/* Message Layout */
|
| 77 |
+
.stChatMessage[data-testid="user-message"] {
|
| 78 |
+
background: rgba(6, 182, 212, 0.1) !important;
|
| 79 |
+
margin-left: 12%;
|
| 80 |
+
margin-right: 2%;
|
| 81 |
+
border-left: 3px solid var(--primary);
|
| 82 |
+
}
|
| 83 |
+
.stChatMessage[data-testid="assistant-message"] {
|
| 84 |
+
background: rgba(10, 25, 48, 0.7) !important;
|
| 85 |
+
margin-right: 12%;
|
| 86 |
+
margin-left: 2%;
|
| 87 |
+
border-right: 3px solid var(--primary);
|
| 88 |
+
}
|
| 89 |
+
/* Enhanced Input Area */
|
| 90 |
+
.stChatInput {
|
| 91 |
+
background-color: transparent !important;
|
| 92 |
+
}
|
| 93 |
+
.stChatInput > div {
|
| 94 |
+
background-color: transparent !important;
|
| 95 |
+
}
|
| 96 |
+
div[data-testid="stChatInput"] {
|
| 97 |
+
background-color: transparent !important;
|
| 98 |
+
}
|
| 99 |
+
.stTextInput > div {
|
| 100 |
+
background-color: transparent !important;
|
| 101 |
+
}
|
| 102 |
+
div[data-testid="textInput"] {
|
| 103 |
+
background-color: transparent !important;
|
| 104 |
+
}
|
| 105 |
+
.stTextInput > div > div {
|
| 106 |
+
background-color: transparent !important;
|
| 107 |
+
}
|
| 108 |
+
.stTextInput > div > div > input {
|
| 109 |
+
background: rgba(10, 25, 48, 0.7) !important;
|
| 110 |
+
color: var(--text-primary);
|
| 111 |
+
border: 1px solid rgba(6, 182, 212, 0.3);
|
| 112 |
+
border-radius: 12px;
|
| 113 |
+
padding: 1rem 1.5rem;
|
| 114 |
+
font-size: 1rem;
|
| 115 |
+
font-weight: 500;
|
| 116 |
+
transition: all 0.2s ease;
|
| 117 |
+
margin-bottom: 1rem;
|
| 118 |
+
width: 100%;
|
| 119 |
+
}
|
| 120 |
+
.stTextInput > div > div > input:focus {
|
| 121 |
+
border-color: var(--primary);
|
| 122 |
+
box-shadow: 0 0 0 3px rgba(6, 182, 212, 0.15);
|
| 123 |
+
}
|
| 124 |
+
/* Chat Input Container Fix */
|
| 125 |
+
.stChatInputContainer {
|
| 126 |
+
background-color: transparent !important;
|
| 127 |
+
border: none !important;
|
| 128 |
+
padding: 0 !important;
|
| 129 |
+
}
|
| 130 |
+
section[data-testid="stChatInput"] {
|
| 131 |
+
background-color: transparent !important;
|
| 132 |
+
border: none !important;
|
| 133 |
+
padding: 0 !important;
|
| 134 |
+
}
|
| 135 |
+
/* Source Details */
|
| 136 |
+
.streamlit-expanderHeader {
|
| 137 |
+
background: rgba(6, 182, 212, 0.08);
|
| 138 |
+
border-radius: 10px;
|
| 139 |
+
padding: 1rem;
|
| 140 |
+
border: 1px solid rgba(6, 182, 212, 0.15);
|
| 141 |
+
transition: all 0.2s ease;
|
| 142 |
+
}
|
| 143 |
+
/* Copy Button */
|
| 144 |
+
button[data-testid="baseButton-secondary"] {
|
| 145 |
+
background: rgba(6, 182, 212, 0.1);
|
| 146 |
+
color: var(--primary-light);
|
| 147 |
+
border: 1px solid rgba(6, 182, 212, 0.2);
|
| 148 |
+
border-radius: 8px;
|
| 149 |
+
padding: 0.5rem 1rem;
|
| 150 |
+
font-weight: 500;
|
| 151 |
+
transition: all 0.2s ease;
|
| 152 |
+
}
|
| 153 |
+
button[data-testid="baseButton-secondary"]:hover {
|
| 154 |
+
background: rgba(6, 182, 212, 0.2);
|
| 155 |
+
border-color: var(--primary);
|
| 156 |
+
}
|
| 157 |
+
/* Footer Area */
|
| 158 |
+
footer {
|
| 159 |
+
visibility: hidden;
|
| 160 |
+
}
|
| 161 |
+
/* Sidebar Text Size Control */
|
| 162 |
+
.stSlider {
|
| 163 |
+
padding: 1rem;
|
| 164 |
+
}
|
| 165 |
+
.stSlider > div > div > div {
|
| 166 |
+
background-color: var(--primary) !important;
|
| 167 |
+
}
|
| 168 |
+
/* Remove Bottom Space */
|
| 169 |
+
.main .block-container {
|
| 170 |
+
padding-bottom: 2rem;
|
| 171 |
+
max-width: 1000px;
|
| 172 |
+
}
|
| 173 |
+
/* Custom Scrollbar */
|
| 174 |
+
::-webkit-scrollbar {
|
| 175 |
+
width: 8px;
|
| 176 |
+
height: 8px;
|
| 177 |
+
}
|
| 178 |
+
::-webkit-scrollbar-track {
|
| 179 |
+
background: rgba(10, 25, 48, 0.1);
|
| 180 |
+
}
|
| 181 |
+
::-webkit-scrollbar-thumb {
|
| 182 |
+
background: var(--primary);
|
| 183 |
+
border-radius: 4px;
|
| 184 |
+
}
|
| 185 |
+
::-webkit-scrollbar-thumb:hover {
|
| 186 |
+
background: var(--primary-light);
|
| 187 |
+
}
|
| 188 |
+
</style>
|
| 189 |
+
""",
|
| 190 |
+
unsafe_allow_html=True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 191 |
)
|
| 192 |
|
| 193 |
+
|
| 194 |
def add_copy_button(text: str, key: str):
|
| 195 |
if st.button("📋 Kopieren", key=f"copy_{key}"):
|
| 196 |
st.session_state[f"copied_{key}"] = True
|