Yuchan5386 commited on
Commit
33edad8
ยท
verified ยท
1 Parent(s): 43a3069

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +261 -177
app.py CHANGED
@@ -1,191 +1,275 @@
1
- <!DOCTYPE html>
2
- <html lang="ko">
3
- <head>
4
- <meta charset="UTF-8" />
5
- <title>Kossistant Chat</title>
6
- <style>
7
- body {
8
- background-color: #121212;
9
- color: #e0e0e0;
10
- font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
11
- display: flex;
12
- flex-direction: column;
13
- align-items: center;
14
- justify-content: center;
15
- height: 100vh;
16
- margin: 0;
17
- padding: 20px;
18
- animation: fadeIn 1s ease-in-out;
19
- }
20
-
21
- @keyframes fadeIn {
22
- 0% { opacity: 0; }
23
- 100% { opacity: 1; }
24
- }
25
 
26
- .container {
27
- width: 100%;
28
- max-width: 600px;
29
- background-color: #1e1e1e;
30
- border-radius: 8px;
31
- padding: 24px;
32
- box-shadow: 0 4px 20px rgba(0, 0, 0, 0.7);
33
- display: flex;
34
- flex-direction: column;
35
- animation: slideUp 0.5s ease-out;
36
- height: 90vh;
37
- max-height: 800px; /* ์ตœ๋Œ€ ๋†’์ด ์ œํ•œ */
38
- }
39
 
40
- @keyframes slideUp {
41
- 0% { transform: translateY(20px); opacity: 0; }
42
- 100% { transform: translateY(0); opacity: 1; }
43
- }
 
 
 
 
 
 
 
 
 
 
 
44
 
45
- #response-container {
46
- margin-bottom: 20px;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
  padding: 16px;
48
- background-color: #1e1e1e;
49
- border-radius: 8px;
50
- box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
51
- white-space: pre-wrap;
52
- line-height: 1.6;
53
- color: #e0e0e0;
54
- font-size: 14px;
55
- flex-grow: 1;
56
- animation: fadeInText 1s ease-in-out;
57
- overflow-y: auto; /* ์Šคํฌ๋กค ๊ฐ€๋Šฅํ•˜๊ฒŒ ์„ค์ • */
58
- max-height: 60vh; /* ์ตœ๋Œ€ ๋†’์ด ์„ค์ • */
59
- }
60
-
61
- @keyframes fadeInText {
62
- 0% { opacity: 0; }
63
- 100% { opacity: 1; }
64
- }
65
-
66
- .input-container {
67
- display: flex;
68
- flex-direction: column;
69
- gap: 12px;
70
- }
71
-
72
- #userInput {
73
- padding: 12px 16px;
74
- font-size: 16px;
75
- border: 1px solid #333;
76
- border-radius: 8px;
77
- background-color: #1e1e1e;
78
- color: #fff;
79
- transition: background-color 0.3s ease;
80
- animation: fadeInInput 1s ease-in-out;
81
- }
82
-
83
- @keyframes fadeInInput {
84
- 0% { opacity: 0; }
85
- 100% { opacity: 1; }
86
  }
87
-
88
- #userInput:focus {
89
- outline: none;
90
- background-color: #333;
91
- }
92
-
93
- #sendBtn {
94
- padding: 12px 20px;
95
- font-size: 16px;
96
- background-color: #ff9800; /* ๋ฒ„ํŠผ ์ƒ‰์ƒ ๋ณ€๊ฒฝ */
97
- color: #fff;
98
- border: none;
99
- border-radius: 8px;
100
- cursor: pointer;
101
- transition: background-color 0.2s ease, transform 0.2s ease;
102
- animation: fadeInButton 1s ease-in-out;
103
- }
104
-
105
- @keyframes fadeInButton {
106
- 0% { opacity: 0; transform: scale(0.8); }
107
- 100% { opacity: 1; transform: scale(1); }
108
- }
109
-
110
- #sendBtn:hover {
111
- background-color: #fb8c00;
112
- transform: scale(1.05);
113
  }
114
-
115
- #sendBtn:active {
116
- transform: scale(0.95);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
117
  }
118
-
119
- /* ๋กœ๋”ฉ ์Šคํ”ผ๋„ˆ */
120
- .spinner {
121
- width: 24px;
122
- height: 24px;
123
- border: 4px solid #f3f3f3;
124
- border-top: 4px solid #ff9800;
125
- border-radius: 50%;
126
- animation: spin 1s linear infinite;
127
- margin: 0 auto;
128
  }
