Spaces:
Running
Running
nguyenbh
commited on
Commit
·
d00bdd7
1
Parent(s):
ad9e272
support dark mode
Browse files
app.py
CHANGED
|
@@ -8,6 +8,7 @@ from azure.core.credentials import AzureKeyCredential
|
|
| 8 |
url = os.getenv("Azure_Endpoint")
|
| 9 |
api_key = AzureKeyCredential(os.getenv("Azure_API_KEY"))
|
| 10 |
|
|
|
|
| 11 |
# Initialize the ChatCompletionsClient
|
| 12 |
client = ChatCompletionsClient(
|
| 13 |
endpoint=url,
|
|
@@ -76,31 +77,46 @@ def get_azure_response(message, chat_history, temperature, max_tokens, top_p):
|
|
| 76 |
|
| 77 |
# CSS for custom styling
|
| 78 |
custom_css = """
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
.container {
|
| 80 |
max-width: 1200px !important;
|
| 81 |
margin-left: auto !important;
|
| 82 |
margin-right: auto !important;
|
| 83 |
padding-top: 0rem !important;
|
| 84 |
}
|
|
|
|
| 85 |
.header {
|
| 86 |
text-align: center;
|
| 87 |
margin-bottom: 0rem;
|
| 88 |
}
|
|
|
|
| 89 |
.header h1 {
|
| 90 |
font-size: 2.5rem !important;
|
| 91 |
font-weight: 700 !important;
|
| 92 |
-
color: #1a5276 !important;
|
| 93 |
margin-bottom: 0.5rem !important;
|
| 94 |
}
|
|
|
|
| 95 |
.header p {
|
| 96 |
font-size: 1.2rem !important;
|
| 97 |
-
color: #34495e !important;
|
| 98 |
}
|
|
|
|
| 99 |
.chatbot-container {
|
| 100 |
border-radius: 10px !important;
|
| 101 |
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1) !important;
|
| 102 |
overflow: hidden !important;
|
| 103 |
}
|
|
|
|
| 104 |
.emoji-button {
|
| 105 |
background: none !important;
|
| 106 |
border: none !important;
|
|
@@ -109,35 +125,150 @@ custom_css = """
|
|
| 109 |
cursor: pointer !important;
|
| 110 |
transition: transform 0.2s !important;
|
| 111 |
}
|
|
|
|
| 112 |
.emoji-button:hover {
|
| 113 |
transform: scale(1.2) !important;
|
| 114 |
}
|
|
|
|
| 115 |
.message-input {
|
| 116 |
margin-top: 1rem !important;
|
| 117 |
display: flex !important;
|
| 118 |
align-items: center !important;
|
| 119 |
}
|
|
|
|
| 120 |
.footer {
|
| 121 |
margin-top: 2rem;
|
| 122 |
text-align: center;
|
| 123 |
font-size: 0.9rem;
|
| 124 |
-
color: #7f8c8d;
|
| 125 |
}
|
|
|
|
| 126 |
.parameters-section {
|
| 127 |
-
background-color: #f8f9fa !important;
|
| 128 |
padding: 1rem !important;
|
| 129 |
border-radius: 8px !important;
|
| 130 |
margin-bottom: 1rem !important;
|
|
|
|
| 131 |
}
|
|
|
|
| 132 |
.examples-section {
|
| 133 |
-
background-color: #e8f4f8 !important;
|
| 134 |
padding: 1rem !important;
|
| 135 |
border-radius: 8px !important;
|
| 136 |
margin-bottom: 1rem !important;
|
|
|
|
| 137 |
}
|
|
|
|
| 138 |
.right-panel {
|
| 139 |
padding-left: 1rem !important;
|
| 140 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 141 |
"""
|
| 142 |
|
| 143 |
# Create the Gradio interface with a modern, professional design
|
|
@@ -298,4 +429,4 @@ with gr.Blocks(css=custom_css, title="Phi-4-mini Playground") as demo:
|
|
| 298 |
regenerate.click(regenerate_response, [chatbot, temp_slider, max_tokens_slider, top_p_slider], [chatbot])
|
| 299 |
|
| 300 |
# Launch the app
|
| 301 |
-
demo.launch() # Set share=True to generate a public URL for testing# Launch the app
|
|
|
|
| 8 |
url = os.getenv("Azure_Endpoint")
|
| 9 |
api_key = AzureKeyCredential(os.getenv("Azure_API_KEY"))
|
| 10 |
|
| 11 |
+
|
| 12 |
# Initialize the ChatCompletionsClient
|
| 13 |
client = ChatCompletionsClient(
|
| 14 |
endpoint=url,
|
|
|
|
| 77 |
|
| 78 |
# CSS for custom styling
|
| 79 |
custom_css = """
|
| 80 |
+
/* Light theme variables */
|
| 81 |
+
:root {
|
| 82 |
+
--text-primary: #1a5276;
|
| 83 |
+
--text-secondary: #34495e;
|
| 84 |
+
--text-tertiary: #7f8c8d;
|
| 85 |
+
--background-primary: #ffffff;
|
| 86 |
+
--background-secondary: #f8f9fa;
|
| 87 |
+
--background-accent: #e8f4f8;
|
| 88 |
+
--border-color: #e0e0e0;
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
/* Base styles that work in both light and dark themes */
|
| 92 |
.container {
|
| 93 |
max-width: 1200px !important;
|
| 94 |
margin-left: auto !important;
|
| 95 |
margin-right: auto !important;
|
| 96 |
padding-top: 0rem !important;
|
| 97 |
}
|
| 98 |
+
|
| 99 |
.header {
|
| 100 |
text-align: center;
|
| 101 |
margin-bottom: 0rem;
|
| 102 |
}
|
| 103 |
+
|
| 104 |
.header h1 {
|
| 105 |
font-size: 2.5rem !important;
|
| 106 |
font-weight: 700 !important;
|
|
|
|
| 107 |
margin-bottom: 0.5rem !important;
|
| 108 |
}
|
| 109 |
+
|
| 110 |
.header p {
|
| 111 |
font-size: 1.2rem !important;
|
|
|
|
| 112 |
}
|
| 113 |
+
|
| 114 |
.chatbot-container {
|
| 115 |
border-radius: 10px !important;
|
| 116 |
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1) !important;
|
| 117 |
overflow: hidden !important;
|
| 118 |
}
|
| 119 |
+
|
| 120 |
.emoji-button {
|
| 121 |
background: none !important;
|
| 122 |
border: none !important;
|
|
|
|
| 125 |
cursor: pointer !important;
|
| 126 |
transition: transform 0.2s !important;
|
| 127 |
}
|
| 128 |
+
|
| 129 |
.emoji-button:hover {
|
| 130 |
transform: scale(1.2) !important;
|
| 131 |
}
|
| 132 |
+
|
| 133 |
.message-input {
|
| 134 |
margin-top: 1rem !important;
|
| 135 |
display: flex !important;
|
| 136 |
align-items: center !important;
|
| 137 |
}
|
| 138 |
+
|
| 139 |
.footer {
|
| 140 |
margin-top: 2rem;
|
| 141 |
text-align: center;
|
| 142 |
font-size: 0.9rem;
|
|
|
|
| 143 |
}
|
| 144 |
+
|
| 145 |
.parameters-section {
|
|
|
|
| 146 |
padding: 1rem !important;
|
| 147 |
border-radius: 8px !important;
|
| 148 |
margin-bottom: 1rem !important;
|
| 149 |
+
border: 1px solid var(--border-color) !important;
|
| 150 |
}
|
| 151 |
+
|
| 152 |
.examples-section {
|
|
|
|
| 153 |
padding: 1rem !important;
|
| 154 |
border-radius: 8px !important;
|
| 155 |
margin-bottom: 1rem !important;
|
| 156 |
+
border: 1px solid var(--border-color) !important;
|
| 157 |
}
|
| 158 |
+
|
| 159 |
.right-panel {
|
| 160 |
padding-left: 1rem !important;
|
| 161 |
}
|
| 162 |
+
|
| 163 |
+
/* Light theme specific styles */
|
| 164 |
+
body:not(.dark) .header h1 {
|
| 165 |
+
color: var(--text-primary) !important;
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
body:not(.dark) .header p {
|
| 169 |
+
color: var(--text-secondary) !important;
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
+
body:not(.dark) .footer {
|
| 173 |
+
color: var(--text-tertiary) !important;
|
| 174 |
+
}
|
| 175 |
+
|
| 176 |
+
body:not(.dark) .parameters-section {
|
| 177 |
+
background-color: var(--background-secondary) !important;
|
| 178 |
+
}
|
| 179 |
+
|
| 180 |
+
body:not(.dark) .examples-section {
|
| 181 |
+
background-color: var(--background-accent) !important;
|
| 182 |
+
}
|
| 183 |
+
|
| 184 |
+
body:not(.dark) .chatbot-container {
|
| 185 |
+
background-color: var(--background-primary) !important;
|
| 186 |
+
}
|
| 187 |
+
|
| 188 |
+
/* Dark theme specific styles */
|
| 189 |
+
body.dark {
|
| 190 |
+
--text-primary: #eaeaea !important;
|
| 191 |
+
--text-secondary: #b0b0b0 !important;
|
| 192 |
+
--text-tertiary: #909090 !important;
|
| 193 |
+
--background-primary: #2a2a2a !important;
|
| 194 |
+
--background-secondary: #333333 !important;
|
| 195 |
+
--background-accent: #1e3a5f !important;
|
| 196 |
+
--border-color: #555555 !important;
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
body.dark .header h1 {
|
| 200 |
+
color: var(--text-primary) !important;
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
body.dark .header p {
|
| 204 |
+
color: var(--text-secondary) !important;
|
| 205 |
+
}
|
| 206 |
+
|
| 207 |
+
body.dark .footer {
|
| 208 |
+
color: var(--text-tertiary) !important;
|
| 209 |
+
}
|
| 210 |
+
|
| 211 |
+
body.dark .parameters-section {
|
| 212 |
+
background-color: var(--background-secondary) !important;
|
| 213 |
+
}
|
| 214 |
+
|
| 215 |
+
body.dark .examples-section {
|
| 216 |
+
background-color: var(--background-accent) !important;
|
| 217 |
+
}
|
| 218 |
+
|
| 219 |
+
body.dark .chatbot-container {
|
| 220 |
+
background-color: var(--background-primary) !important;
|
| 221 |
+
}
|
| 222 |
+
|
| 223 |
+
/* Chat bubbles styling for both themes */
|
| 224 |
+
[data-testid="chatbot"] .message.user {
|
| 225 |
+
border: 1px solid rgba(0, 0, 0, 0.1) !important;
|
| 226 |
+
}
|
| 227 |
+
|
| 228 |
+
[data-testid="chatbot"] .message.bot {
|
| 229 |
+
border: 1px solid rgba(0, 0, 0, 0.1) !important;
|
| 230 |
+
}
|
| 231 |
+
|
| 232 |
+
/* Chat bubbles in dark mode */
|
| 233 |
+
body.dark [data-testid="chatbot"] .message.user {
|
| 234 |
+
background-color: #3a3a3a !important;
|
| 235 |
+
color: #ffffff !important;
|
| 236 |
+
border: 1px solid #4a4a4a !important;
|
| 237 |
+
}
|
| 238 |
+
|
| 239 |
+
body.dark [data-testid="chatbot"] .message.bot {
|
| 240 |
+
background-color: #1e3a5f !important;
|
| 241 |
+
color: #ffffff !important;
|
| 242 |
+
border: 1px solid #2c5999 !important;
|
| 243 |
+
}
|
| 244 |
+
|
| 245 |
+
/* Ensure text inputs are visible in dark mode */
|
| 246 |
+
body.dark input[type="text"],
|
| 247 |
+
body.dark textarea {
|
| 248 |
+
background-color: #333333 !important;
|
| 249 |
+
color: #ffffff !important;
|
| 250 |
+
border-color: #555555 !important;
|
| 251 |
+
}
|
| 252 |
+
|
| 253 |
+
/* Fix for slider tracks and thumbs in dark mode */
|
| 254 |
+
body.dark input[type="range"]::-webkit-slider-runnable-track {
|
| 255 |
+
background-color: #555555 !important;
|
| 256 |
+
}
|
| 257 |
+
|
| 258 |
+
body.dark input[type="range"]::-webkit-slider-thumb {
|
| 259 |
+
background-color: #1e88e5 !important;
|
| 260 |
+
}
|
| 261 |
+
|
| 262 |
+
/* Buttons in dark mode */
|
| 263 |
+
body.dark button {
|
| 264 |
+
border-color: #555555 !important;
|
| 265 |
+
}
|
| 266 |
+
|
| 267 |
+
/* Labels and descriptions in dark mode */
|
| 268 |
+
body.dark label,
|
| 269 |
+
body.dark .gr-form > div > p {
|
| 270 |
+
color: var(--text-secondary) !important;
|
| 271 |
+
}
|
| 272 |
"""
|
| 273 |
|
| 274 |
# Create the Gradio interface with a modern, professional design
|
|
|
|
| 429 |
regenerate.click(regenerate_response, [chatbot, temp_slider, max_tokens_slider, top_p_slider], [chatbot])
|
| 430 |
|
| 431 |
# Launch the app
|
| 432 |
+
demo.launch(share=True) # Set share=True to generate a public URL for testing# Launch the app
|