Kim Juwon
commited on
Commit
Β·
517d30a
1
Parent(s):
830b72b
update UI/UX
Browse files
app.py
CHANGED
|
@@ -19,7 +19,6 @@ Your role is to:
|
|
| 19 |
4. Maintain a {personality} tone throughout the conversation
|
| 20 |
5. Consider the user's expertise level ({expertise_level}) when explaining
|
| 21 |
|
| 22 |
-
|
| 23 |
Please respond in {language}."""
|
| 24 |
return base_prompt
|
| 25 |
|
|
@@ -36,11 +35,11 @@ def respond(
|
|
| 36 |
genre,
|
| 37 |
mood,
|
| 38 |
):
|
| 39 |
-
#
|
| 40 |
system_message = create_system_prompt(agent_type, personality, expertise_level, language)
|
| 41 |
messages = [{"role": "system", "content": system_message}]
|
| 42 |
|
| 43 |
-
#
|
| 44 |
enhanced_message = f"Genre: {genre}\nMood: {mood}\nUser request: {message}"
|
| 45 |
|
| 46 |
for val in history:
|
|
@@ -68,20 +67,20 @@ def reset_chat():
|
|
| 68 |
|
| 69 |
def show_settings_changed_info(agent_type, personality, expertise_level, language):
|
| 70 |
return f"""
|
| 71 |
-
|
| 72 |
-
-
|
| 73 |
-
-
|
| 74 |
-
-
|
| 75 |
-
-
|
| 76 |
|
| 77 |
-
|
| 78 |
"""
|
| 79 |
|
| 80 |
"""
|
| 81 |
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
| 82 |
"""
|
| 83 |
|
| 84 |
-
#
|
| 85 |
custom_css = """
|
| 86 |
:root {
|
| 87 |
--primary-color: #2196f3;
|
|
@@ -109,7 +108,7 @@ custom_css = """
|
|
| 109 |
padding: var(--spacing-unit);
|
| 110 |
}
|
| 111 |
|
| 112 |
-
/*
|
| 113 |
.chat-container {
|
| 114 |
display: flex;
|
| 115 |
flex-direction: column;
|
|
@@ -120,7 +119,7 @@ custom_css = """
|
|
| 120 |
margin-bottom: var(--spacing-unit);
|
| 121 |
}
|
| 122 |
|
| 123 |
-
/*
|
| 124 |
.chat-message {
|
| 125 |
padding: var(--spacing-unit);
|
| 126 |
margin: calc(var(--spacing-unit) / 2);
|
|
@@ -128,29 +127,23 @@ custom_css = """
|
|
| 128 |
max-width: 85%;
|
| 129 |
line-height: 1.5;
|
| 130 |
position: relative;
|
| 131 |
-
animation: fadeIn 0.3s ease-in-out;
|
| 132 |
-
}
|
| 133 |
-
|
| 134 |
-
@keyframes fadeIn {
|
| 135 |
-
from { opacity: 0; transform: translateY(10px); }
|
| 136 |
-
to { opacity: 1; transform: translateY(0); }
|
| 137 |
}
|
| 138 |
|
| 139 |
-
/*
|
| 140 |
.user-message {
|
| 141 |
background-color: var(--chat-user-bg);
|
| 142 |
margin-left: auto;
|
| 143 |
border-bottom-right-radius: 4px;
|
| 144 |
}
|
| 145 |
|
| 146 |
-
/*
|
| 147 |
.bot-message {
|
| 148 |
background-color: var(--chat-bot-bg);
|
| 149 |
margin-right: auto;
|
| 150 |
border-bottom-left-radius: 4px;
|
| 151 |
}
|
| 152 |
|
| 153 |
-
/*
|
| 154 |
.input-container {
|
| 155 |
display: flex;
|
| 156 |
gap: var(--spacing-unit);
|
|
@@ -163,7 +156,7 @@ custom_css = """
|
|
| 163 |
border-bottom-right-radius: 12px;
|
| 164 |
}
|
| 165 |
|
| 166 |
-
/*
|
| 167 |
input[type="text"] {
|
| 168 |
flex: 1;
|
| 169 |
padding: calc(var(--spacing-unit) * 0.75);
|
|
@@ -179,7 +172,7 @@ input[type="text"]:focus {
|
|
| 179 |
outline: none;
|
| 180 |
}
|
| 181 |
|
| 182 |
-
/*
|
| 183 |
button {
|
| 184 |
padding: calc(var(--spacing-unit) * 0.75) calc(var(--spacing-unit) * 1.5);
|
| 185 |
border: none;
|
|
@@ -195,7 +188,7 @@ button:hover {
|
|
| 195 |
background-color: var(--primary-hover);
|
| 196 |
}
|
| 197 |
|
| 198 |
-
/*
|
| 199 |
.settings-panel {
|
| 200 |
background: var(--panel-bg);
|
| 201 |
padding: var(--spacing-unit);
|
|
@@ -204,7 +197,7 @@ button:hover {
|
|
| 204 |
margin-bottom: var(--spacing-unit);
|
| 205 |
}
|
| 206 |
|
| 207 |
-
/*
|
| 208 |
select {
|
| 209 |
width: 100%;
|
| 210 |
padding: calc(var(--spacing-unit) * 0.5);
|
|
@@ -214,37 +207,37 @@ select {
|
|
| 214 |
background-color: var(--panel-bg);
|
| 215 |
}
|
| 216 |
|
| 217 |
-
/*
|
| 218 |
input[type="range"] {
|
| 219 |
width: 100%;
|
| 220 |
margin: calc(var(--spacing-unit) * 0.5) 0;
|
| 221 |
}
|
| 222 |
|
| 223 |
-
/*
|
| 224 |
.markdown {
|
| 225 |
color: var(--text-color);
|
| 226 |
margin-bottom: var(--spacing-unit);
|
| 227 |
}
|
| 228 |
|
| 229 |
-
/*
|
| 230 |
.group {
|
| 231 |
margin-bottom: var(--spacing-unit);
|
| 232 |
}
|
| 233 |
|
| 234 |
-
/*
|
| 235 |
label {
|
| 236 |
color: var(--text-color);
|
| 237 |
margin-bottom: calc(var(--spacing-unit) * 0.5);
|
| 238 |
font-weight: 500;
|
| 239 |
}
|
| 240 |
|
| 241 |
-
/*
|
| 242 |
h1, h2, h3 {
|
| 243 |
color: var(--text-color);
|
| 244 |
margin-bottom: var(--spacing-unit);
|
| 245 |
}
|
| 246 |
|
| 247 |
-
/*
|
| 248 |
::-webkit-scrollbar {
|
| 249 |
width: 8px;
|
| 250 |
}
|
|
@@ -267,8 +260,8 @@ with gr.Blocks(css=custom_css) as demo:
|
|
| 267 |
gr.Markdown("""
|
| 268 |
# π¬ Personalized Movie Recommender
|
| 269 |
|
| 270 |
-
|
| 271 |
-
|
| 272 |
""")
|
| 273 |
|
| 274 |
with gr.Row():
|
|
@@ -280,63 +273,63 @@ with gr.Blocks(css=custom_css) as demo:
|
|
| 280 |
avatar_images=("π€", "π¬"),
|
| 281 |
bubble_full_width=False,
|
| 282 |
elem_classes=["chat-message"],
|
| 283 |
-
type="messages"
|
| 284 |
)
|
| 285 |
with gr.Group(elem_classes="input-container"):
|
| 286 |
msg = gr.Textbox(
|
| 287 |
-
placeholder="
|
| 288 |
show_label=False,
|
| 289 |
container=False
|
| 290 |
)
|
| 291 |
with gr.Row():
|
| 292 |
-
submit = gr.Button("
|
| 293 |
-
clear = gr.Button("
|
| 294 |
|
| 295 |
with gr.Column(scale=1):
|
| 296 |
with gr.Group(elem_classes="settings-panel"):
|
| 297 |
-
gr.Markdown("### π―
|
| 298 |
genre = gr.Dropdown(
|
| 299 |
-
choices=["
|
| 300 |
-
label="
|
| 301 |
multiselect=True
|
| 302 |
)
|
| 303 |
mood = gr.Dropdown(
|
| 304 |
-
choices=["
|
| 305 |
-
label="
|
| 306 |
multiselect=True
|
| 307 |
)
|
| 308 |
|
| 309 |
with gr.Group(elem_classes="settings-panel"):
|
| 310 |
-
gr.Markdown("### π€ Agent
|
| 311 |
agent_type = gr.Dropdown(
|
| 312 |
-
choices=["
|
| 313 |
-
label="Agent
|
| 314 |
-
value="
|
| 315 |
)
|
| 316 |
personality = gr.Dropdown(
|
| 317 |
-
choices=["
|
| 318 |
-
label="
|
| 319 |
-
value="
|
| 320 |
)
|
| 321 |
expertise_level = gr.Dropdown(
|
| 322 |
-
choices=["
|
| 323 |
-
label="
|
| 324 |
-
value="
|
| 325 |
)
|
| 326 |
language = gr.Dropdown(
|
| 327 |
-
choices=["
|
| 328 |
-
label="
|
| 329 |
-
value="
|
| 330 |
)
|
| 331 |
|
| 332 |
with gr.Group(elem_classes="settings-panel"):
|
| 333 |
-
gr.Markdown("### βοΈ
|
| 334 |
max_tokens = gr.Slider(
|
| 335 |
minimum=1,
|
| 336 |
maximum=2048,
|
| 337 |
value=512,
|
| 338 |
step=1,
|
| 339 |
-
label="
|
| 340 |
)
|
| 341 |
temperature = gr.Slider(
|
| 342 |
minimum=0.1,
|
|
@@ -353,7 +346,7 @@ with gr.Blocks(css=custom_css) as demo:
|
|
| 353 |
label="Top-p"
|
| 354 |
)
|
| 355 |
|
| 356 |
-
#
|
| 357 |
for component in [agent_type, personality, expertise_level, language]:
|
| 358 |
component.change(
|
| 359 |
fn=show_settings_changed_info,
|
|
|
|
| 19 |
4. Maintain a {personality} tone throughout the conversation
|
| 20 |
5. Consider the user's expertise level ({expertise_level}) when explaining
|
| 21 |
|
|
|
|
| 22 |
Please respond in {language}."""
|
| 23 |
return base_prompt
|
| 24 |
|
|
|
|
| 35 |
genre,
|
| 36 |
mood,
|
| 37 |
):
|
| 38 |
+
# Create system prompt
|
| 39 |
system_message = create_system_prompt(agent_type, personality, expertise_level, language)
|
| 40 |
messages = [{"role": "system", "content": system_message}]
|
| 41 |
|
| 42 |
+
# Add genre and mood information to user input
|
| 43 |
enhanced_message = f"Genre: {genre}\nMood: {mood}\nUser request: {message}"
|
| 44 |
|
| 45 |
for val in history:
|
|
|
|
| 67 |
|
| 68 |
def show_settings_changed_info(agent_type, personality, expertise_level, language):
|
| 69 |
return f"""
|
| 70 |
+
New Agent Settings:
|
| 71 |
+
- Type: {agent_type}
|
| 72 |
+
- Personality: {personality}
|
| 73 |
+
- Expertise Level: {expertise_level}
|
| 74 |
+
- Response Language: {language}
|
| 75 |
|
| 76 |
+
Chat has been reset. Please start a new conversation with the updated settings.
|
| 77 |
"""
|
| 78 |
|
| 79 |
"""
|
| 80 |
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
| 81 |
"""
|
| 82 |
|
| 83 |
+
# Custom CSS styles
|
| 84 |
custom_css = """
|
| 85 |
:root {
|
| 86 |
--primary-color: #2196f3;
|
|
|
|
| 108 |
padding: var(--spacing-unit);
|
| 109 |
}
|
| 110 |
|
| 111 |
+
/* Chat container styles */
|
| 112 |
.chat-container {
|
| 113 |
display: flex;
|
| 114 |
flex-direction: column;
|
|
|
|
| 119 |
margin-bottom: var(--spacing-unit);
|
| 120 |
}
|
| 121 |
|
| 122 |
+
/* Chat message styles */
|
| 123 |
.chat-message {
|
| 124 |
padding: var(--spacing-unit);
|
| 125 |
margin: calc(var(--spacing-unit) / 2);
|
|
|
|
| 127 |
max-width: 85%;
|
| 128 |
line-height: 1.5;
|
| 129 |
position: relative;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 130 |
}
|
| 131 |
|
| 132 |
+
/* User message styles */
|
| 133 |
.user-message {
|
| 134 |
background-color: var(--chat-user-bg);
|
| 135 |
margin-left: auto;
|
| 136 |
border-bottom-right-radius: 4px;
|
| 137 |
}
|
| 138 |
|
| 139 |
+
/* Bot message styles */
|
| 140 |
.bot-message {
|
| 141 |
background-color: var(--chat-bot-bg);
|
| 142 |
margin-right: auto;
|
| 143 |
border-bottom-left-radius: 4px;
|
| 144 |
}
|
| 145 |
|
| 146 |
+
/* Input area styles */
|
| 147 |
.input-container {
|
| 148 |
display: flex;
|
| 149 |
gap: var(--spacing-unit);
|
|
|
|
| 156 |
border-bottom-right-radius: 12px;
|
| 157 |
}
|
| 158 |
|
| 159 |
+
/* Input field styles */
|
| 160 |
input[type="text"] {
|
| 161 |
flex: 1;
|
| 162 |
padding: calc(var(--spacing-unit) * 0.75);
|
|
|
|
| 172 |
outline: none;
|
| 173 |
}
|
| 174 |
|
| 175 |
+
/* Button styles */
|
| 176 |
button {
|
| 177 |
padding: calc(var(--spacing-unit) * 0.75) calc(var(--spacing-unit) * 1.5);
|
| 178 |
border: none;
|
|
|
|
| 188 |
background-color: var(--primary-hover);
|
| 189 |
}
|
| 190 |
|
| 191 |
+
/* Settings panel styles */
|
| 192 |
.settings-panel {
|
| 193 |
background: var(--panel-bg);
|
| 194 |
padding: var(--spacing-unit);
|
|
|
|
| 197 |
margin-bottom: var(--spacing-unit);
|
| 198 |
}
|
| 199 |
|
| 200 |
+
/* Dropdown styles */
|
| 201 |
select {
|
| 202 |
width: 100%;
|
| 203 |
padding: calc(var(--spacing-unit) * 0.5);
|
|
|
|
| 207 |
background-color: var(--panel-bg);
|
| 208 |
}
|
| 209 |
|
| 210 |
+
/* Slider styles */
|
| 211 |
input[type="range"] {
|
| 212 |
width: 100%;
|
| 213 |
margin: calc(var(--spacing-unit) * 0.5) 0;
|
| 214 |
}
|
| 215 |
|
| 216 |
+
/* Markdown styles */
|
| 217 |
.markdown {
|
| 218 |
color: var(--text-color);
|
| 219 |
margin-bottom: var(--spacing-unit);
|
| 220 |
}
|
| 221 |
|
| 222 |
+
/* Group styles */
|
| 223 |
.group {
|
| 224 |
margin-bottom: var(--spacing-unit);
|
| 225 |
}
|
| 226 |
|
| 227 |
+
/* Label styles */
|
| 228 |
label {
|
| 229 |
color: var(--text-color);
|
| 230 |
margin-bottom: calc(var(--spacing-unit) * 0.5);
|
| 231 |
font-weight: 500;
|
| 232 |
}
|
| 233 |
|
| 234 |
+
/* Header styles */
|
| 235 |
h1, h2, h3 {
|
| 236 |
color: var(--text-color);
|
| 237 |
margin-bottom: var(--spacing-unit);
|
| 238 |
}
|
| 239 |
|
| 240 |
+
/* Scrollbar styles */
|
| 241 |
::-webkit-scrollbar {
|
| 242 |
width: 8px;
|
| 243 |
}
|
|
|
|
| 260 |
gr.Markdown("""
|
| 261 |
# π¬ Personalized Movie Recommender
|
| 262 |
|
| 263 |
+
Welcome to your personalized movie recommendation system!
|
| 264 |
+
Tell us your preferred genres and current mood, and we'll recommend the perfect movies for you.
|
| 265 |
""")
|
| 266 |
|
| 267 |
with gr.Row():
|
|
|
|
| 273 |
avatar_images=("π€", "π¬"),
|
| 274 |
bubble_full_width=False,
|
| 275 |
elem_classes=["chat-message"],
|
| 276 |
+
type="messages"
|
| 277 |
)
|
| 278 |
with gr.Group(elem_classes="input-container"):
|
| 279 |
msg = gr.Textbox(
|
| 280 |
+
placeholder="What kind of movie are you looking for?",
|
| 281 |
show_label=False,
|
| 282 |
container=False
|
| 283 |
)
|
| 284 |
with gr.Row():
|
| 285 |
+
submit = gr.Button("Get Recommendations", variant="primary", size="sm")
|
| 286 |
+
clear = gr.Button("Clear Chat", size="sm")
|
| 287 |
|
| 288 |
with gr.Column(scale=1):
|
| 289 |
with gr.Group(elem_classes="settings-panel"):
|
| 290 |
+
gr.Markdown("### π― Recommendation Settings")
|
| 291 |
genre = gr.Dropdown(
|
| 292 |
+
choices=["Action", "Comedy", "Drama", "Romance", "Thriller", "Sci-Fi", "Fantasy", "Animation"],
|
| 293 |
+
label="Preferred Genres",
|
| 294 |
multiselect=True
|
| 295 |
)
|
| 296 |
mood = gr.Dropdown(
|
| 297 |
+
choices=["Exciting", "Emotional", "Suspenseful", "Relaxing", "Mysterious"],
|
| 298 |
+
label="Current Mood",
|
| 299 |
multiselect=True
|
| 300 |
)
|
| 301 |
|
| 302 |
with gr.Group(elem_classes="settings-panel"):
|
| 303 |
+
gr.Markdown("### π€ Agent Settings")
|
| 304 |
agent_type = gr.Dropdown(
|
| 305 |
+
choices=["Expert", "Friend", "Film Critic", "Curator"],
|
| 306 |
+
label="Agent Type",
|
| 307 |
+
value="Expert"
|
| 308 |
)
|
| 309 |
personality = gr.Dropdown(
|
| 310 |
+
choices=["Friendly", "Professional", "Humorous", "Emotional", "Objective"],
|
| 311 |
+
label="Personality",
|
| 312 |
+
value="Friendly"
|
| 313 |
)
|
| 314 |
expertise_level = gr.Dropdown(
|
| 315 |
+
choices=["Beginner", "Intermediate", "Expert"],
|
| 316 |
+
label="Explanation Level",
|
| 317 |
+
value="Intermediate"
|
| 318 |
)
|
| 319 |
language = gr.Dropdown(
|
| 320 |
+
choices=["English", "Korean", "Japanese"],
|
| 321 |
+
label="Response Language",
|
| 322 |
+
value="English"
|
| 323 |
)
|
| 324 |
|
| 325 |
with gr.Group(elem_classes="settings-panel"):
|
| 326 |
+
gr.Markdown("### βοΈ Advanced Settings")
|
| 327 |
max_tokens = gr.Slider(
|
| 328 |
minimum=1,
|
| 329 |
maximum=2048,
|
| 330 |
value=512,
|
| 331 |
step=1,
|
| 332 |
+
label="Max Tokens"
|
| 333 |
)
|
| 334 |
temperature = gr.Slider(
|
| 335 |
minimum=0.1,
|
|
|
|
| 346 |
label="Top-p"
|
| 347 |
)
|
| 348 |
|
| 349 |
+
# Reset chat and show notification when settings change
|
| 350 |
for component in [agent_type, personality, expertise_level, language]:
|
| 351 |
component.change(
|
| 352 |
fn=show_settings_changed_info,
|