Kim Juwon commited on
Commit
517d30a
Β·
1 Parent(s): 830b72b

update UI/UX

Browse files
Files changed (1) hide show
  1. app.py +51 -58
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
- μƒˆλ‘œμš΄ Agent μ„€μ •:
72
- - μœ ν˜•: {agent_type}
73
- - 성격: {personality}
74
- - μ„€λͺ… μˆ˜μ€€: {expertise_level}
75
- - 응닡 μ–Έμ–΄: {language}
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
- # μ»€μŠ€ν…€ CSS μŠ€νƒ€μΌ
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" # OpenAI μŠ€νƒ€μΌ λ©”μ‹œμ§€ ν˜•μ‹ μ‚¬μš©
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("μΆ”μ²œ λ°›κΈ°", variant="primary", size="sm")
293
- clear = gr.Button("λŒ€ν™” μ΄ˆκΈ°ν™”", size="sm")
294
 
295
  with gr.Column(scale=1):
296
  with gr.Group(elem_classes="settings-panel"):
297
- gr.Markdown("### 🎯 μΆ”μ²œ μ„€μ •")
298
  genre = gr.Dropdown(
299
- choices=["μ•‘μ…˜", "μ½”λ―Έλ””", "λ“œλΌλ§ˆ", "둜맨슀", "슀릴러", "SF", "νŒνƒ€μ§€", "μ• λ‹ˆλ©”μ΄μ…˜"],
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,