forked from Ziyad-Firos/Efficode-ACRR
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_interface.html
More file actions
363 lines (333 loc) Β· 11.9 KB
/
Copy pathtest_interface.html
File metadata and controls
363 lines (333 loc) Β· 11.9 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>EFFICODE - AI Code Optimizer</title>
<style>
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
max-width: 1200px;
margin: 0 auto;
padding: 20px;
background-color: #f5f5f5;
}
.container {
background: white;
border-radius: 10px;
padding: 30px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}
h1 {
color: #2c3e50;
text-align: center;
margin-bottom: 30px;
}
.input-section, .output-section {
margin-bottom: 30px;
}
label {
display: block;
margin-bottom: 10px;
font-weight: bold;
color: #34495e;
}
textarea {
width: 100%;
height: 200px;
padding: 15px;
border: 2px solid #ddd;
border-radius: 5px;
font-family: 'Courier New', monospace;
font-size: 14px;
resize: vertical;
}
textarea:focus {
border-color: #3498db;
outline: none;
}
.controls {
display: flex;
gap: 15px;
align-items: center;
margin: 20px 0;
}
select, button {
padding: 10px 20px;
border: 2px solid #ddd;
border-radius: 5px;
font-size: 14px;
}
button {
background-color: #3498db;
color: white;
border-color: #3498db;
cursor: pointer;
font-weight: bold;
}
button:hover {
background-color: #2980b9;
border-color: #2980b9;
}
button:disabled {
background-color: #bdc3c7;
border-color: #bdc3c7;
cursor: not-allowed;
}
.results {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 20px;
margin-top: 20px;
}
.result-panel {
border: 2px solid #ddd;
border-radius: 5px;
padding: 15px;
}
.result-panel h3 {
margin-top: 0;
color: #2c3e50;
}
.optimized {
border-color: #27ae60;
}
.optimized h3 {
color: #27ae60;
}
.complexity-info {
background-color: #ecf0f1;
padding: 15px;
border-radius: 5px;
margin: 15px 0;
}
.improvements {
background-color: #e8f5e8;
padding: 15px;
border-radius: 5px;
margin: 15px 0;
}
.improvement-item {
margin-bottom: 10px;
padding: 8px;
background-color: white;
border-radius: 3px;
border-left: 4px solid #27ae60;
}
.error {
background-color: #f8d7da;
color: #721c24;
padding: 15px;
border-radius: 5px;
margin: 15px 0;
}
.loading {
text-align: center;
color: #7f8c8d;
font-style: italic;
}
pre {
background-color: #f8f9fa;
padding: 15px;
border-radius: 5px;
overflow-x: auto;
font-size: 13px;
line-height: 1.4;
}
.example-buttons {
display: flex;
gap: 10px;
margin-bottom: 15px;
flex-wrap: wrap;
}
.example-btn {
padding: 8px 15px;
background-color: #f8f9fa;
border: 1px solid #ddd;
border-radius: 3px;
cursor: pointer;
font-size: 12px;
}
.example-btn:hover {
background-color: #e9ecef;
}
</style>
</head>
<body>
<div class="container">
<h1>π§ EFFICODE - AI-Powered Python Code Optimizer</h1>
<div class="input-section">
<label for="code-input">Enter your Python code:</label>
<div class="example-buttons">
<button class="example-btn" onclick="loadExample('fibonacci')">Fibonacci Example</button>
<button class="example-btn" onclick="loadExample('constants')">Constant Folding</button>
<button class="example-btn" onclick="loadExample('bubble_sort')">Bubble Sort</button>
<button class="example-btn" onclick="loadExample('linear_search')">Linear Search</button>
</div>
<textarea id="code-input" placeholder="def fibonacci(n):
if n <= 0:
return 0
elif n == 1:
return 1
else:
return fibonacci(n-1) + fibonacci(n-2)"></textarea>
</div>
<div class="controls">
<label for="optimization-level">Optimization Level:</label>
<select id="optimization-level">
<option value="low">Low</option>
<option value="medium" selected>Medium</option>
<option value="high">High</option>
</select>
<button id="optimize-btn" onclick="optimizeCode()">π Optimize Code</button>
</div>
<div id="results-container" style="display: none;">
<div class="results">
<div class="result-panel">
<h3>π Original Code</h3>
<pre id="original-code"></pre>
<div class="complexity-info">
<strong>Complexity:</strong> <span id="original-complexity">-</span>
</div>
</div>
<div class="result-panel optimized">
<h3>β‘ Optimized Code</h3>
<pre id="optimized-code"></pre>
<div class="complexity-info">
<strong>Complexity:</strong> <span id="optimized-complexity">-</span>
</div>
</div>
</div>
<div class="improvements" id="improvements-section">
<h3>π― Applied Optimizations</h3>
<div id="improvements-list"></div>
</div>
<div class="complexity-info">
<h3>π Explanation</h3>
<p id="explanation"></p>
</div>
</div>
<div id="loading" class="loading" style="display: none;">
<p>π Optimizing your code...</p>
</div>
<div id="error" class="error" style="display: none;"></div>
</div>
<script>
const examples = {
fibonacci: `def fibonacci(n):
if n <= 0:
return 0
elif n == 1:
return 1
else:
return fibonacci(n-1) + fibonacci(n-2)`,
constants: `def test_constant_folding():
x = 2 * 3 + 4 # Should be folded to 10
y = 10 / 2 # Should be folded to 5.0
z = 2 ** 8 # Should be folded to 256
return x + y + z`,
bubble_sort: `def bubble_sort(arr):
n = len(arr)
for i in range(n):
for j in range(0, n - i - 1):
if arr[j] > arr[j + 1]:
arr[j], arr[j + 1] = arr[j + 1], arr[j]
return arr`,
linear_search: `def linear_search(arr, target):
for i in range(len(arr)):
if arr[i] == target:
return i
return -1`
};
function loadExample(exampleName) {
const codeInput = document.getElementById('code-input');
codeInput.value = examples[exampleName];
}
async function optimizeCode() {
const codeInput = document.getElementById('code-input');
const optimizationLevel = document.getElementById('optimization-level');
const optimizeBtn = document.getElementById('optimize-btn');
const loading = document.getElementById('loading');
const error = document.getElementById('error');
const resultsContainer = document.getElementById('results-container');
const code = codeInput.value.trim();
if (!code) {
showError('Please enter some Python code to optimize.');
return;
}
// Show loading state
optimizeBtn.disabled = true;
loading.style.display = 'block';
error.style.display = 'none';
resultsContainer.style.display = 'none';
try {
const response = await fetch('http://localhost:5000/optimize', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
code: code,
level: optimizationLevel.value
})
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const result = await response.json();
if (result.status === 'error') {
throw new Error(result.error || 'Unknown error occurred');
}
displayResults(result);
} catch (err) {
console.error('Optimization error:', err);
showError(`Failed to optimize code: ${err.message}`);
} finally {
optimizeBtn.disabled = false;
loading.style.display = 'none';
}
}
function displayResults(result) {
// Show results container
document.getElementById('results-container').style.display = 'block';
// Display code
document.getElementById('original-code').textContent = result.original_code;
document.getElementById('optimized-code').textContent = result.optimized_code;
// Display complexity
document.getElementById('original-complexity').textContent = result.original_complexity || 'Unknown';
document.getElementById('optimized-complexity').textContent = result.optimized_complexity || 'Unknown';
// Display explanation
document.getElementById('explanation').textContent = result.explanation || 'No explanation available.';
// Display improvements
const improvementsList = document.getElementById('improvements-list');
improvementsList.innerHTML = '';
if (result.improvements && result.improvements.length > 0) {
result.improvements.forEach(improvement => {
const div = document.createElement('div');
div.className = 'improvement-item';
div.innerHTML = `
<strong>${improvement.type || 'Optimization'}:</strong>
${improvement.description || 'No description available'}
<small style="color: #666; display: block; margin-top: 5px;">
Category: ${improvement.category || 'general'}
</small>
`;
improvementsList.appendChild(div);
});
} else {
improvementsList.innerHTML = '<p>No specific optimizations were applied to this code.</p>';
}
}
function showError(message) {
const errorDiv = document.getElementById('error');
errorDiv.textContent = message;
errorDiv.style.display = 'block';
document.getElementById('results-container').style.display = 'none';
}
// Load default example on page load
window.onload = function() {
loadExample('fibonacci');
};
</script>
</body>
</html>