Kim Juwon
commited on
Commit
Β·
8807103
1
Parent(s):
7901dd6
update UI/UX
Browse files
app.py
CHANGED
@@ -14,19 +14,23 @@ def respond(
|
|
14 |
max_tokens,
|
15 |
temperature,
|
16 |
top_p,
|
|
|
|
|
17 |
):
|
18 |
messages = [{"role": "system", "content": system_message}]
|
19 |
|
|
|
|
|
|
|
20 |
for val in history:
|
21 |
if val[0]:
|
22 |
messages.append({"role": "user", "content": val[0]})
|
23 |
if val[1]:
|
24 |
messages.append({"role": "assistant", "content": val[1]})
|
25 |
|
26 |
-
messages.append({"role": "user", "content":
|
27 |
|
28 |
response = ""
|
29 |
-
|
30 |
for message in client.chat_completion(
|
31 |
messages,
|
32 |
max_tokens=max_tokens,
|
@@ -35,7 +39,6 @@ def respond(
|
|
35 |
top_p=top_p,
|
36 |
):
|
37 |
token = message.choices[0].delta.content
|
38 |
-
|
39 |
response += token
|
40 |
yield response
|
41 |
|
@@ -43,21 +46,118 @@ def respond(
|
|
43 |
"""
|
44 |
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
45 |
"""
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
|
62 |
|
63 |
if __name__ == "__main__":
|
|
|
14 |
max_tokens,
|
15 |
temperature,
|
16 |
top_p,
|
17 |
+
genre,
|
18 |
+
mood,
|
19 |
):
|
20 |
messages = [{"role": "system", "content": system_message}]
|
21 |
|
22 |
+
# μ¬μ©μ μ
λ ₯μ μ₯λ₯΄μ κΈ°λΆ μ 보 μΆκ°
|
23 |
+
enhanced_message = f"Genre: {genre}\nMood: {mood}\nUser request: {message}"
|
24 |
+
|
25 |
for val in history:
|
26 |
if val[0]:
|
27 |
messages.append({"role": "user", "content": val[0]})
|
28 |
if val[1]:
|
29 |
messages.append({"role": "assistant", "content": val[1]})
|
30 |
|
31 |
+
messages.append({"role": "user", "content": enhanced_message})
|
32 |
|
33 |
response = ""
|
|
|
34 |
for message in client.chat_completion(
|
35 |
messages,
|
36 |
max_tokens=max_tokens,
|
|
|
39 |
top_p=top_p,
|
40 |
):
|
41 |
token = message.choices[0].delta.content
|
|
|
42 |
response += token
|
43 |
yield response
|
44 |
|
|
|
46 |
"""
|
47 |
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
48 |
"""
|
49 |
+
|
50 |
+
# 컀μ€ν
CSS μ€νμΌ
|
51 |
+
custom_css = """
|
52 |
+
.gradio-container {
|
53 |
+
font-family: 'Helvetica Neue', Arial, sans-serif;
|
54 |
+
}
|
55 |
+
.container {
|
56 |
+
max-width: 800px;
|
57 |
+
margin: auto;
|
58 |
+
padding: 20px;
|
59 |
+
}
|
60 |
+
.chat-message {
|
61 |
+
padding: 15px;
|
62 |
+
border-radius: 10px;
|
63 |
+
margin-bottom: 10px;
|
64 |
+
}
|
65 |
+
.user-message {
|
66 |
+
background-color: #f0f2f5;
|
67 |
+
}
|
68 |
+
.bot-message {
|
69 |
+
background-color: #e3f2fd;
|
70 |
+
}
|
71 |
+
"""
|
72 |
+
|
73 |
+
with gr.Blocks(css=custom_css) as demo:
|
74 |
+
gr.Markdown("""
|
75 |
+
# π¬ Personalized Movie Recommender
|
76 |
+
|
77 |
+
μλ
νμΈμ! λΉμ λ§μ μν μν μΆμ² μμ€ν
μ
λλ€.
|
78 |
+
μ νΈνλ μ₯λ₯΄μ νμ¬ κΈ°λΆμ μλ €μ£Όμλ©΄, λ§μΆ€ν μνλ₯Ό μΆμ²ν΄λ립λλ€.
|
79 |
+
""")
|
80 |
+
|
81 |
+
with gr.Row():
|
82 |
+
with gr.Column(scale=2):
|
83 |
+
chatbot = gr.Chatbot(
|
84 |
+
height=600,
|
85 |
+
show_copy_button=True,
|
86 |
+
avatar_images=("π€", "π¬"),
|
87 |
+
bubble_full_width=False,
|
88 |
+
)
|
89 |
+
msg = gr.Textbox(
|
90 |
+
placeholder="μ΄λ€ μνλ₯Ό μ°Ύκ³ κ³μ κ°μ?",
|
91 |
+
show_label=False,
|
92 |
+
container=False
|
93 |
+
)
|
94 |
+
with gr.Row():
|
95 |
+
submit = gr.Button("μΆμ² λ°κΈ°", variant="primary")
|
96 |
+
clear = gr.Button("λν μ΄κΈ°ν")
|
97 |
+
|
98 |
+
with gr.Column(scale=1):
|
99 |
+
with gr.Group():
|
100 |
+
gr.Markdown("### π― μΆμ² μ€μ ")
|
101 |
+
genre = gr.Dropdown(
|
102 |
+
choices=["μ‘μ
", "μ½λ―Έλ", "λλΌλ§", "λ‘맨μ€", "μ€λ¦΄λ¬", "SF", "ννμ§", "μ λλ©μ΄μ
"],
|
103 |
+
label="μ νΈνλ μ₯λ₯΄",
|
104 |
+
multiselect=True
|
105 |
+
)
|
106 |
+
mood = gr.Dropdown(
|
107 |
+
choices=["μ λλ", "κ°μ±μ μΈ", "κΈ΄μ₯κ° μλ", "νΈμν", "μ λΉλ‘μ΄"],
|
108 |
+
label="νμ¬ κΈ°λΆ",
|
109 |
+
multiselect=True
|
110 |
+
)
|
111 |
+
|
112 |
+
with gr.Group():
|
113 |
+
gr.Markdown("### βοΈ κ³ κΈ μ€μ ")
|
114 |
+
system_message = gr.Textbox(
|
115 |
+
value="You are a friendly movie recommendation assistant. Provide detailed movie recommendations based on user preferences.",
|
116 |
+
label="μμ€ν
λ©μμ§"
|
117 |
+
)
|
118 |
+
max_tokens = gr.Slider(
|
119 |
+
minimum=1,
|
120 |
+
maximum=2048,
|
121 |
+
value=512,
|
122 |
+
step=1,
|
123 |
+
label="μ΅λ ν ν° μ"
|
124 |
+
)
|
125 |
+
temperature = gr.Slider(
|
126 |
+
minimum=0.1,
|
127 |
+
maximum=4.0,
|
128 |
+
value=0.7,
|
129 |
+
step=0.1,
|
130 |
+
label="Temperature"
|
131 |
+
)
|
132 |
+
top_p = gr.Slider(
|
133 |
+
minimum=0.1,
|
134 |
+
maximum=1.0,
|
135 |
+
value=0.95,
|
136 |
+
step=0.05,
|
137 |
+
label="Top-p"
|
138 |
+
)
|
139 |
+
|
140 |
+
submit.click(
|
141 |
+
respond,
|
142 |
+
inputs=[
|
143 |
+
msg,
|
144 |
+
chatbot,
|
145 |
+
system_message,
|
146 |
+
max_tokens,
|
147 |
+
temperature,
|
148 |
+
top_p,
|
149 |
+
genre,
|
150 |
+
mood,
|
151 |
+
],
|
152 |
+
outputs=chatbot,
|
153 |
+
).then(
|
154 |
+
lambda: "",
|
155 |
+
None,
|
156 |
+
msg,
|
157 |
+
queue=False
|
158 |
+
)
|
159 |
+
|
160 |
+
clear.click(lambda: None, None, chatbot, queue=False)
|
161 |
|
162 |
|
163 |
if __name__ == "__main__":
|