Spaces:
Running
Running
من یک سری کد پایتون دارم . میخوام برات بفرستم ، بررسی کنی و عملکردش و بران توضیح بدی
Browse files- README.md +6 -3
- index.html +267 -18
README.md
CHANGED
|
@@ -1,10 +1,13 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji: 🏃
|
| 4 |
colorFrom: red
|
| 5 |
colorTo: pink
|
|
|
|
| 6 |
sdk: static
|
| 7 |
pinned: false
|
|
|
|
|
|
|
| 8 |
---
|
| 9 |
|
| 10 |
-
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: CodeExplainer Wizard 🧙♂️
|
|
|
|
| 3 |
colorFrom: red
|
| 4 |
colorTo: pink
|
| 5 |
+
emoji: 🐳
|
| 6 |
sdk: static
|
| 7 |
pinned: false
|
| 8 |
+
tags:
|
| 9 |
+
- deepsite-v3
|
| 10 |
---
|
| 11 |
|
| 12 |
+
# Welcome to your new DeepSite project!
|
| 13 |
+
This project was created with [DeepSite](https://deepsite.hf.co).
|
index.html
CHANGED
|
@@ -1,19 +1,268 @@
|
|
| 1 |
-
<!
|
| 2 |
-
<html>
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
</html>
|
|
|
|
| 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>CodeExplainer Wizard</title>
|
| 7 |
+
<link rel="icon" type="image/x-icon" href="/static/favicon.ico">
|
| 8 |
+
<script src="https://cdn.tailwindcss.com"></script>
|
| 9 |
+
<script src="https://unpkg.com/feather-icons"></script>
|
| 10 |
+
<script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
|
| 11 |
+
<style>
|
| 12 |
+
.code-block {
|
| 13 |
+
font-family: 'Courier New', monospace;
|
| 14 |
+
background-color: #1e293b;
|
| 15 |
+
color: #e2e8f0;
|
| 16 |
+
border-radius: 0.5rem;
|
| 17 |
+
overflow-x: auto;
|
| 18 |
+
}
|
| 19 |
+
.highlight {
|
| 20 |
+
background-color: rgba(167, 139, 250, 0.2);
|
| 21 |
+
border-left: 3px solid rgba(167, 139, 250, 1);
|
| 22 |
+
}
|
| 23 |
+
</style>
|
| 24 |
+
</head>
|
| 25 |
+
<body class="bg-gradient-to-br from-gray-900 to-gray-800 min-h-screen text-gray-100">
|
| 26 |
+
<div class="container mx-auto px-4 py-12">
|
| 27 |
+
<!-- Header -->
|
| 28 |
+
<header class="text-center mb-16">
|
| 29 |
+
<h1 class="text-4xl md:text-5xl font-bold bg-clip-text text-transparent bg-gradient-to-r from-purple-400 to-pink-600 mb-4">
|
| 30 |
+
CodeExplainer Wizard
|
| 31 |
+
</h1>
|
| 32 |
+
<p class="text-xl text-gray-300 max-w-2xl mx-auto">
|
| 33 |
+
Paste your Python code and get a detailed explanation of its functionality
|
| 34 |
+
</p>
|
| 35 |
+
</header>
|
| 36 |
+
|
| 37 |
+
<!-- Main Content -->
|
| 38 |
+
<main class="grid grid-cols-1 lg:grid-cols-2 gap-8">
|
| 39 |
+
<!-- Input Section -->
|
| 40 |
+
<div class="bg-gray-800 rounded-xl p-6 shadow-xl">
|
| 41 |
+
<div class="flex items-center justify-between mb-4">
|
| 42 |
+
<h2 class="text-2xl font-semibold text-purple-300">
|
| 43 |
+
<i data-feather="code" class="inline mr-2"></i>
|
| 44 |
+
Your Python Code
|
| 45 |
+
</h2>
|
| 46 |
+
<button id="clear-btn" class="text-pink-400 hover:text-pink-300 transition">
|
| 47 |
+
<i data-feather="trash-2" class="w-5 h-5"></i>
|
| 48 |
+
</button>
|
| 49 |
+
</div>
|
| 50 |
+
<textarea id="code-input" class="code-block w-full h-96 p-4 resize-none focus:outline-none focus:ring-2 focus:ring-purple-500 rounded-lg" placeholder="Paste your Python code here..."></textarea>
|
| 51 |
+
<button id="analyze-btn" class="mt-4 w-full bg-gradient-to-r from-purple-600 to-pink-600 text-white font-bold py-3 px-6 rounded-lg hover:opacity-90 transition flex items-center justify-center">
|
| 52 |
+
<i data-feather="zap" class="mr-2"></i>
|
| 53 |
+
Analyze Code
|
| 54 |
+
</button>
|
| 55 |
+
</div>
|
| 56 |
+
|
| 57 |
+
<!-- Output Section -->
|
| 58 |
+
<div class="bg-gray-800 rounded-xl p-6 shadow-xl">
|
| 59 |
+
<div class="flex items-center mb-4">
|
| 60 |
+
<h2 class="text-2xl font-semibold text-green-300">
|
| 61 |
+
<i data-feather="book-open" class="inline mr-2"></i>
|
| 62 |
+
Code Explanation
|
| 63 |
+
</h2>
|
| 64 |
+
</div>
|
| 65 |
+
<div id="output" class="h-96 overflow-y-auto p-4 bg-gray-700 rounded-lg">
|
| 66 |
+
<div id="placeholder" class="flex flex-col items-center justify-center h-full text-center text-gray-400">
|
| 67 |
+
<i data-feather="search" class="w-12 h-12 mb-4"></i>
|
| 68 |
+
<p class="text-xl mb-2">No code analyzed yet</p>
|
| 69 |
+
<p class="max-w-md">Paste your Python code in the left panel and click "Analyze Code" to get a detailed explanation.</p>
|
| 70 |
+
</div>
|
| 71 |
+
<div id="analysis-results" class="hidden">
|
| 72 |
+
<!-- Results will be inserted here by JavaScript -->
|
| 73 |
+
</div>
|
| 74 |
+
</div>
|
| 75 |
+
<div class="mt-4 flex justify-end">
|
| 76 |
+
<button id="copy-btn" class="bg-gray-700 hover:bg-gray-600 text-white font-medium py-2 px-4 rounded-lg transition flex items-center">
|
| 77 |
+
<i data-feather="copy" class="mr-2"></i>
|
| 78 |
+
Copy Explanation
|
| 79 |
+
</button>
|
| 80 |
+
</div>
|
| 81 |
+
</div>
|
| 82 |
+
</main>
|
| 83 |
+
|
| 84 |
+
<!-- Features Section -->
|
| 85 |
+
<section class="mt-24">
|
| 86 |
+
<h2 class="text-3xl font-bold text-center mb-12">
|
| 87 |
+
How It Works <i data-feather="help-circle" class="inline"></i>
|
| 88 |
+
</h2>
|
| 89 |
+
<div class="grid grid-cols-1 md:grid-cols-3 gap-8">
|
| 90 |
+
<div class="bg-gray-800 p-6 rounded-xl shadow-lg">
|
| 91 |
+
<div class="text-purple-400 mb-4">
|
| 92 |
+
<i data-feather="clipboard" class="w-10 h-10"></i>
|
| 93 |
+
</div>
|
| 94 |
+
<h3 class="text-xl font-semibold mb-2">1. Paste Your Code</h3>
|
| 95 |
+
<p class="text-gray-300">Copy and paste any Python code snippet into the input area.</p>
|
| 96 |
+
</div>
|
| 97 |
+
<div class="bg-gray-800 p-6 rounded-xl shadow-lg">
|
| 98 |
+
<div class="text-purple-400 mb-4">
|
| 99 |
+
<i data-feather="cpu" class="w-10 h-10"></i>
|
| 100 |
+
</div>
|
| 101 |
+
<h3 class="text-xl font-semibold mb-2">2. Analyze It</h3>
|
| 102 |
+
<p class="text-gray-300">Our wizard examines your code structure and logic.</p>
|
| 103 |
+
</div>
|
| 104 |
+
<div class="bg-gray-800 p-6 rounded-xl shadow-lg">
|
| 105 |
+
<div class="text-purple-400 mb-4">
|
| 106 |
+
<i data-feather="book" class="w-10 h-10"></i>
|
| 107 |
+
</div>
|
| 108 |
+
<h3 class="text-xl font-semibold mb-2">3. Get Explanation</h3>
|
| 109 |
+
<p class="text-gray-300">Receive a detailed breakdown of what your code does.</p>
|
| 110 |
+
</div>
|
| 111 |
+
</div>
|
| 112 |
+
</section>
|
| 113 |
+
</div>
|
| 114 |
+
|
| 115 |
+
<script>
|
| 116 |
+
feather.replace();
|
| 117 |
+
|
| 118 |
+
document.addEventListener('DOMContentLoaded', function() {
|
| 119 |
+
const codeInput = document.getElementById('code-input');
|
| 120 |
+
const analyzeBtn = document.getElementById('analyze-btn');
|
| 121 |
+
const clearBtn = document.getElementById('clear-btn');
|
| 122 |
+
const copyBtn = document.getElementById('copy-btn');
|
| 123 |
+
const output = document.getElementById('output');
|
| 124 |
+
const placeholder = document.getElementById('placeholder');
|
| 125 |
+
const analysisResults = document.getElementById('analysis-results');
|
| 126 |
+
|
| 127 |
+
// Clear button functionality
|
| 128 |
+
clearBtn.addEventListener('click', function() {
|
| 129 |
+
codeInput.value = '';
|
| 130 |
+
});
|
| 131 |
+
|
| 132 |
+
// Analyze button functionality
|
| 133 |
+
analyzeBtn.addEventListener('click', function() {
|
| 134 |
+
const code = codeInput.value.trim();
|
| 135 |
+
|
| 136 |
+
if (!code) {
|
| 137 |
+
alert('Please paste some Python code first!');
|
| 138 |
+
return;
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
// Simulate analysis (in a real app, this would be an API call)
|
| 142 |
+
placeholder.classList.add('hidden');
|
| 143 |
+
analysisResults.classList.remove('hidden');
|
| 144 |
+
|
| 145 |
+
// For demo purposes - in a real app, this would be the actual analysis
|
| 146 |
+
analysisResults.innerHTML = `
|
| 147 |
+
<div class="mb-6">
|
| 148 |
+
<h3 class="text-xl font-semibold text-purple-300 mb-2">Code Summary</h3>
|
| 149 |
+
<p class="text-gray-300">Your Python code appears to be a ${getRandomLength()} script that ${getRandomFunctionality()}.</p>
|
| 150 |
+
</div>
|
| 151 |
+
<div class="mb-6">
|
| 152 |
+
<h3 class="text-xl font-semibold text-purple-300 mb-2">Key Components</h3>
|
| 153 |
+
<ul class="list-disc pl-5 text-gray-300 space-y-2">
|
| 154 |
+
<li>${getRandomComponent()}</li>
|
| 155 |
+
<li>${getRandomComponent()}</li>
|
| 156 |
+
<li>${getRandomComponent()}</li>
|
| 157 |
+
</ul>
|
| 158 |
+
</div>
|
| 159 |
+
<div>
|
| 160 |
+
<h3 class="text-xl font-semibold text-purple-300 mb-2">How It Works</h3>
|
| 161 |
+
<p class="text-gray-300 mb-4">${getRandomExplanation()}</p>
|
| 162 |
+
<div class="code-block p-4 rounded-lg mb-4">
|
| 163 |
+
<code class="text-sm">${highlightRandomLines(code)}</code>
|
| 164 |
+
</div>
|
| 165 |
+
<p class="text-gray-300">${getRandomTip()}</p>
|
| 166 |
+
</div>
|
| 167 |
+
`;
|
| 168 |
+
});
|
| 169 |
+
|
| 170 |
+
// Copy button functionality
|
| 171 |
+
copyBtn.addEventListener('click', function() {
|
| 172 |
+
if (analysisResults.classList.contains('hidden')) {
|
| 173 |
+
alert('No explanation to copy yet!');
|
| 174 |
+
return;
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
const range = document.createRange();
|
| 178 |
+
range.selectNode(analysisResults);
|
| 179 |
+
window.getSelection().removeAllRanges();
|
| 180 |
+
window.getSelection().addRange(range);
|
| 181 |
+
document.execCommand('copy');
|
| 182 |
+
window.getSelection().removeAllRanges();
|
| 183 |
+
|
| 184 |
+
// Show feedback
|
| 185 |
+
const originalText = copyBtn.innerHTML;
|
| 186 |
+
copyBtn.innerHTML = '<i data-feather="check" class="mr-2"></i> Copied!';
|
| 187 |
+
feather.replace();
|
| 188 |
+
|
| 189 |
+
setTimeout(() => {
|
| 190 |
+
copyBtn.innerHTML = originalText;
|
| 191 |
+
feather.replace();
|
| 192 |
+
}, 2000);
|
| 193 |
+
});
|
| 194 |
+
|
| 195 |
+
// Helper functions for demo purposes
|
| 196 |
+
function getRandomLength() {
|
| 197 |
+
const lengths = ['short', 'medium-length', 'long', 'complex'];
|
| 198 |
+
return lengths[Math.floor(Math.random() * lengths.length)];
|
| 199 |
+
}
|
| 200 |
+
|
| 201 |
+
function getRandomFunctionality() {
|
| 202 |
+
const functionalities = [
|
| 203 |
+
'processes data from an external API',
|
| 204 |
+
'implements a machine learning algorithm',
|
| 205 |
+
'manipulates strings and arrays',
|
| 206 |
+
'reads and writes to files',
|
| 207 |
+
'performs mathematical calculations',
|
| 208 |
+
'creates a GUI application'
|
| 209 |
+
];
|
| 210 |
+
return functionalities[Math.floor(Math.random() * functionalities.length)];
|
| 211 |
+
}
|
| 212 |
+
|
| 213 |
+
function getRandomComponent() {
|
| 214 |
+
const components = [
|
| 215 |
+
'Functions that handle specific tasks',
|
| 216 |
+
'Variables that store important data',
|
| 217 |
+
'Loops that iterate through collections',
|
| 218 |
+
'Conditional statements that control program flow',
|
| 219 |
+
'Class definitions for object-oriented programming',
|
| 220 |
+
'Error handling with try-except blocks'
|
| 221 |
+
];
|
| 222 |
+
return components[Math.floor(Math.random() * components.length)];
|
| 223 |
+
}
|
| 224 |
+
|
| 225 |
+
function getRandomExplanation() {
|
| 226 |
+
const explanations = [
|
| 227 |
+
'The code starts by importing necessary modules, then defines the main processing function. It takes input, transforms it through several steps, and returns the result.',
|
| 228 |
+
'This script follows a modular approach, separating concerns into different functions. The main execution flow coordinates between these components to achieve the desired outcome.',
|
| 229 |
+
'Using Python\'s built-in functions and some custom logic, the code efficiently processes the data while maintaining readability and modularity.'
|
| 230 |
+
];
|
| 231 |
+
return explanations[Math.floor(Math.random() * explanations.length)];
|
| 232 |
+
}
|
| 233 |
+
|
| 234 |
+
function highlightRandomLines(code) {
|
| 235 |
+
const lines = code.split('\n');
|
| 236 |
+
if (lines.length < 5) return code;
|
| 237 |
+
|
| 238 |
+
// Highlight 1-3 random lines
|
| 239 |
+
const numHighlighted = Math.floor(Math.random() * 3) + 1;
|
| 240 |
+
const highlightedIndices = [];
|
| 241 |
+
|
| 242 |
+
for (let i = 0; i < numHighlighted; i++) {
|
| 243 |
+
const randomIndex = Math.floor(Math.random() * lines.length);
|
| 244 |
+
if (!highlightedIndices.includes(randomIndex)) {
|
| 245 |
+
highlightedIndices.push(randomIndex);
|
| 246 |
+
}
|
| 247 |
+
}
|
| 248 |
+
|
| 249 |
+
return lines.map((line, index) =>
|
| 250 |
+
highlightedIndices.includes(index)
|
| 251 |
+
? `<span class="highlight">${line}</span>`
|
| 252 |
+
: line
|
| 253 |
+
).join('\n');
|
| 254 |
+
}
|
| 255 |
+
|
| 256 |
+
function getRandomTip() {
|
| 257 |
+
const tips = [
|
| 258 |
+
'Tip: Consider adding comments to explain complex logic for better maintainability.',
|
| 259 |
+
'Tip: You might want to add input validation to make the code more robust.',
|
| 260 |
+
'Tip: This could be optimized by using list comprehensions for better performance.',
|
| 261 |
+
'Tip: Adding type hints would improve code readability and IDE support.'
|
| 262 |
+
];
|
| 263 |
+
return tips[Math.floor(Math.random() * tips.length)];
|
| 264 |
+
}
|
| 265 |
+
});
|
| 266 |
+
</script>
|
| 267 |
+
</body>
|
| 268 |
</html>
|