129
-
130
- @keyframes spin {
131
- 0% { transform: rotate(0deg); }
132
- 100% { transform: rotate(360deg); }
 
133
  }
134
-
135
- /* ๋ฐ˜์‘ํ˜• ๋””์ž์ธ */
136
- @media (max-width: 768px) {
137
- .container {
138
- width: 100%;
139
- padding: 16px;
140
- }
141
-
142
- #userInput, #sendBtn {
143
- width: 100%;
144
- max-width: 100%;
145
- }
146
  }
147
- </style>
148
- </head>
149
- <body>
150
- <div class="container">
151
- <div id="response-container"></div>
152
- <div class="input-container">
153
- <input id="userInput" type="text" placeholder="์งˆ๋ฌธ์„ ์ž…๋ ฅํ•˜์„ธ์š”" />
154
- <button id="sendBtn">๋ณด๋‚ด๊ธฐ</button>
155
- </div>
156
- </div>
157
-
158
- <script type="module">
159
- import { Client } from "https://cdn.jsdelivr.net/npm/@gradio/client/dist/index.min.js";
160
-
161
- (async () => {
162
- const client = await Client.connect("Yuchan5386/Kossistant-1");
163
-
164
- const sendMessage = async () => {
165
- const userInput = document.querySelector("#userInput").value;
166
- if (!userInput.trim()) return;
167
 
168
- // ๋กœ๋”ฉ ์Šคํ”ผ๋„ˆ ์ถ”๊ฐ€
169
- document.querySelector("#response-container").innerHTML = '<div class="spinner"></div>';
 
 
 
 
 
170
 
171
- try {
172
- const result = await client.predict("/chat_respond", [userInput]);
173
- document.querySelector("#response-container").innerHTML = result.data[0].replace(/\n/g, "<br>");
174
- document.querySelector("#userInput").value = ''; // ์ž…๋ ฅ์ฐฝ ์ดˆ๊ธฐํ™”
175
- } catch (error) {
176
- document.querySelector("#response-container").innerHTML = "์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค. ๋‹ค์‹œ ์‹œ๋„ํ•ด ์ฃผ์„ธ์š”.";
177
- }
178
- };
179
 
180
- // ์—”ํ„ฐํ‚ค๋กœ ๋ฉ”์‹œ์ง€ ์ „์†ก
181
- document.querySelector("#sendBtn").addEventListener("click", sendMessage);
182
- document.querySelector("#userInput").addEventListener("keypress", (e) => {
183
- if (e.key === "Enter") sendMessage();
184
- });
185
 
186
- // ํŽ˜์ด์ง€ ๋กœ๋”ฉ ํ›„ ์ž๋™ ํฌ์ปค์Šค
187
- document.querySelector("#userInput").focus();
188
- })();
189
- </script>
190
- </body>
191
- </html>
 
1
+ import gradio as gr
2
+ from chatbot import respond
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
 
4
+ def chat_respond(message, history):
5
+ response = respond(message)
6
+ history.append(f"User: {message}")
7
+ history.append(f"Kossistant: {response}")
8
+ return format_history(history), history, ""
 
 
 
 
 
 
 
 
9
 
10
+ def format_history(history):
11
+ html = "<div class='chat-container'>"
12
+ for i in range(0, len(history) - 1, 2):
13
+ user = history[i].replace("User: ", "")
14
+ bot = history[i+1].replace("Kossistant: ", "")
15
+ html += f"""
16
+ <div class='message user'>
17
+ <div class='bubble user-bubble'>{user}</div>
18
+ </div>
19
+ <div class='message bot'>
20
+ <div class='bubble bot-bubble'>{bot}</div>
21
+ </div>
22
+ """
23
+ html += "</div>"
24
+ return html
25
 
