Spaces:
Running
Running
Add 3 files
Browse files- README.md +6 -4
- index.html +509 -19
- prompts.txt +1 -0
README.md
CHANGED
|
@@ -1,10 +1,12 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
colorFrom: green
|
| 5 |
-
colorTo:
|
| 6 |
sdk: static
|
| 7 |
pinned: false
|
|
|
|
|
|
|
| 8 |
---
|
| 9 |
|
| 10 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 1 |
---
|
| 2 |
+
title: code-creator
|
| 3 |
+
emoji: 🐳
|
| 4 |
colorFrom: green
|
| 5 |
+
colorTo: yellow
|
| 6 |
sdk: static
|
| 7 |
pinned: false
|
| 8 |
+
tags:
|
| 9 |
+
- deepsite
|
| 10 |
---
|
| 11 |
|
| 12 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
index.html
CHANGED
|
@@ -1,19 +1,509 @@
|
|
| 1 |
-
<!
|
| 2 |
-
<html>
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Code Corrector & Modifier</title>
|
| 7 |
+
<script src="https://cdn.tailwindcss.com"></script>
|
| 8 |
+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
|
| 9 |
+
<style>
|
| 10 |
+
.code-editor {
|
| 11 |
+
font-family: 'Fira Code', 'Courier New', monospace;
|
| 12 |
+
font-size: 14px;
|
| 13 |
+
line-height: 1.5;
|
| 14 |
+
}
|
| 15 |
+
.suggestion-highlight {
|
| 16 |
+
background-color: rgba(255, 255, 0, 0.3);
|
| 17 |
+
border-bottom: 2px dashed orange;
|
| 18 |
+
}
|
| 19 |
+
.diff-added {
|
| 20 |
+
background-color: rgba(0, 255, 0, 0.2);
|
| 21 |
+
}
|
| 22 |
+
.diff-removed {
|
| 23 |
+
background-color: rgba(255, 0, 0, 0.2);
|
| 24 |
+
text-decoration: line-through;
|
| 25 |
+
}
|
| 26 |
+
.tab-button.active {
|
| 27 |
+
border-bottom: 3px solid #3b82f6;
|
| 28 |
+
color: #3b82f6;
|
| 29 |
+
font-weight: 600;
|
| 30 |
+
}
|
| 31 |
+
#editor {
|
| 32 |
+
height: 400px;
|
| 33 |
+
}
|
| 34 |
+
#suggestions-container {
|
| 35 |
+
max-height: 300px;
|
| 36 |
+
overflow-y: auto;
|
| 37 |
+
}
|
| 38 |
+
</style>
|
| 39 |
+
</head>
|
| 40 |
+
<body class="bg-gray-100">
|
| 41 |
+
<div class="container mx-auto px-4 py-8">
|
| 42 |
+
<div class="bg-white rounded-xl shadow-lg overflow-hidden">
|
| 43 |
+
<!-- Header -->
|
| 44 |
+
<div class="bg-gradient-to-r from-blue-600 to-indigo-700 p-6 text-white">
|
| 45 |
+
<div class="flex justify-between items-center">
|
| 46 |
+
<div>
|
| 47 |
+
<h1 class="text-2xl font-bold"><i class="fas fa-code mr-3"></i>Code Corrector & Modifier</h1>
|
| 48 |
+
<p class="mt-2 opacity-90">Analyze, correct and improve your code with AI assistance</p>
|
| 49 |
+
</div>
|
| 50 |
+
<div class="flex space-x-2">
|
| 51 |
+
<button id="analyze-btn" class="bg-white text-blue-600 px-4 py-2 rounded-lg font-medium hover:bg-blue-50 transition flex items-center">
|
| 52 |
+
<i class="fas fa-magic mr-2"></i> Analyze Code
|
| 53 |
+
</button>
|
| 54 |
+
<button id="export-btn" class="bg-blue-800 text-white px-4 py-2 rounded-lg font-medium hover:bg-blue-900 transition flex items-center">
|
| 55 |
+
<i class="fas fa-file-export mr-2"></i> Export
|
| 56 |
+
</button>
|
| 57 |
+
</div>
|
| 58 |
+
</div>
|
| 59 |
+
</div>
|
| 60 |
+
|
| 61 |
+
<!-- Main Content -->
|
| 62 |
+
<div class="grid grid-cols-1 lg:grid-cols-3 gap-6 p-6">
|
| 63 |
+
<!-- Left Column - Code Editor -->
|
| 64 |
+
<div class="lg:col-span-2 space-y-4">
|
| 65 |
+
<div class="flex border-b">
|
| 66 |
+
<button class="tab-button active px-4 py-2" data-tab="editor">Editor</button>
|
| 67 |
+
<button class="tab-button px-4 py-2" data-tab="diff">Diff View</button>
|
| 68 |
+
<button class="tab-button px-4 py-2" data-tab="preview">Preview</button>
|
| 69 |
+
</div>
|
| 70 |
+
|
| 71 |
+
<div id="editor-tab" class="tab-content">
|
| 72 |
+
<div class="border rounded-lg overflow-hidden">
|
| 73 |
+
<div class="bg-gray-800 text-white px-4 py-2 flex justify-between items-center">
|
| 74 |
+
<div class="flex items-center">
|
| 75 |
+
<i class="fas fa-file-code mr-2"></i>
|
| 76 |
+
<span>main.js</span>
|
| 77 |
+
</div>
|
| 78 |
+
<div class="flex space-x-2">
|
| 79 |
+
<button class="text-gray-300 hover:text-white" title="Format Code">
|
| 80 |
+
<i class="fas fa-align-left"></i>
|
| 81 |
+
</button>
|
| 82 |
+
<button class="text-gray-300 hover:text-white" title="Settings">
|
| 83 |
+
<i class="fas fa-cog"></i>
|
| 84 |
+
</button>
|
| 85 |
+
</div>
|
| 86 |
+
</div>
|
| 87 |
+
<textarea id="editor" class="w-full p-4 code-editor bg-gray-900 text-gray-100 outline-none resize-none" spellcheck="false">// Sample code to analyze
|
| 88 |
+
function calculateTotal(items, taxRate) {
|
| 89 |
+
let total = 0;
|
| 90 |
+
for (let i = 0; i < items.length; i++) {
|
| 91 |
+
total += items[i].price;
|
| 92 |
+
}
|
| 93 |
+
total += total * taxRate;
|
| 94 |
+
return total;
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
const items = [
|
| 98 |
+
{ name: 'Book', price: 15 },
|
| 99 |
+
{ name: 'Pen', price: 3.5 },
|
| 100 |
+
{ name: 'Notebook', price: 8 }
|
| 101 |
+
];
|
| 102 |
+
|
| 103 |
+
const totalWithTax = calculateTotal(items, 0.1);
|
| 104 |
+
console.log('Total with tax:', totalWithTax);</textarea>
|
| 105 |
+
</div>
|
| 106 |
+
</div>
|
| 107 |
+
|
| 108 |
+
<div id="diff-tab" class="tab-content hidden">
|
| 109 |
+
<div class="border rounded-lg overflow-hidden">
|
| 110 |
+
<div class="bg-gray-800 text-white px-4 py-2">
|
| 111 |
+
<i class="fas fa-code-compare mr-2"></i>
|
| 112 |
+
<span>Code Differences</span>
|
| 113 |
+
</div>
|
| 114 |
+
<div id="diff-view" class="p-4 bg-gray-100 text-gray-800 code-editor whitespace-pre">
|
| 115 |
+
<!-- Diff content will be inserted here by JavaScript -->
|
| 116 |
+
</div>
|
| 117 |
+
</div>
|
| 118 |
+
</div>
|
| 119 |
+
|
| 120 |
+
<div id="preview-tab" class="tab-content hidden">
|
| 121 |
+
<div class="border rounded-lg overflow-hidden">
|
| 122 |
+
<div class="bg-gray-800 text-white px-4 py-2">
|
| 123 |
+
<i class="fas fa-eye mr-2"></i>
|
| 124 |
+
<span>Code Preview</span>
|
| 125 |
+
</div>
|
| 126 |
+
<div id="preview-content" class="p-4 bg-gray-100 text-gray-800 code-editor">
|
| 127 |
+
<!-- Preview content will be inserted here by JavaScript -->
|
| 128 |
+
</div>
|
| 129 |
+
</div>
|
| 130 |
+
</div>
|
| 131 |
+
</div>
|
| 132 |
+
|
| 133 |
+
<!-- Right Column - Suggestions -->
|
| 134 |
+
<div class="space-y-4">
|
| 135 |
+
<div class="bg-white border rounded-lg overflow-hidden">
|
| 136 |
+
<div class="bg-gray-100 px-4 py-3 border-b flex justify-between items-center">
|
| 137 |
+
<h3 class="font-semibold text-gray-800">
|
| 138 |
+
<i class="fas fa-lightbulb mr-2 text-yellow-500"></i> Suggestions
|
| 139 |
+
</h3>
|
| 140 |
+
<div class="flex items-center space-x-2">
|
| 141 |
+
<span class="text-xs bg-blue-100 text-blue-800 px-2 py-1 rounded-full" id="suggestion-count">0</span>
|
| 142 |
+
<button id="apply-all-btn" class="text-xs bg-green-100 text-green-800 px-2 py-1 rounded hover:bg-green-200 transition">
|
| 143 |
+
Apply All
|
| 144 |
+
</button>
|
| 145 |
+
</div>
|
| 146 |
+
</div>
|
| 147 |
+
<div id="suggestions-container" class="p-4">
|
| 148 |
+
<div class="text-center text-gray-500 py-8" id="no-suggestions">
|
| 149 |
+
<i class="fas fa-comment-dots text-3xl mb-2"></i>
|
| 150 |
+
<p>No suggestions yet. Click "Analyze Code" to get started.</p>
|
| 151 |
+
</div>
|
| 152 |
+
<!-- Suggestions will be inserted here by JavaScript -->
|
| 153 |
+
</div>
|
| 154 |
+
</div>
|
| 155 |
+
|
| 156 |
+
<div class="bg-white border rounded-lg overflow-hidden">
|
| 157 |
+
<div class="bg-gray-100 px-4 py-3 border-b">
|
| 158 |
+
<h3 class="font-semibold text-gray-800">
|
| 159 |
+
<i class="fas fa-chart-line mr-2 text-purple-500"></i> Code Metrics
|
| 160 |
+
</h3>
|
| 161 |
+
</div>
|
| 162 |
+
<div class="p-4">
|
| 163 |
+
<div class="grid grid-cols-2 gap-4">
|
| 164 |
+
<div class="bg-blue-50 p-3 rounded-lg">
|
| 165 |
+
<div class="text-blue-800 font-medium">Lines of Code</div>
|
| 166 |
+
<div class="text-2xl font-bold" id="loc-metric">-</div>
|
| 167 |
+
</div>
|
| 168 |
+
<div class="bg-green-50 p-3 rounded-lg">
|
| 169 |
+
<div class="text-green-800 font-medium">Complexity</div>
|
| 170 |
+
<div class="text-2xl font-bold" id="complexity-metric">-</div>
|
| 171 |
+
</div>
|
| 172 |
+
<div class="bg-purple-50 p-3 rounded-lg">
|
| 173 |
+
<div class="text-purple-800 font-medium">Issues</div>
|
| 174 |
+
<div class="text-2xl font-bold" id="issues-metric">0</div>
|
| 175 |
+
</div>
|
| 176 |
+
<div class="bg-yellow-50 p-3 rounded-lg">
|
| 177 |
+
<div class="text-yellow-800 font-medium">Readability</div>
|
| 178 |
+
<div class="text-2xl font-bold" id="readability-metric">-</div>
|
| 179 |
+
</div>
|
| 180 |
+
</div>
|
| 181 |
+
</div>
|
| 182 |
+
</div>
|
| 183 |
+
</div>
|
| 184 |
+
</div>
|
| 185 |
+
</div>
|
| 186 |
+
</div>
|
| 187 |
+
|
| 188 |
+
<script>
|
| 189 |
+
document.addEventListener('DOMContentLoaded', function() {
|
| 190 |
+
// Tab switching
|
| 191 |
+
const tabButtons = document.querySelectorAll('.tab-button');
|
| 192 |
+
tabButtons.forEach(button => {
|
| 193 |
+
button.addEventListener('click', () => {
|
| 194 |
+
// Remove active class from all buttons
|
| 195 |
+
tabButtons.forEach(btn => btn.classList.remove('active'));
|
| 196 |
+
// Add active class to clicked button
|
| 197 |
+
button.classList.add('active');
|
| 198 |
+
|
| 199 |
+
// Hide all tab contents
|
| 200 |
+
document.querySelectorAll('.tab-content').forEach(tab => {
|
| 201 |
+
tab.classList.add('hidden');
|
| 202 |
+
});
|
| 203 |
+
|
| 204 |
+
// Show the selected tab content
|
| 205 |
+
const tabId = button.getAttribute('data-tab') + '-tab';
|
| 206 |
+
document.getElementById(tabId).classList.remove('hidden');
|
| 207 |
+
});
|
| 208 |
+
});
|
| 209 |
+
|
| 210 |
+
// Analyze button click handler
|
| 211 |
+
document.getElementById('analyze-btn').addEventListener('click', analyzeCode);
|
| 212 |
+
|
| 213 |
+
// Apply all button click handler
|
| 214 |
+
document.getElementById('apply-all-btn').addEventListener('click', applyAllSuggestions);
|
| 215 |
+
|
| 216 |
+
// Export button click handler
|
| 217 |
+
document.getElementById('export-btn').addEventListener('click', exportCode);
|
| 218 |
+
|
| 219 |
+
// Sample suggestions data (in a real app, this would come from an API)
|
| 220 |
+
const sampleSuggestions = [
|
| 221 |
+
{
|
| 222 |
+
id: 1,
|
| 223 |
+
title: "Use Array.reduce() instead of for loop",
|
| 224 |
+
description: "The for loop can be replaced with Array.reduce() for more concise and functional code.",
|
| 225 |
+
category: "Best Practice",
|
| 226 |
+
severity: "medium",
|
| 227 |
+
line: 3,
|
| 228 |
+
codeBefore: "let total = 0;\nfor (let i = 0; i < items.length; i++) {\n total += items[i].price;\n}",
|
| 229 |
+
codeAfter: "const total = items.reduce((sum, item) => sum + item.price, 0);",
|
| 230 |
+
applied: false
|
| 231 |
+
},
|
| 232 |
+
{
|
| 233 |
+
id: 2,
|
| 234 |
+
title: "Use const instead of let for total",
|
| 235 |
+
description: "Since total is not reassigned after initialization, it's better to use const.",
|
| 236 |
+
category: "Code Style",
|
| 237 |
+
severity: "low",
|
| 238 |
+
line: 2,
|
| 239 |
+
codeBefore: "let total = 0;",
|
| 240 |
+
codeAfter: "const total = 0;",
|
| 241 |
+
applied: false
|
| 242 |
+
},
|
| 243 |
+
{
|
| 244 |
+
id: 3,
|
| 245 |
+
title: "Add input validation",
|
| 246 |
+
description: "Consider adding validation for items and taxRate parameters to prevent runtime errors.",
|
| 247 |
+
category: "Error Prevention",
|
| 248 |
+
severity: "high",
|
| 249 |
+
line: 1,
|
| 250 |
+
codeBefore: "function calculateTotal(items, taxRate) {",
|
| 251 |
+
codeAfter: "function calculateTotal(items = [], taxRate = 0) {\n if (!Array.isArray(items)) throw new Error('Items must be an array');\n if (typeof taxRate !== 'number') throw new Error('Tax rate must be a number');",
|
| 252 |
+
applied: false
|
| 253 |
+
}
|
| 254 |
+
];
|
| 255 |
+
|
| 256 |
+
// Analyze code function
|
| 257 |
+
function analyzeCode() {
|
| 258 |
+
// In a real app, this would send the code to an API for analysis
|
| 259 |
+
// For this demo, we'll use the sample suggestions
|
| 260 |
+
|
| 261 |
+
// Update metrics
|
| 262 |
+
document.getElementById('loc-metric').textContent = document.getElementById('editor').value.split('\n').length;
|
| 263 |
+
document.getElementById('complexity-metric').textContent = "Medium";
|
| 264 |
+
document.getElementById('issues-metric').textContent = sampleSuggestions.length;
|
| 265 |
+
document.getElementById('readability-metric').textContent = "Good";
|
| 266 |
+
|
| 267 |
+
// Display suggestions
|
| 268 |
+
displaySuggestions(sampleSuggestions);
|
| 269 |
+
|
| 270 |
+
// Highlight code lines with suggestions
|
| 271 |
+
highlightCodeLines(sampleSuggestions);
|
| 272 |
+
}
|
| 273 |
+
|
| 274 |
+
// Display suggestions
|
| 275 |
+
function displaySuggestions(suggestions) {
|
| 276 |
+
const container = document.getElementById('suggestions-container');
|
| 277 |
+
const noSuggestions = document.getElementById('no-suggestions');
|
| 278 |
+
|
| 279 |
+
if (suggestions.length === 0) {
|
| 280 |
+
noSuggestions.classList.remove('hidden');
|
| 281 |
+
container.innerHTML = '';
|
| 282 |
+
document.getElementById('suggestion-count').textContent = '0';
|
| 283 |
+
return;
|
| 284 |
+
}
|
| 285 |
+
|
| 286 |
+
noSuggestions.classList.add('hidden');
|
| 287 |
+
container.innerHTML = '';
|
| 288 |
+
document.getElementById('suggestion-count').textContent = suggestions.length;
|
| 289 |
+
|
| 290 |
+
suggestions.forEach(suggestion => {
|
| 291 |
+
const suggestionElement = document.createElement('div');
|
| 292 |
+
suggestionElement.className = `mb-4 pb-4 border-b border-gray-200 ${suggestion.applied ? 'opacity-50' : ''}`;
|
| 293 |
+
suggestionElement.innerHTML = `
|
| 294 |
+
<div class="flex justify-between items-start mb-2">
|
| 295 |
+
<h4 class="font-medium text-gray-800">${suggestion.title}</h4>
|
| 296 |
+
<span class="text-xs px-2 py-1 rounded-full ${
|
| 297 |
+
suggestion.severity === 'high' ? 'bg-red-100 text-red-800' :
|
| 298 |
+
suggestion.severity === 'medium' ? 'bg-yellow-100 text-yellow-800' :
|
| 299 |
+
'bg-blue-100 text-blue-800'
|
| 300 |
+
}">${suggestion.category}</span>
|
| 301 |
+
</div>
|
| 302 |
+
<p class="text-sm text-gray-600 mb-3">${suggestion.description}</p>
|
| 303 |
+
<div class="bg-gray-50 p-2 rounded mb-3 text-sm">
|
| 304 |
+
<div class="text-xs text-gray-500 mb-1">Current:</div>
|
| 305 |
+
<div class="code-editor text-gray-700">${suggestion.codeBefore}</div>
|
| 306 |
+
</div>
|
| 307 |
+
<div class="bg-green-50 p-2 rounded mb-3 text-sm">
|
| 308 |
+
<div class="text-xs text-green-600 mb-1">Suggested:</div>
|
| 309 |
+
<div class="code-editor text-gray-700">${suggestion.codeAfter}</div>
|
| 310 |
+
</div>
|
| 311 |
+
<div class="flex justify-end">
|
| 312 |
+
<button class="text-xs bg-blue-600 text-white px-3 py-1 rounded hover:bg-blue-700 transition apply-suggestion" data-id="${suggestion.id}">
|
| 313 |
+
Apply Suggestion
|
| 314 |
+
</button>
|
| 315 |
+
</div>
|
| 316 |
+
`;
|
| 317 |
+
container.appendChild(suggestionElement);
|
| 318 |
+
});
|
| 319 |
+
|
| 320 |
+
// Add event listeners to apply buttons
|
| 321 |
+
document.querySelectorAll('.apply-suggestion').forEach(button => {
|
| 322 |
+
button.addEventListener('click', function() {
|
| 323 |
+
const suggestionId = parseInt(this.getAttribute('data-id'));
|
| 324 |
+
applySuggestion(suggestionId);
|
| 325 |
+
});
|
| 326 |
+
});
|
| 327 |
+
}
|
| 328 |
+
|
| 329 |
+
// Apply a single suggestion
|
| 330 |
+
function applySuggestion(suggestionId) {
|
| 331 |
+
// In a real app, this would be more sophisticated
|
| 332 |
+
const suggestion = sampleSuggestions.find(s => s.id === suggestionId);
|
| 333 |
+
if (!suggestion || suggestion.applied) return;
|
| 334 |
+
|
| 335 |
+
// Mark as applied
|
| 336 |
+
suggestion.applied = true;
|
| 337 |
+
|
| 338 |
+
// Update the editor content (simplified for demo)
|
| 339 |
+
const editor = document.getElementById('editor');
|
| 340 |
+
let code = editor.value;
|
| 341 |
+
|
| 342 |
+
// Simple replacement (in a real app, this would need proper line/position handling)
|
| 343 |
+
code = code.replace(suggestion.codeBefore, suggestion.codeAfter);
|
| 344 |
+
editor.value = code;
|
| 345 |
+
|
| 346 |
+
// Update the UI
|
| 347 |
+
displaySuggestions(sampleSuggestions);
|
| 348 |
+
updateDiffView();
|
| 349 |
+
updatePreview();
|
| 350 |
+
|
| 351 |
+
// Show success message
|
| 352 |
+
showToast(`Applied suggestion: ${suggestion.title}`, 'success');
|
| 353 |
+
}
|
| 354 |
+
|
| 355 |
+
// Apply all suggestions
|
| 356 |
+
function applyAllSuggestions() {
|
| 357 |
+
sampleSuggestions.forEach(suggestion => {
|
| 358 |
+
if (!suggestion.applied) {
|
| 359 |
+
suggestion.applied = true;
|
| 360 |
+
|
| 361 |
+
// Update the editor content (simplified for demo)
|
| 362 |
+
const editor = document.getElementById('editor');
|
| 363 |
+
let code = editor.value;
|
| 364 |
+
code = code.replace(suggestion.codeBefore, suggestion.codeAfter);
|
| 365 |
+
editor.value = code;
|
| 366 |
+
}
|
| 367 |
+
});
|
| 368 |
+
|
| 369 |
+
// Update the UI
|
| 370 |
+
displaySuggestions(sampleSuggestions);
|
| 371 |
+
updateDiffView();
|
| 372 |
+
updatePreview();
|
| 373 |
+
|
| 374 |
+
// Show success message
|
| 375 |
+
showToast('All suggestions applied successfully', 'success');
|
| 376 |
+
}
|
| 377 |
+
|
| 378 |
+
// Highlight code lines with suggestions
|
| 379 |
+
function highlightCodeLines(suggestions) {
|
| 380 |
+
// In a real app, this would highlight the specific lines in the editor
|
| 381 |
+
// For this demo, we'll just show an alert
|
| 382 |
+
const linesWithIssues = [...new Set(suggestions.map(s => s.line))];
|
| 383 |
+
showToast(`Found issues on lines: ${linesWithIssues.join(', ')}`, 'info');
|
| 384 |
+
}
|
| 385 |
+
|
| 386 |
+
// Update diff view
|
| 387 |
+
function updateDiffView() {
|
| 388 |
+
const originalCode = `// Sample code to analyze
|
| 389 |
+
function calculateTotal(items, taxRate) {
|
| 390 |
+
let total = 0;
|
| 391 |
+
for (let i = 0; i < items.length; i++) {
|
| 392 |
+
total += items[i].price;
|
| 393 |
+
}
|
| 394 |
+
total += total * taxRate;
|
| 395 |
+
return total;
|
| 396 |
+
}
|
| 397 |
+
|
| 398 |
+
const items = [
|
| 399 |
+
{ name: 'Book', price: 15 },
|
| 400 |
+
{ name: 'Pen', price: 3.5 },
|
| 401 |
+
{ name: 'Notebook', price: 8 }
|
| 402 |
+
];
|
| 403 |
+
|
| 404 |
+
const totalWithTax = calculateTotal(items, 0.1);
|
| 405 |
+
console.log('Total with tax:', totalWithTax);`;
|
| 406 |
+
|
| 407 |
+
const currentCode = document.getElementById('editor').value;
|
| 408 |
+
|
| 409 |
+
// Simple diff for demo purposes
|
| 410 |
+
const diffView = document.getElementById('diff-view');
|
| 411 |
+
diffView.innerHTML = '';
|
| 412 |
+
|
| 413 |
+
const originalLines = originalCode.split('\n');
|
| 414 |
+
const currentLines = currentCode.split('\n');
|
| 415 |
+
|
| 416 |
+
const maxLines = Math.max(originalLines.length, currentLines.length);
|
| 417 |
+
|
| 418 |
+
for (let i = 0; i < maxLines; i++) {
|
| 419 |
+
const originalLine = originalLines[i] || '';
|
| 420 |
+
const currentLine = currentLines[i] || '';
|
| 421 |
+
|
| 422 |
+
if (originalLine === currentLine) {
|
| 423 |
+
// No change
|
| 424 |
+
const lineDiv = document.createElement('div');
|
| 425 |
+
lineDiv.textContent = originalLine;
|
| 426 |
+
diffView.appendChild(lineDiv);
|
| 427 |
+
} else {
|
| 428 |
+
// Changed line
|
| 429 |
+
const lineDiv = document.createElement('div');
|
| 430 |
+
lineDiv.className = 'mb-2';
|
| 431 |
+
|
| 432 |
+
if (originalLine) {
|
| 433 |
+
const removedDiv = document.createElement('div');
|
| 434 |
+
removedDiv.className = 'diff-removed text-sm';
|
| 435 |
+
removedDiv.textContent = '- ' + originalLine;
|
| 436 |
+
lineDiv.appendChild(removedDiv);
|
| 437 |
+
}
|
| 438 |
+
|
| 439 |
+
if (currentLine) {
|
| 440 |
+
const addedDiv = document.createElement('div');
|
| 441 |
+
addedDiv.className = 'diff-added text-sm';
|
| 442 |
+
addedDiv.textContent = '+ ' + currentLine;
|
| 443 |
+
lineDiv.appendChild(addedDiv);
|
| 444 |
+
}
|
| 445 |
+
|
| 446 |
+
diffView.appendChild(lineDiv);
|
| 447 |
+
}
|
| 448 |
+
}
|
| 449 |
+
}
|
| 450 |
+
|
| 451 |
+
// Update preview
|
| 452 |
+
function updatePreview() {
|
| 453 |
+
const currentCode = document.getElementById('editor').value;
|
| 454 |
+
const previewContent = document.getElementById('preview-content');
|
| 455 |
+
previewContent.textContent = currentCode;
|
| 456 |
+
}
|
| 457 |
+
|
| 458 |
+
// Export code
|
| 459 |
+
function exportCode() {
|
| 460 |
+
const code = document.getElementById('editor').value;
|
| 461 |
+
const blob = new Blob([code], { type: 'text/javascript' });
|
| 462 |
+
const url = URL.createObjectURL(blob);
|
| 463 |
+
|
| 464 |
+
const a = document.createElement('a');
|
| 465 |
+
a.href = url;
|
| 466 |
+
a.download = 'corrected-code.js';
|
| 467 |
+
a.click();
|
| 468 |
+
|
| 469 |
+
URL.revokeObjectURL(url);
|
| 470 |
+
|
| 471 |
+
showToast('Code exported successfully', 'success');
|
| 472 |
+
}
|
| 473 |
+
|
| 474 |
+
// Show toast notification
|
| 475 |
+
function showToast(message, type) {
|
| 476 |
+
const toast = document.createElement('div');
|
| 477 |
+
toast.className = `fixed bottom-4 right-4 px-4 py-2 rounded-lg shadow-lg text-white ${
|
| 478 |
+
type === 'success' ? 'bg-green-500' :
|
| 479 |
+
type === 'error' ? 'bg-red-500' :
|
| 480 |
+
'bg-blue-500'
|
| 481 |
+
}`;
|
| 482 |
+
toast.innerHTML = `
|
| 483 |
+
<div class="flex items-center">
|
| 484 |
+
<i class="fas ${
|
| 485 |
+
type === 'success' ? 'fa-check-circle' :
|
| 486 |
+
type === 'error' ? 'fa-exclamation-circle' :
|
| 487 |
+
'fa-info-circle'
|
| 488 |
+
} mr-2"></i>
|
| 489 |
+
<span>${message}</span>
|
| 490 |
+
</div>
|
| 491 |
+
`;
|
| 492 |
+
|
| 493 |
+
document.body.appendChild(toast);
|
| 494 |
+
|
| 495 |
+
setTimeout(() => {
|
| 496 |
+
toast.classList.add('opacity-0', 'transition-opacity', 'duration-300');
|
| 497 |
+
setTimeout(() => {
|
| 498 |
+
toast.remove();
|
| 499 |
+
}, 300);
|
| 500 |
+
}, 3000);
|
| 501 |
+
}
|
| 502 |
+
|
| 503 |
+
// Initialize the UI
|
| 504 |
+
updateDiffView();
|
| 505 |
+
updatePreview();
|
| 506 |
+
});
|
| 507 |
+
</script>
|
| 508 |
+
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=docto41/code-creator" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
|
| 509 |
+
</html>
|
prompts.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
https://huggingface.co/spaces/docto41/corriger-et-modifier-code
|