-
Notifications
You must be signed in to change notification settings - Fork 50
/
index.html.prompt.txt
363 lines (303 loc) · 14 KB
/
index.html.prompt.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
claude-3-5-sonnet-20240620
You are an expert in Web development, including CSS, JavaScript, React, Tailwind, Node.JS and Hugo / Markdown. You are expert at selecting and choosing the best tools, and doing your utmost to avoid unnecessary duplication and complexity.
When making a suggestion, you break things down in to discrete changes, and suggest a small test after each stage to make sure things are on the right track.
Produce code to illustrate examples, or when directed to in the conversation. If you can answer without code, that is preferred, and you will be asked to elaborate if it is required.
Before writing or suggesting code, you conduct a deep-dive review of the existing code and describe how it works between <CODE_REVIEW> tags. Once you have completed the review, you produce a careful plan for the change in <PLANNING> tags. Pay attention to variable names and string literals - when reproducing code make sure that these do not change unless necessary or directed. If naming something by convention surround in double colons and in ::UPPERCASE::.
Finally, you produce correct outputs that provide the right balance between solving the immediate problem and remaining generic and flexible.
You always ask for clarifications if anything is unclear or ambiguous. You stop to discuss trade-offs and implementation options if there are choices to make.
It is important that you follow this approach, and do your best to teach your interlocutor about making effective decisions. You avoid apologising unnecessarily, and review the conversation to never repeat earlier mistakes.
You are keenly aware of security, and make sure at every step that we don't do anything that could compromise data or introduce new vulnerabilities. Whenever there is a potential security risk (e.g. input handling, authentication management) you will do an additional review, showing your reasoning between <SECURITY_REVIEW> tags.
Finally, it is important that everything produced is operationally sound. We consider how to host, manage, monitor and maintain our solutions. You consider operational concerns at every step, and highlight them where they are relevant.
Bonus: if you can use 3djs or WebGL anywhere need a render or dashboard, use it.
Assume the server is already running at `localhost:9079`, generate html code that connects to the server.
Final html code should be included in <INDEX_HTML_CODE></INDEX_HTML_CODE> block.
=== 0: user ===
Generate "server.py". Backend design:
```
The backend will be a Python Flask server with the following components:
1. Main Flask app:
- Import necessary libraries (Flask, difflib)
- Create Flask app instance
2. Route: "/"
- Serve the main HTML page
3. Route: "/compare" (POST method)
- Receive two texts from the frontend
- Use difflib to compare the texts and generate HTML diff
- Return the HTML diff to the frontend
4. Helper function: generate_diff(text1, text2)
- Use difflib.HtmlDiff().make_file() to create an HTML diff
- Customize the output to make it more visually appealing
5. Run the Flask app
The server will use the difflib library to generate a colorized HTML diff between the two input texts. This diff will highlight additions, deletions, and changes between the two versions.
```
=== 1: assistant ===
Certainly! I'll create a "server.py" file based on your backend design specifications. Here's the Python code for the Flask server:
<SERVER_PYTHON_CODE>
from flask import Flask, request, jsonify, send_from_directory
from flask_cors import CORS
import difflib
import os
app = Flask(__name__)
CORS(app)
@app.route('/')
def serve_html():
return send_from_directory('.', 'index.html')
@app.route('/compare', methods=['POST'])
def compare_texts():
data = request.json
text1 = data.get('text1', '')
text2 = data.get('text2', '')
diff_html = generate_diff(text1, text2)
return jsonify({'diff': diff_html})
def generate_diff(text1, text2):
differ = difflib.HtmlDiff(wrapcolumn=70)
diff = differ.make_file(text1.splitlines(), text2.splitlines())
# Customize the diff output
custom_diff = diff.replace(
'<table class="diff" id="difflib_chg_to0__top"',
'<table class="diff" id="difflib_chg_to0__top" style="width:100%; border-collapse: collapse;"'
)
custom_diff = custom_diff.replace(
'<td class="diff_header"',
'<td class="diff_header" style="padding: 5px; text-align: right; width: 40px; background-color: #f0f0f0;"'
)
custom_diff = custom_diff.replace(
'<td nowrap="nowrap"',
'<td nowrap="nowrap" style="padding: 5px; white-space: pre-wrap; font-family: monospace;"'
)
return custom_diff
if __name__ == '__main__':
app.run(host='localhost', port=9079, debug=True)
</SERVER_PYTHON_CODE>
This "server.py" file implements the backend design you specified. Here's a breakdown of the components:
1. Main Flask app:
- We import the necessary libraries: Flask, jsonify, request, send_from_directory, CORS, and difflib.
- We create a Flask app instance and enable CORS.
2. Route: "/"
- The root route serves the main HTML page (assuming there's an index.html file in the same directory).
3. Route: "/compare" (POST method)
- This route receives two texts from the frontend via a POST request.
- It calls the generate_diff function to create an HTML diff.
- The HTML diff is returned to the frontend as JSON.
4. Helper function: generate_diff(text1, text2)
- This function uses difflib.HtmlDiff().make_file() to create an HTML diff.
- The output is customized to make it more visually appealing by adding inline styles.
5. Run the Flask app
- The app is set to run on localhost:9079 in debug mode.
To use this server:
1. Save this code as "server.py" in your project directory.
2. Make sure you have Flask and flask-cors installed (`pip install flask flask-cors`).
3. Run the server using `python server.py`.
The server will start on http://localhost:9079. You can then send POST requests to the "/compare" endpoint with JSON data containing "text1" and "text2" to get the HTML diff.
Note that this server expects an "index.html" file in the same directory to serve the main page. You'll need to create that file separately or modify the root route to serve your frontend content as needed.
=== 2: user ===
Generate "index.html" that connect to the server. The "index.html" design:
```
The frontend will be a single HTML page with embedded CSS and JavaScript:
1. HTML structure:
- Title: "Text Comparison Tool"
- Two large text areas for input:
- Left: "Original Text"
- Right: "Modified Text"
- "Compare" button
- Result area to display the diff
2. CSS styling:
- Modern, clean design with a color scheme (e.g., blue and white)
- Responsive layout for various screen sizes
- Styled text areas and button
- Custom styling for diff output (highlighted additions and deletions)
3. JavaScript functionality:
- Event listener for the "Compare" button
- AJAX call to send texts to the backend "/compare" route
- Function to display the returned HTML diff in the result area
- Error handling for failed requests or empty inputs
4. Additional features:
- "Clear" button to reset both text areas
- "Swap" button to switch the contents of the two text areas
- Loading spinner while waiting for the comparison result
The frontend will provide an intuitive interface for users to input their texts, initiate the comparison, and view the results in a visually appealing manner.
```
=== Reply 0 ===
Certainly! I'll create an "index.html" file that connects to the server based on your design specifications. Here's the HTML code with embedded CSS and JavaScript:
<INDEX_HTML_CODE>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Text Comparison Tool</title>
<style>
body {
font-family: Arial, sans-serif;
line-height: 1.6;
color: #333;
max-width: 1200px;
margin: 0 auto;
padding: 20px;
background-color: #f4f4f4;
}
h1 {
text-align: center;
color: #2c3e50;
}
.container {
display: flex;
flex-wrap: wrap;
gap: 20px;
}
.text-area {
flex: 1 1 45%;
min-width: 300px;
}
textarea {
width: 100%;
height: 300px;
padding: 10px;
border: 1px solid #ddd;
border-radius: 5px;
resize: vertical;
}
.buttons {
display: flex;
justify-content: center;
gap: 10px;
margin: 20px 0;
}
button {
padding: 10px 20px;
background-color: #3498db;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s;
}
button:hover {
background-color: #2980b9;
}
#result {
background-color: white;
padding: 20px;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0,0,0,0.1);
}
.spinner {
display: none;
width: 50px;
height: 50px;
border: 3px solid #f3f3f3;
border-top: 3px solid #3498db;
border-radius: 50%;
animation: spin 1s linear infinite;
margin: 20px auto;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
@media (max-width: 768px) {
.text-area {
flex: 1 1 100%;
}
}
</style>
</head>
<body>
<h1>Text Comparison Tool</h1>
<div class="container">
<div class="text-area">
<h2>Original Text</h2>
<textarea id="text1" placeholder="Enter original text here..."></textarea>
</div>
<div class="text-area">
<h2>Modified Text</h2>
<textarea id="text2" placeholder="Enter modified text here..."></textarea>
</div>
</div>
<div class="buttons">
<button id="compareBtn">Compare</button>
<button id="clearBtn">Clear</button>
<button id="swapBtn">Swap</button>
</div>
<div class="spinner" id="spinner"></div>
<div id="result"></div>
<script>
const text1 = document.getElementById('text1');
const text2 = document.getElementById('text2');
const compareBtn = document.getElementById('compareBtn');
const clearBtn = document.getElementById('clearBtn');
const swapBtn = document.getElementById('swapBtn');
const result = document.getElementById('result');
const spinner = document.getElementById('spinner');
compareBtn.addEventListener('click', compareTexts);
clearBtn.addEventListener('click', clearTexts);
swapBtn.addEventListener('click', swapTexts);
function compareTexts() {
const originalText = text1.value.trim();
const modifiedText = text2.value.trim();
if (!originalText || !modifiedText) {
alert('Please enter both original and modified texts.');
return;
}
spinner.style.display = 'block';
result.innerHTML = '';
fetch('http://localhost:9079/compare', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ text1: originalText, text2: modifiedText }),
})
.then(response => response.json())
.then(data => {
spinner.style.display = 'none';
result.innerHTML = data.diff;
})
.catch(error => {
spinner.style.display = 'none';
console.error('Error:', error);
result.innerHTML = 'An error occurred while comparing the texts. Please try again.';
});
}
function clearTexts() {
text1.value = '';
text2.value = '';
result.innerHTML = '';
}
function swapTexts() {
const temp = text1.value;
text1.value = text2.value;
text2.value = temp;
}
</script>
</body>
</html>
</INDEX_HTML_CODE>
This "index.html" file implements the frontend design you specified. Here's a breakdown of the components:
1. HTML structure:
- Title: "Text Comparison Tool"
- Two large text areas for input: "Original Text" and "Modified Text"
- "Compare", "Clear", and "Swap" buttons
- Result area to display the diff
- Loading spinner
2. CSS styling:
- Modern, clean design with a blue and white color scheme
- Responsive layout using flexbox
- Styled text areas and buttons
- Custom styling for the result area
- Loading spinner animation
3. JavaScript functionality:
- Event listeners for the "Compare", "Clear", and "Swap" buttons
- AJAX call using fetch() to send texts to the backend "/compare" route
- Function to display the returned HTML diff in the result area
- Error handling for failed requests or empty inputs
4. Additional features:
- "Clear" button to reset both text areas
- "Swap" button to switch the contents of the two text areas
- Loading spinner while waiting for the comparison result
This frontend provides an intuitive interface for users to input their texts, initiate the comparison, and view the results in a visually appealing manner. It connects to the server running at http://localhost:9079 and sends POST requests to the "/compare" endpoint.
To use this frontend:
1. Save this code as "index.html" in the same directory as your "server.py" file.
2. Make sure your Flask server is running (python server.py).
3. Open the "index.html" file in a web browser.
You should now have a fully functional Text Comparison Tool that connects to your Flask backend and provides a user-friendly interface for comparing texts.