26
+ with gr.Blocks(css="""
27
+ * {
28
+ box-sizing: border-box;
29
+ -webkit-tap-highlight-color: transparent;
30
+ }
31
+ body {
32
+ margin: 0;
33
+ padding: 0;
34
+ font-family: 'Pretendard', 'Segoe UI', 'Apple SD Gothic Neo', sans-serif;
35
+ background-color: #121212;
36
+ color: #FFF;
37
+ overflow-x: hidden;
38
+ transition: background-color 0.3s ease;
39
+ }
40
+ .gradio-container {
41
+ background-color: #121212 !important;
42
+ color: white;
43
+ }
44
+ h1 {
45
+ text-align: center;
46
+ font-size: 2rem;
47
+ color: #00f7ff;
48
+ margin: 30px 0;
49
+ text-transform: uppercase;
50
+ letter-spacing: 1px;
51
+ animation: fadeIn 1.5s ease-in-out;
52
+ }
53
+ .chat-wrapper {
54
+ background-color: #1A1A1A;
55
+ border-radius: 20px;
56
+ padding: 30px 35px;
57
+ max-width: 768px;
58
+ margin: auto;
59
+ box-shadow: 0 0 20px rgba(0,0,0,0.3);
60
+ height: 75vh;
61
+ display: flex;
62
+ flex-direction: column;
63
+ justify-content: space-between;
64
+ transition: background-color 0.3s ease, box-shadow 0.3s ease;
65
+ }
66
+ .chat-wrapper:hover {
67
+ box-shadow: 0 0 30px rgba(0,0,0,0.5);
68
+ }
69
+ .chat-container {
70
+ overflow-y: auto;
71
+ flex-grow: 1;
72
+ padding-right: 10px;
73
+ margin-bottom: 30px;
74
+ scrollbar-width: thin;
75
+ scrollbar-color: #444 #1A1A1A;
76
+ }
77
+ .chat-container::-webkit-scrollbar {
78
+ width: 6px;
79
+ }
80
+ .chat-container::-webkit-scrollbar-thumb {
81
+ background-color: #444;
82
+ border-radius: 3px;
83
+ }
84
+ .message {
85
+ margin-bottom: 14px;
86
+ display: flex;
87
+ animation: slideIn 0.3s ease-in-out;
88
+ }
89
+ .user {
90
+ justify-content: flex-end;
91
+ }
92
+ .bot {
93
+ justify-content: flex-start;
94
+ }
95
+ .bubble {
96
+ max-width: 80%;
97
+ padding: 12px 16px;
98
+ border-radius: 20px;
99
+ line-height: 1.6;
100
+ font-size: 0.98rem;
101
+ position: relative;
102
+ animation: fadeIn 0.5s ease-in-out;
103
+ word-break: break-word;
104
+ white-space: pre-wrap;
105
+ transition: background-color 0.3s ease, box-shadow 0.3s ease;
106
+ }
107
+ .user-bubble {
108
+ background-color: #00796B;
109
+ color: white;
110
+ border-bottom-right-radius: 0;
111
+ align-self: flex-end;
112
+ box-shadow: 0 4px 8px rgba(0, 121, 107, 0.3);
113
+ }
114
+ .bot-bubble {
115
+ background-color: #2F3136;
116
+ color: white;
117
+ border-bottom-left-radius: 0;
118
+ align-self: flex-start;
119
+ box-shadow: 0 4px 8px rgba(255, 255, 255, 0.1);
120
+ }
121
+ .bot-bubble:after {
122
+ content: '';
123
+ position: absolute;
124
+ left: -10px;
125
+ top: 10px;
126
+ border: 6px solid transparent;
127
+ border-right-color: #2F3136;
128
+ }
129
+ .user-bubble:after {
130
+ content: '';
131
+ position: absolute;
132
+ right: -10px;
133
+ top: 10px;
134
+ border: 6px solid transparent;
135
+ border-left-color: #00796B;
136
+ }
137
+ textarea, input[type="text"] {
138
+ background-color: #2C2C2C !important;
139
+ color: white !important;
140
+ border: 1px solid #555 !important;
141
+ border-radius: 14px !important;
142
+ padding: 12px 14px !important;
143
+ font-size: 1rem;
144
+ width: 100%;
145
+ transition: all 0.2s ease-in-out;
146
+ }
147
+ textarea:focus, input[type="text"]:focus {
148
+ outline: none;
149
+ border-color: #00f7ff !important;
150
+ box-shadow: 0 0 5px #00f7ff55;
151
+ }
152
+ button {
153
+ background-color: #00C896 !important;
154
+ color: white !important;
155
+ font-weight: bold;
156
+ border: none !important;
157
+ border-radius: 14px !important;
158
+ padding: 12px 18px !important;
159
+ font-size: 1rem;
160
+ transition: all 0.2s ease-in-out;
161
+ }
162
+ button:hover {
163
+ background-color: #00a67e !important;
164
+ transform: scale(1.05);
165
+ }
166
+ @media screen and (max-width: 768px) {
167
+ .chat-wrapper {
168
  padding: 16px;
169
+ border-radius: 0;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
170
  }
171
+ .bubble {
172
+ font-size: 0.95rem;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
173
  }
174
+ }
175
+ ::selection {
176
+ background: #00f7ff;
177
+ color: #000;
178
+ }
179
+ @keyframes slideIn {
180
+ 0% { transform: translateY(10px); opacity: 0; }
181
+ 100% { transform: translateY(0); opacity: 1; }
182
+ }
183
+ @keyframes fadeIn {
184
+ 0% { opacity: 0; }
185
+ 100% { opacity: 1; }
186
+ }
187
+ /* ์ถ”๊ฐ€์ ์ธ ์š”์†Œ๋“ค */
188
+ .message {
189
+ display: flex;
190
+ flex-direction: column;
191
+ gap: 8px;
192
+ }
193
+ .user-bubble {
194
+ background-color: #00796B;
195
+ color: white;
196
+ padding: 14px 18px;
197
+ border-radius: 18px;
198
+ box-shadow: 0 4px 6px rgba(0, 121, 107, 0.3);
199
+ transition: all 0.3s ease-in-out;
200
+ }
201
+ .user-bubble:hover {
202
+ background-color: #004d40;
203
+ transform: scale(1.05);
204
+ }
205
+ .bot-bubble {
206
+ background-color: #2F3136;
207
+ color: white;
208
+ padding: 14px 18px;
209
+ border-radius: 18px;
210
+ box-shadow: 0 4px 6px rgba(255, 255, 255, 0.1);
211
+ transition: all 0.3s ease-in-out;
212
+ }
213
+ .bot-bubble:hover {
214
+ background-color: #1a1a1a;
215
+ transform: scale(1.05);
216
+ }
217
+ /* ๋ฉ”์‹œ์ง€ ์ž…๋ ฅ ์Šคํƒ€์ผ */
218
+ .gradio-textbox input, .gradio-textbox textarea {
219
+ background-color: #2C2C2C;
220
+ color: white;
221
+ border-radius: 14px;
222
+ padding: 12px 16px;
223
+ border: 1px solid #444;
224
+ }
225
+ .gradio-textbox input:focus, .gradio-textbox textarea:focus {
226
+ border-color: #00f7ff;
227
+ outline: none;
228
+ box-shadow: 0 0 5px rgba(0, 247, 255, 0.5);
229
+ }
230
+ .gradio-button {
231
+ background-color: #00C896;
232
+ color: white;
233
+ padding: 12px 18px;
234
+ border-radius: 14px;
235
+ font-size: 1rem;
236
+ transition: all 0.2s ease;
237
+ }
238
+ .gradio-button:hover {
239
+ background-color: #00a67e;
240
+ transform: scale(1.05);
241
+ }
242
+ /* ๋ฏธ๋””์–ด ์ฟผ๋ฆฌ ๏ฟฝ๏ฟฝ์„  */
243
+ @media (max-width: 1024px) {
244
+ .chat-wrapper {
245
+ padding: 20px 25px;
246
  }
247
+ .message {
248
+ gap: 12px;
 
 
 
 
 
 
 
 
249
  }
250
+ }
251
+ @media (max-width: 768px) {
252
+ .chat-wrapper {
253
+ padding: 15px 20px;
254
+ border-radius: 0;
255
  }
256
+ .message {
257
+ gap: 8px;
 
 
 
 
 
 
 
 
 
 
258
  }
259
+ }
260
+ """) as demo:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
261
 
262
+ gr.HTML("<h1>Kossistant ์ฑ—๋ด‡</h1>")
263
+
264
+ with gr.Column(elem_classes="chat-wrapper"):
265
+ chatbox = gr.HTML(value="", label="๋Œ€ํ™”")
266
+ with gr.Row():
267
+ msg = gr.Textbox(placeholder="๋ฉ”์‹œ์ง€๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”", lines=1, scale=8)
268
+ send_button = gr.Button("์ „์†ก", scale=2)
269
 
270
+ state = gr.State([])
 
 
 
 
 
 
 
271
 
272
+ send_button.click(chat_respond, inputs=[msg, state], outputs=[chatbox, state, msg])
273
+ msg.submit(chat_respond, inputs=[msg, state], outputs=[chatbox, state, msg])
 
 
 
274
 
275
+ demo.launch(share=True)