codeexplainer-wizard / index.html
Hooman1335's picture
من یک سری کد پایتون دارم . میخوام برات بفرستم ، بررسی کنی و عملکردش و بران توضیح بدی
9741390 verified
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CodeExplainer Wizard</title>
<link rel="icon" type="image/x-icon" href="/static/favicon.ico">
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://unpkg.com/feather-icons"></script>
<script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
<style>
.code-block {
font-family: 'Courier New', monospace;
background-color: #1e293b;
color: #e2e8f0;
border-radius: 0.5rem;
overflow-x: auto;
}
.highlight {
background-color: rgba(167, 139, 250, 0.2);
border-left: 3px solid rgba(167, 139, 250, 1);
}
</style>
</head>
<body class="bg-gradient-to-br from-gray-900 to-gray-800 min-h-screen text-gray-100">
<div class="container mx-auto px-4 py-12">
<!-- Header -->
<header class="text-center mb-16">
<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">
CodeExplainer Wizard
</h1>
<p class="text-xl text-gray-300 max-w-2xl mx-auto">
Paste your Python code and get a detailed explanation of its functionality
</p>
</header>
<!-- Main Content -->
<main class="grid grid-cols-1 lg:grid-cols-2 gap-8">
<!-- Input Section -->
<div class="bg-gray-800 rounded-xl p-6 shadow-xl">
<div class="flex items-center justify-between mb-4">
<h2 class="text-2xl font-semibold text-purple-300">
<i data-feather="code" class="inline mr-2"></i>
Your Python Code
</h2>
<button id="clear-btn" class="text-pink-400 hover:text-pink-300 transition">
<i data-feather="trash-2" class="w-5 h-5"></i>
</button>
</div>
<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>
<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">
<i data-feather="zap" class="mr-2"></i>
Analyze Code
</button>
</div>
<!-- Output Section -->
<div class="bg-gray-800 rounded-xl p-6 shadow-xl">
<div class="flex items-center mb-4">
<h2 class="text-2xl font-semibold text-green-300">
<i data-feather="book-open" class="inline mr-2"></i>
Code Explanation
</h2>
</div>
<div id="output" class="h-96 overflow-y-auto p-4 bg-gray-700 rounded-lg">
<div id="placeholder" class="flex flex-col items-center justify-center h-full text-center text-gray-400">
<i data-feather="search" class="w-12 h-12 mb-4"></i>
<p class="text-xl mb-2">No code analyzed yet</p>
<p class="max-w-md">Paste your Python code in the left panel and click "Analyze Code" to get a detailed explanation.</p>
</div>
<div id="analysis-results" class="hidden">
<!-- Results will be inserted here by JavaScript -->
</div>
</div>
<div class="mt-4 flex justify-end">
<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">
<i data-feather="copy" class="mr-2"></i>
Copy Explanation
</button>
</div>
</div>
</main>
<!-- Features Section -->
<section class="mt-24">
<h2 class="text-3xl font-bold text-center mb-12">
How It Works <i data-feather="help-circle" class="inline"></i>
</h2>
<div class="grid grid-cols-1 md:grid-cols-3 gap-8">
<div class="bg-gray-800 p-6 rounded-xl shadow-lg">
<div class="text-purple-400 mb-4">
<i data-feather="clipboard" class="w-10 h-10"></i>
</div>
<h3 class="text-xl font-semibold mb-2">1. Paste Your Code</h3>
<p class="text-gray-300">Copy and paste any Python code snippet into the input area.</p>
</div>
<div class="bg-gray-800 p-6 rounded-xl shadow-lg">
<div class="text-purple-400 mb-4">
<i data-feather="cpu" class="w-10 h-10"></i>
</div>
<h3 class="text-xl font-semibold mb-2">2. Analyze It</h3>
<p class="text-gray-300">Our wizard examines your code structure and logic.</p>
</div>
<div class="bg-gray-800 p-6 rounded-xl shadow-lg">
<div class="text-purple-400 mb-4">
<i data-feather="book" class="w-10 h-10"></i>
</div>
<h3 class="text-xl font-semibold mb-2">3. Get Explanation</h3>
<p class="text-gray-300">Receive a detailed breakdown of what your code does.</p>
</div>
</div>
</section>
</div>
<script>
feather.replace();
document.addEventListener('DOMContentLoaded', function() {
const codeInput = document.getElementById('code-input');
const analyzeBtn = document.getElementById('analyze-btn');
const clearBtn = document.getElementById('clear-btn');
const copyBtn = document.getElementById('copy-btn');
const output = document.getElementById('output');
const placeholder = document.getElementById('placeholder');
const analysisResults = document.getElementById('analysis-results');
// Clear button functionality
clearBtn.addEventListener('click', function() {
codeInput.value = '';
});
// Analyze button functionality
analyzeBtn.addEventListener('click', function() {
const code = codeInput.value.trim();
if (!code) {
alert('Please paste some Python code first!');
return;
}
// Simulate analysis (in a real app, this would be an API call)
placeholder.classList.add('hidden');
analysisResults.classList.remove('hidden');
// For demo purposes - in a real app, this would be the actual analysis
analysisResults.innerHTML = `
<div class="mb-6">
<h3 class="text-xl font-semibold text-purple-300 mb-2">Code Summary</h3>
<p class="text-gray-300">Your Python code appears to be a ${getRandomLength()} script that ${getRandomFunctionality()}.</p>
</div>
<div class="mb-6">
<h3 class="text-xl font-semibold text-purple-300 mb-2">Key Components</h3>
<ul class="list-disc pl-5 text-gray-300 space-y-2">
<li>${getRandomComponent()}</li>
<li>${getRandomComponent()}</li>
<li>${getRandomComponent()}</li>
</ul>
</div>
<div>
<h3 class="text-xl font-semibold text-purple-300 mb-2">How It Works</h3>
<p class="text-gray-300 mb-4">${getRandomExplanation()}</p>
<div class="code-block p-4 rounded-lg mb-4">
<code class="text-sm">${highlightRandomLines(code)}</code>
</div>
<p class="text-gray-300">${getRandomTip()}</p>
</div>
`;
});
// Copy button functionality
copyBtn.addEventListener('click', function() {
if (analysisResults.classList.contains('hidden')) {
alert('No explanation to copy yet!');
return;
}
const range = document.createRange();
range.selectNode(analysisResults);
window.getSelection().removeAllRanges();
window.getSelection().addRange(range);
document.execCommand('copy');
window.getSelection().removeAllRanges();
// Show feedback
const originalText = copyBtn.innerHTML;
copyBtn.innerHTML = '<i data-feather="check" class="mr-2"></i> Copied!';
feather.replace();
setTimeout(() => {
copyBtn.innerHTML = originalText;
feather.replace();
}, 2000);
});
// Helper functions for demo purposes
function getRandomLength() {
const lengths = ['short', 'medium-length', 'long', 'complex'];
return lengths[Math.floor(Math.random() * lengths.length)];
}
function getRandomFunctionality() {
const functionalities = [
'processes data from an external API',
'implements a machine learning algorithm',
'manipulates strings and arrays',
'reads and writes to files',
'performs mathematical calculations',
'creates a GUI application'
];
return functionalities[Math.floor(Math.random() * functionalities.length)];
}
function getRandomComponent() {
const components = [
'Functions that handle specific tasks',
'Variables that store important data',
'Loops that iterate through collections',
'Conditional statements that control program flow',
'Class definitions for object-oriented programming',
'Error handling with try-except blocks'
];
return components[Math.floor(Math.random() * components.length)];
}
function getRandomExplanation() {
const explanations = [
'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.',
'This script follows a modular approach, separating concerns into different functions. The main execution flow coordinates between these components to achieve the desired outcome.',
'Using Python\'s built-in functions and some custom logic, the code efficiently processes the data while maintaining readability and modularity.'
];
return explanations[Math.floor(Math.random() * explanations.length)];
}
function highlightRandomLines(code) {
const lines = code.split('\n');
if (lines.length < 5) return code;
// Highlight 1-3 random lines
const numHighlighted = Math.floor(Math.random() * 3) + 1;
const highlightedIndices = [];
for (let i = 0; i < numHighlighted; i++) {
const randomIndex = Math.floor(Math.random() * lines.length);
if (!highlightedIndices.includes(randomIndex)) {
highlightedIndices.push(randomIndex);
}
}
return lines.map((line, index) =>
highlightedIndices.includes(index)
? `<span class="highlight">${line}</span>`
: line
).join('\n');
}
function getRandomTip() {
const tips = [
'Tip: Consider adding comments to explain complex logic for better maintainability.',
'Tip: You might want to add input validation to make the code more robust.',
'Tip: This could be optimized by using list comprehensions for better performance.',
'Tip: Adding type hints would improve code readability and IDE support.'
];
return tips[Math.floor(Math.random() * tips.length)];
}
});
</script>
</body>
</html>