FrederickSundeep commited on
Commit
7ce3b8a
Β·
1 Parent(s): 4007909

commit 007

Browse files
Files changed (2) hide show
  1. static/style.css +39 -5
  2. templates/index.html +21 -9
static/style.css CHANGED
@@ -15,6 +15,8 @@ body {
15
  background: white;
16
  border-radius: 10px;
17
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.05);
 
 
18
  }
19
 
20
  h2 {
@@ -24,13 +26,16 @@ h2 {
24
  }
25
 
26
  .chat-box {
27
- max-height: 400px;
 
28
  overflow-y: auto;
29
  padding: 10px;
30
  border: 1px solid #e5e7eb;
31
  border-radius: 8px;
32
  margin-bottom: 16px;
33
  background: #fafafa;
 
 
34
  }
35
 
36
  .message {
@@ -66,6 +71,8 @@ textarea {
66
  border-radius: 6px;
67
  border: 1px solid #d1d5db;
68
  font-size: 14px;
 
 
69
  }
70
 
71
  button {
@@ -77,17 +84,18 @@ button {
77
  border-radius: 6px;
78
  cursor: pointer;
79
  align-self: flex-end;
 
80
  }
81
 
82
  button:hover {
83
  background: #4f46e5;
84
  }
85
 
 
86
  .typing-indicator {
87
  display: flex;
88
  gap: 6px;
89
- margin-left: 10px;
90
- margin-bottom: 10px;
91
  }
92
 
93
  .dot {
@@ -111,21 +119,26 @@ button:hover {
111
  40% { opacity: 1; }
112
  }
113
 
 
114
  .code-block {
115
  position: relative;
116
  background: #1f2937;
117
  color: #e5e7eb;
118
  border-radius: 6px;
119
  overflow: auto;
120
- padding: 12px;
121
- margin-top: 6px;
122
  }
123
 
124
  .code-block pre {
125
  margin: 0;
 
 
 
126
  overflow-x: auto;
 
127
  }
128
 
 
129
  .copy-btn {
130
  position: absolute;
131
  top: 8px;
@@ -137,8 +150,29 @@ button:hover {
137
  border-radius: 4px;
138
  font-size: 12px;
139
  cursor: pointer;
 
140
  }
141
 
142
  .copy-btn:hover {
143
  background: #4b5563;
144
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  background: white;
16
  border-radius: 10px;
17
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.05);
18
+ display: flex;
19
+ flex-direction: column;
20
  }
21
 
22
  h2 {
 
26
  }
27
 
28
  .chat-box {
29
+ flex-grow: 1;
30
+ max-height: 450px;
31
  overflow-y: auto;
32
  padding: 10px;
33
  border: 1px solid #e5e7eb;
34
  border-radius: 8px;
35
  margin-bottom: 16px;
36
  background: #fafafa;
37
+ display: flex;
38
+ flex-direction: column;
39
  }
40
 
41
  .message {
 
71
  border-radius: 6px;
72
  border: 1px solid #d1d5db;
73
  font-size: 14px;
74
+ width: 100%;
75
+ box-sizing: border-box;
76
  }
77
 
78
  button {
 
84
  border-radius: 6px;
85
  cursor: pointer;
86
  align-self: flex-end;
87
+ transition: background 0.3s ease;
88
  }
89
 
90
  button:hover {
91
  background: #4f46e5;
92
  }
93
 
94
+ /* Typing indicator */
95
  .typing-indicator {
96
  display: flex;
97
  gap: 6px;
98
+ margin: 5px 0 10px 5px;
 
99
  }
100
 
101
  .dot {
 
119
  40% { opacity: 1; }
120
  }
121
 
122
+ /* Code block styling */
123
  .code-block {
124
  position: relative;
125
  background: #1f2937;
126
  color: #e5e7eb;
127
  border-radius: 6px;
128
  overflow: auto;
129
+ margin: 8px 0;
 
130
  }
131
 
132
  .code-block pre {
133
  margin: 0;
134
+ padding: 12px;
135
+ font-family: 'Courier New', monospace;
136
+ font-size: 14px;
137
  overflow-x: auto;
138
+ line-height: 1.5;
139
  }
140
 
141
+ /* Copy button styling */
142
  .copy-btn {
143
  position: absolute;
144
  top: 8px;
 
150
  border-radius: 4px;
151
  font-size: 12px;
152
  cursor: pointer;
153
+ z-index: 10;
154
  }
155
 
156
  .copy-btn:hover {
157
  background: #4b5563;
158
  }
159
+
160
+ /* Responsive tweaks */
161
+ @media (max-width: 768px) {
162
+ .chat-container {
163
+ margin: 10px;
164
+ padding: 16px;
165
+ }
166
+
167
+ .chat-box {
168
+ max-height: 60vh;
169
+ }
170
+
171
+ textarea {
172
+ font-size: 13px;
173
+ }
174
+
175
+ button {
176
+ font-size: 14px;
177
+ }
178
+ }
templates/index.html CHANGED
@@ -15,14 +15,16 @@
15
 
16
  <div class="chat-box" ref="chatbox">
17
  <div v-for="(msg, i) in history" :key="i" class="message" :class="msg.role">
18
- <div v-if="msg.role === 'assistant' && msg.content.includes('```')" v-html="renderCode(msg.content)"></div>
19
- <div v-else>{{ '{{' }} msg.content {{ '}}' }}</div>
 
 
 
 
20
  </div>
21
 
22
  <div v-if="loading" class="typing-indicator">
23
- <span class="dot"></span>
24
- <span class="dot"></span>
25
- <span class="dot"></span>
26
  </div>
27
  </div>
28
 
@@ -52,15 +54,25 @@
52
  const match = text.match(/```([^]*)```/);
53
  if (!match) return text;
54
  const code = match[1].trim();
55
- const escaped = hljs.highlightAuto(code).value;
 
56
  return `
57
  <div class="code-block">
58
- <pre><code>${escaped}</code></pre>
59
- <button class="copy-btn" onclick="copyToClipboard(\`${code.replace(/`/g, '\\`')}\`, this)">Copy</button>
 
 
60
  </div>
61
  `;
62
  };
63
 
 
 
 
 
 
 
 
64
  const sendMessage = async () => {
65
  if (!message.value.trim()) return;
66
  const userMsg = { role: 'user', content: message.value };
@@ -95,7 +107,7 @@
95
  loading.value = false;
96
  };
97
 
98
- return { message, history, sendMessage, renderCode, loading, chatbox };
99
  }
