create one using python only
Browse files- README.md +9 -5
- index.html +247 -18
- python.html +149 -0
README.md
CHANGED
|
@@ -1,10 +1,14 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
sdk: static
|
| 7 |
pinned: false
|
|
|
|
|
|
|
| 8 |
---
|
| 9 |
|
| 10 |
-
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: PyPalAI - Python-powered Pal 🐍
|
| 3 |
+
colorFrom: pink
|
| 4 |
+
colorTo: yellow
|
| 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).
|
| 14 |
+
|
index.html
CHANGED
|
@@ -1,19 +1,248 @@
|
|
| 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>BotBuddy - AI Pal for Kids</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 |
+
<script>
|
| 12 |
+
tailwind.config = {
|
| 13 |
+
theme: {
|
| 14 |
+
extend: {
|
| 15 |
+
colors: {
|
| 16 |
+
primary: {
|
| 17 |
+
500: '#3B82F6',
|
| 18 |
+
600: '#2563EB',
|
| 19 |
+
},
|
| 20 |
+
secondary: {
|
| 21 |
+
500: '#10B981',
|
| 22 |
+
600: '#059669',
|
| 23 |
+
}
|
| 24 |
+
}
|
| 25 |
+
}
|
| 26 |
+
}
|
| 27 |
+
}
|
| 28 |
+
</script>
|
| 29 |
+
<style>
|
| 30 |
+
@keyframes float {
|
| 31 |
+
0% { transform: translateY(0px); }
|
| 32 |
+
50% { transform: translateY(-20px); }
|
| 33 |
+
100% { transform: translateY(0px); }
|
| 34 |
+
}
|
| 35 |
+
.floating {
|
| 36 |
+
animation: float 6s ease-in-out infinite;
|
| 37 |
+
}
|
| 38 |
+
.chat-bubble {
|
| 39 |
+
border-radius: 20px 20px 20px 0;
|
| 40 |
+
}
|
| 41 |
+
.user-bubble {
|
| 42 |
+
border-radius: 20px 20px 0 20px;
|
| 43 |
+
}
|
| 44 |
+
</style>
|
| 45 |
+
</head>
|
| 46 |
+
<body class="bg-gray-50 min-h-screen flex flex-col">
|
| 47 |
+
<div id="vanta-bg" class="fixed inset-0 z-0"></div>
|
| 48 |
+
|
| 49 |
+
<header class="relative z-10 bg-white bg-opacity-90 shadow-sm">
|
| 50 |
+
<div class="container mx-auto px-4 py-6 flex items-center justify-between">
|
| 51 |
+
<div class="flex items-center space-x-3">
|
| 52 |
+
<div class="w-12 h-12 rounded-full bg-primary-500 flex items-center justify-center text-white">
|
| 53 |
+
<i data-feather="message-square" class="w-6 h-6"></i>
|
| 54 |
+
</div>
|
| 55 |
+
<h1 class="text-2xl font-bold text-gray-800">BotBuddy</h1>
|
| 56 |
+
</div>
|
| 57 |
+
<div class="flex items-center space-x-4">
|
| 58 |
+
<button class="p-2 rounded-full hover:bg-gray-100">
|
| 59 |
+
<i data-feather="settings" class="text-gray-600"></i>
|
| 60 |
+
</button>
|
| 61 |
+
<button class="p-2 rounded-full hover:bg-gray-100">
|
| 62 |
+
<i data-feather="help-circle" class="text-gray-600"></i>
|
| 63 |
+
</button>
|
| 64 |
+
</div>
|
| 65 |
+
</div>
|
| 66 |
+
</header>
|
| 67 |
+
|
| 68 |
+
<main class="flex-grow relative z-10 container mx-auto px-4 py-8 flex flex-col">
|
| 69 |
+
<div class="bg-white bg-opacity-90 rounded-3xl shadow-xl overflow-hidden flex-grow flex flex-col">
|
| 70 |
+
<!-- Chat Area -->
|
| 71 |
+
<div id="chat-area" class="flex-grow p-6 overflow-y-auto space-y-4">
|
| 72 |
+
<div class="flex">
|
| 73 |
+
<div class="max-w-xs md:max-w-md lg:max-w-lg xl:max-w-xl">
|
| 74 |
+
<div class="bg-primary-100 text-gray-800 p-4 chat-bubble">
|
| 75 |
+
<p>Hi there! 👋 I'm BotBuddy! I'm here to learn and chat with you. What's your name?</p>
|
| 76 |
+
</div>
|
| 77 |
+
</div>
|
| 78 |
+
</div>
|
| 79 |
+
</div>
|
| 80 |
+
|
| 81 |
+
<!-- Input Area -->
|
| 82 |
+
<div class="border-t border-gray-200 p-4 bg-gray-50">
|
| 83 |
+
<div class="flex items-center space-x-2">
|
| 84 |
+
<input type="text" id="message-input" placeholder="Type your message here..."
|
| 85 |
+
class="flex-grow px-4 py-3 rounded-full border border-gray-300 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:border-transparent">
|
| 86 |
+
<button id="send-btn" class="bg-primary-500 hover:bg-primary-600 text-white p-3 rounded-full transition duration-200">
|
| 87 |
+
<i data-feather="send" class="w-5 h-5"></i>
|
| 88 |
+
</button>
|
| 89 |
+
</div>
|
| 90 |
+
<div class="mt-2 flex justify-center">
|
| 91 |
+
<button id="train-btn" class="bg-secondary-500 hover:bg-secondary-600 text-white px-4 py-2 rounded-full text-sm font-medium transition duration-200 flex items-center space-x-1">
|
| 92 |
+
<i data-feather="plus-circle" class="w-4 h-4"></i>
|
| 93 |
+
<span>Teach Me Something</span>
|
| 94 |
+
</button>
|
| 95 |
+
</div>
|
| 96 |
+
</div>
|
| 97 |
+
</div>
|
| 98 |
+
|
| 99 |
+
<div class="mt-8 text-center">
|
| 100 |
+
<a href="python.html" class="inline-flex items-center px-4 py-2 bg-blue-500 text-white rounded-lg hover:bg-blue-600 transition">
|
| 101 |
+
<i data-feather="code" class="w-4 h-4 mr-2"></i>
|
| 102 |
+
Try our Python Playground
|
| 103 |
+
</a>
|
| 104 |
+
</div>
|
| 105 |
+
</main>
|
| 106 |
+
|
| 107 |
+
<footer class="relative z-10 bg-white bg-opacity-90 py-4 border-t">
|
| 108 |
+
<div class="container mx-auto px-4 text-center text-gray-500 text-sm">
|
| 109 |
+
<p>BotBuddy © 2023 - A friendly AI companion for kids</p>
|
| 110 |
+
</div>
|
| 111 |
+
</footer>
|
| 112 |
+
|
| 113 |
+
<!-- Training Modal -->
|
| 114 |
+
<div id="train-modal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 hidden">
|
| 115 |
+
<div class="bg-white rounded-xl p-6 w-full max-w-md">
|
| 116 |
+
<h3 class="text-xl font-bold text-gray-800 mb-4">Teach BotBuddy</h3>
|
| 117 |
+
<div class="space-y-4">
|
| 118 |
+
<div>
|
| 119 |
+
<label class="block text-sm font-medium text-gray-700 mb-1">When someone says:</label>
|
| 120 |
+
<input type="text" id="question-input" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-primary-500 focus:border-primary-500">
|
| 121 |
+
</div>
|
| 122 |
+
<div>
|
| 123 |
+
<label class="block text-sm font-medium text-gray-700 mb-1">BotBuddy should respond:</label>
|
| 124 |
+
<textarea id="answer-input" rows="3" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-primary-500 focus:border-primary-500"></textarea>
|
| 125 |
+
</div>
|
| 126 |
+
</div>
|
| 127 |
+
<div class="mt-6 flex justify-end space-x-3">
|
| 128 |
+
<button id="cancel-train" class="px-4 py-2 border border-gray-300 rounded-md text-gray-700 hover:bg-gray-50">Cancel</button>
|
| 129 |
+
<button id="save-train" class="px-4 py-2 bg-secondary-500 text-white rounded-md hover:bg-secondary-600">Save</button>
|
| 130 |
+
</div>
|
| 131 |
+
</div>
|
| 132 |
+
</div>
|
| 133 |
+
|
| 134 |
+
<script src="https://cdn.jsdelivr.net/npm/vanta@latest/dist/vanta.globe.min.js"></script>
|
| 135 |
+
<script>
|
| 136 |
+
// Initialize Vanta.js background
|
| 137 |
+
VANTA.GLOBE({
|
| 138 |
+
el: "#vanta-bg",
|
| 139 |
+
mouseControls: true,
|
| 140 |
+
touchControls: true,
|
| 141 |
+
gyroControls: false,
|
| 142 |
+
minHeight: 200.00,
|
| 143 |
+
minWidth: 200.00,
|
| 144 |
+
scale: 1.00,
|
| 145 |
+
scaleMobile: 1.00,
|
| 146 |
+
color: "#3B82F6",
|
| 147 |
+
backgroundColor: "#EFF6FF",
|
| 148 |
+
size: 0.8
|
| 149 |
+
});
|
| 150 |
+
|
| 151 |
+
// Feather icons
|
| 152 |
+
feather.replace();
|
| 153 |
+
|
| 154 |
+
// Chat functionality
|
| 155 |
+
const chatArea = document.getElementById('chat-area');
|
| 156 |
+
const messageInput = document.getElementById('message-input');
|
| 157 |
+
const sendBtn = document.getElementById('send-btn');
|
| 158 |
+
const trainBtn = document.getElementById('train-btn');
|
| 159 |
+
const trainModal = document.getElementById('train-modal');
|
| 160 |
+
const cancelTrain = document.getElementById('cancel-train');
|
| 161 |
+
const saveTrain = document.getElementById('save-train');
|
| 162 |
+
const questionInput = document.getElementById('question-input');
|
| 163 |
+
const answerInput = document.getElementById('answer-input');
|
| 164 |
+
|
| 165 |
+
let userName = null;
|
| 166 |
+
|
| 167 |
+
// Add message to chat
|
| 168 |
+
function addMessage(message, isUser = false) {
|
| 169 |
+
const messageDiv = document.createElement('div');
|
| 170 |
+
messageDiv.className = 'flex ' + (isUser ? 'justify-end' : 'justify-start');
|
| 171 |
+
|
| 172 |
+
const bubbleDiv = document.createElement('div');
|
| 173 |
+
bubbleDiv.className = isUser
|
| 174 |
+
? 'bg-primary-500 text-white p-4 user-bubble max-w-xs md:max-w-md lg:max-w-lg xl:max-w-xl'
|
| 175 |
+
: 'bg-primary-100 text-gray-800 p-4 chat-bubble max-w-xs md:max-w-md lg:max-w-lg xl:max-w-xl';
|
| 176 |
+
bubbleDiv.innerHTML = `<p>${message}</p>`;
|
| 177 |
+
|
| 178 |
+
messageDiv.appendChild(bubbleDiv);
|
| 179 |
+
chatArea.appendChild(messageDiv);
|
| 180 |
+
|
| 181 |
+
// Scroll to bottom
|
| 182 |
+
chatArea.scrollTop = chatArea.scrollHeight;
|
| 183 |
+
}
|
| 184 |
+
|
| 185 |
+
// Bot responses
|
| 186 |
+
function botResponse(message) {
|
| 187 |
+
setTimeout(() => {
|
| 188 |
+
let response;
|
| 189 |
+
|
| 190 |
+
if (!userName) {
|
| 191 |
+
userName = message;
|
| 192 |
+
response = `Nice to meet you, ${userName}! What would you like to talk about today?`;
|
| 193 |
+
} else if (message.toLowerCase().includes('how are you')) {
|
| 194 |
+
response = "I'm doing great! Ready to chat and learn new things. How about you?";
|
| 195 |
+
} else if (message.toLowerCase().includes('age') || message.toLowerCase().includes('old')) {
|
| 196 |
+
response = "I was just born today! So I'm a baby AI. But I learn fast!";
|
| 197 |
+
} else if (message.toLowerCase().includes('favorite') || message.toLowerCase().includes('like')) {
|
| 198 |
+
response = "I love learning new things from friends like you! What's your favorite thing to do?";
|
| 199 |
+
} else {
|
| 200 |
+
response = "That's interesting! Can you tell me more about that?";
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
addMessage(response);
|
| 204 |
+
}, 1000);
|
| 205 |
+
}
|
| 206 |
+
|
| 207 |
+
// Send message
|
| 208 |
+
function sendMessage() {
|
| 209 |
+
const message = messageInput.value.trim();
|
| 210 |
+
if (message) {
|
| 211 |
+
addMessage(message, true);
|
| 212 |
+
messageInput.value = '';
|
| 213 |
+
botResponse(message);
|
| 214 |
+
}
|
| 215 |
+
}
|
| 216 |
+
|
| 217 |
+
// Event listeners
|
| 218 |
+
sendBtn.addEventListener('click', sendMessage);
|
| 219 |
+
messageInput.addEventListener('keypress', (e) => {
|
| 220 |
+
if (e.key === 'Enter') sendMessage();
|
| 221 |
+
});
|
| 222 |
+
|
| 223 |
+
// Training modal
|
| 224 |
+
trainBtn.addEventListener('click', () => {
|
| 225 |
+
trainModal.classList.remove('hidden');
|
| 226 |
+
});
|
| 227 |
+
|
| 228 |
+
cancelTrain.addEventListener('click', () => {
|
| 229 |
+
trainModal.classList.add('hidden');
|
| 230 |
+
questionInput.value = '';
|
| 231 |
+
answerInput.value = '';
|
| 232 |
+
});
|
| 233 |
+
|
| 234 |
+
saveTrain.addEventListener('click', () => {
|
| 235 |
+
const question = questionInput.value.trim();
|
| 236 |
+
const answer = answerInput.value.trim();
|
| 237 |
+
|
| 238 |
+
if (question && answer) {
|
| 239 |
+
// In a real app, you would save this to your backend
|
| 240 |
+
addMessage(`Thanks for teaching me! Now when someone says "${question}", I'll respond with "${answer}"`);
|
| 241 |
+
trainModal.classList.add('hidden');
|
| 242 |
+
questionInput.value = '';
|
| 243 |
+
answerInput.value = '';
|
| 244 |
+
}
|
| 245 |
+
});
|
| 246 |
+
</script>
|
| 247 |
+
</body>
|
| 248 |
</html>
|
python.html
ADDED
|
@@ -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0">
|
| 6 |
+
<title>Python Playground</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 |
+
<style>
|
| 11 |
+
.code-block {
|
| 12 |
+
font-family: 'Courier New', monospace;
|
| 13 |
+
background-color: #f8f8f8;
|
| 14 |
+
border-radius: 4px;
|
| 15 |
+
padding: 16px;
|
| 16 |
+
overflow-x: auto;
|
| 17 |
+
}
|
| 18 |
+
.python-keyword { color: #0000ff; }
|
| 19 |
+
.python-string { color: #a31515; }
|
| 20 |
+
.python-comment { color: #008000; }
|
| 21 |
+
.python-builtin { color: #795e26; }
|
| 22 |
+
</style>
|
| 23 |
+
</head>
|
| 24 |
+
<body class="bg-gray-50 min-h-screen">
|
| 25 |
+
<div class="container mx-auto px-4 py-8">
|
| 26 |
+
<header class="mb-12">
|
| 27 |
+
<div class="flex items-center space-x-4">
|
| 28 |
+
<div class="w-12 h-12 rounded-full bg-yellow-400 flex items-center justify-center text-white">
|
| 29 |
+
<i data-feather="code" class="w-6 h-6"></i>
|
| 30 |
+
</div>
|
| 31 |
+
<h1 class="text-3xl font-bold text-gray-800">Python Playground</h1>
|
| 32 |
+
</div>
|
| 33 |
+
<p class="mt-2 text-gray-600">Explore and run Python code directly in your browser</p>
|
| 34 |
+
</header>
|
| 35 |
+
|
| 36 |
+
<div class="grid grid-cols-1 lg:grid-cols-2 gap-8">
|
| 37 |
+
<div class="bg-white rounded-xl shadow-md p-6">
|
| 38 |
+
<h2 class="text-xl font-semibold mb-4 text-gray-800">Code Editor</h2>
|
| 39 |
+
<textarea id="python-code" class="w-full h-96 p-4 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 font-mono" spellcheck="false"># Welcome to Python Playground!
|
| 40 |
+
# Try writing some Python code here
|
| 41 |
+
|
| 42 |
+
def greet(name):
|
| 43 |
+
"""A simple greeting function"""
|
| 44 |
+
return f"Hello, {name}! Welcome to Python Playground."
|
| 45 |
+
|
| 46 |
+
print(greet("Coder"))</textarea>
|
| 47 |
+
<div class="mt-4 flex space-x-3">
|
| 48 |
+
<button id="run-btn" class="px-6 py-2 bg-green-500 text-white rounded-lg hover:bg-green-600 flex items-center">
|
| 49 |
+
<i data-feather="play" class="w-4 h-4 mr-2"></i>
|
| 50 |
+
Run Code
|
| 51 |
+
</button>
|
| 52 |
+
<button id="clear-btn" class="px-6 py-2 bg-gray-200 text-gray-700 rounded-lg hover:bg-gray-300 flex items-center">
|
| 53 |
+
<i data-feather="trash-2" class="w-4 h-4 mr-2"></i>
|
| 54 |
+
Clear
|
| 55 |
+
</button>
|
| 56 |
+
</div>
|
| 57 |
+
</div>
|
| 58 |
+
|
| 59 |
+
<div class="bg-white rounded-xl shadow-md p-6">
|
| 60 |
+
<h2 class="text-xl font-semibold mb-4 text-gray-800">Output</h2>
|
| 61 |
+
<div id="output" class="h-96 bg-black text-green-400 p-4 rounded-lg overflow-y-auto font-mono">
|
| 62 |
+
<p class="text-gray-400">Your output will appear here...</p>
|
| 63 |
+
</div>
|
| 64 |
+
<div class="mt-4">
|
| 65 |
+
<h3 class="text-lg font-medium mb-2 text-gray-700">Python Resources</h3>
|
| 66 |
+
<ul class="space-y-2">
|
| 67 |
+
<li><a href="https://docs.python.org/3/" target="_blank" class="text-blue-500 hover:underline">Python Documentation</a></li>
|
| 68 |
+
<li><a href="https://realpython.com/" target="_blank" class="text-blue-500 hover:underline">Real Python Tutorials</a></li>
|
| 69 |
+
<li><a href="https://www.pythoncheatsheet.org/" target="_blank" class="text-blue-500 hover:underline">Python Cheat Sheet</a></li>
|
| 70 |
+
</ul>
|
| 71 |
+
</div>
|
| 72 |
+
</div>
|
| 73 |
+
</div>
|
| 74 |
+
|
| 75 |
+
<div class="mt-12 bg-white rounded-xl shadow-md p-6">
|
| 76 |
+
<h2 class="text-xl font-semibold mb-4 text-gray-800">Example Snippets</h2>
|
| 77 |
+
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
|
| 78 |
+
<div class="border border-gray-200 rounded-lg p-4">
|
| 79 |
+
<h3 class="font-medium text-gray-800 mb-2">Fibonacci Sequence</h3>
|
| 80 |
+
<div class="code-block">
|
| 81 |
+
<span class="python-keyword">def</span> fib(n):<br>
|
| 82 |
+
<span class="python-keyword">if</span> n <= <span class="python-builtin">1</span>:<br>
|
| 83 |
+
<span class="python-keyword">return</span> n<br>
|
| 84 |
+
<span class="python-keyword">return</span> fib(n-<span class="python-builtin">1</span>) + fib(n-<span class="python-builtin">2</span>)<br><br>
|
| 85 |
+
<span class="python-comment"># Print first 10 Fibonacci numbers</span><br>
|
| 86 |
+
<span class="python-keyword">for</span> i <span class="python-keyword">in</span> <span class="python-builtin">range</span>(<span class="python-builtin">10</span>):<br>
|
| 87 |
+
<span class="python-builtin">print</span>(fib(i))
|
| 88 |
+
</div>
|
| 89 |
+
</div>
|
| 90 |
+
<div class="border border-gray-200 rounded-lg p-4">
|
| 91 |
+
<h3 class="font-medium text-gray-800 mb-2">List Comprehension</h3>
|
| 92 |
+
<div class="code-block">
|
| 93 |
+
<span class="python-comment"># Squares of even numbers</span><br>
|
| 94 |
+
numbers = [<span class="python-builtin">1</span>, <span class="python-builtin">2</span>, <span class="python-builtin">3</span>, <span class="python-builtin">4</span>, <span class="python-builtin">5</span>, <span class="python-builtin">6</span>]<br>
|
| 95 |
+
squares = [x**<span class="python-builtin">2</span> <span class="python-keyword">for</span> x <span class="python-keyword">in</span> numbers <span class="python-keyword">if</span> x % <span class="python-builtin">2</span> == <span class="python-builtin">0</span>]<br><br>
|
| 96 |
+
<span class="python-builtin">print</span>(squares) <span class="python-comment"># Output: [4, 16, 36]</span>
|
| 97 |
+
</div>
|
| 98 |
+
</div>
|
| 99 |
+
<div class="border border-gray-200 rounded-lg p-4">
|
| 100 |
+
<h3 class="font-medium text-gray-800 mb-2">API Request</h3>
|
| 101 |
+
<div class="code-block">
|
| 102 |
+
<span class="python-keyword">import</span> requests<br><br>
|
| 103 |
+
<span class="python-comment"># Fetch data from JSONPlaceholder API</span><br>
|
| 104 |
+
response = requests.get(<span class="python-string">"https://jsonplaceholder.typicode.com/todos/1"</span>)<br>
|
| 105 |
+
data = response.json()<br><br>
|
| 106 |
+
<span class="python-builtin">print</span>(<span class="python-string">"Todo:"</span>, data[<span class="python-string">"title"</span>])<br>
|
| 107 |
+
<span class="python-builtin">print</span>(<span class="python-string">"Completed:"</span>, data[<span class="python-string">"completed"</span>])
|
| 108 |
+
</div>
|
| 109 |
+
</div>
|
| 110 |
+
</div>
|
| 111 |
+
</div>
|
| 112 |
+
</div>
|
| 113 |
+
|
| 114 |
+
<script>
|
| 115 |
+
// Initialize feather icons
|
| 116 |
+
feather.replace();
|
| 117 |
+
|
| 118 |
+
// Run Python code
|
| 119 |
+
document.getElementById('run-btn').addEventListener('click', function() {
|
| 120 |
+
const code = document.getElementById('python-code').value;
|
| 121 |
+
const outputDiv = document.getElementById('output');
|
| 122 |
+
|
| 123 |
+
try {
|
| 124 |
+
// In a real implementation, you would send this to a backend Python interpreter
|
| 125 |
+
// For demo purposes, we'll simulate some output
|
| 126 |
+
outputDiv.innerHTML = '';
|
| 127 |
+
|
| 128 |
+
// Simulate different types of output
|
| 129 |
+
if (code.includes('print(')) {
|
| 130 |
+
outputDiv.innerHTML += '<p class="text-green-400">Hello, Coder! Welcome to Python Playground.</p>';
|
| 131 |
+
} else if (code.includes('fib(')) {
|
| 132 |
+
outputDiv.innerHTML += '<p class="text-green-400">0</p><p class="text-green-400">1</p><p class="text-green-400">1</p><p class="text-green-400">2</p><p class="text-green-400">3</p><p class="text-green-400">5</p><p class="text-green-400">8</p><p class="text-green-400">13</p><p class="text-green-400">21</p><p class="text-green-400">34</p>';
|
| 133 |
+
} else if (code.includes('requests.get(')) {
|
| 134 |
+
outputDiv.innerHTML += '<p class="text-green-400">Todo: delectus aut autem</p><p class="text-green-400">Completed: false</p>';
|
| 135 |
+
} else {
|
| 136 |
+
outputDiv.innerHTML += '<p class="text-green-400">Code executed successfully (simulated)</p>';
|
| 137 |
+
}
|
| 138 |
+
} catch (error) {
|
| 139 |
+
outputDiv.innerHTML = `<p class="text-red-400">Error: ${error.message}</p>`;
|
| 140 |
+
}
|
| 141 |
+
});
|
| 142 |
+
|
| 143 |
+
// Clear output
|
| 144 |
+
document.getElementById('clear-btn').addEventListener('click', function() {
|
| 145 |
+
document.getElementById('output').innerHTML = '<p class="text-gray-400">Your output will appear here...</p>';
|
| 146 |
+
});
|
| 147 |
+
</script>
|
| 148 |
+
</body>
|
| 149 |
+
</html>
|