100
  }).mount('#app');
101
 
 
15
 
16
  <div class="chat-box" ref="chatbox">
17
  <div v-for="(msg, i) in history" :key="i" class="message" :class="msg.role">
18
+ <template v-if="msg.role === 'assistant' && msg.content.includes('```')">
19
+ <div v-html="renderCode(msg.content)"></div>
20
+ </template>
21
+ <template v-else>
22
+ <div class="text-content" v-html="formatText(msg.content)"></div>
23
+ </template>
24
  </div>
25
 
26
  <div v-if="loading" class="typing-indicator">
27
+ <span class="dot"></span><span class="dot"></span><span class="dot"></span>
 
 
28
  </div>
29
  </div>
30
 
 
54
  const match = text.match(/```([^]*)```/);
55
  if (!match) return text;
56
  const code = match[1].trim();
57
+ const highlighted = hljs.highlightAuto(code).value;
58
+
59
  return `
60
  <div class="code-block">
61
+ <div class="code-toolbar">
62
+ <button class="copy-btn" onclick="copyToClipboard(\`${code.replace(/`/g, '\\`')}\`, this)">Copy</button>
63
+ </div>
64
+ <pre><code class="hljs">${highlighted}</code></pre>
65
  </div>
66
  `;
67
  };
68
 
69
+ const formatText = (text) => {
70
+ return text
71
+ .replace(/\n/g, "<br>")
72
+ .replace(/\*\*(.*?)\*\*/g, "<strong>$1</strong>")
73
+ .replace(/\*(.*?)\*/g, "<em>$1</em>");
74
+ };
75
+
76
  const sendMessage = async () => {
77
  if (!message.value.trim()) return;
78
  const userMsg = { role: 'user', content: message.value };
 
107
  loading.value = false;
108
  };
109
 
110
+ return { message, history, sendMessage, renderCode, formatText, loading, chatbox };
111
  }
112
  }).mount('#app');
113