Spaces:
Running
Running
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>Stack Overflow - Where Developers Learn, Share, & Build</title> | |
| <style> | |
| /* --- RESET & BASIC VARS --- */ | |
| :root { | |
| --orange: #f48024; | |
| --black: #232629; | |
| --black-700: #525960; | |
| --blue: #0a95ff; | |
| --blue-dark: #0074cc; | |
| --bg-body: #f8f9f9; | |
| --white: #ffffff; | |
| --border: #d6d9dc; | |
| --shadow: 0 1px 2px rgba(0,0,0,0.05), 0 1px 4px rgba(0,0,0,0.05), 0 2px 8px rgba(0,0,0,0.05); | |
| } | |
| * { box-sizing: border-box; } | |
| body { | |
| font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; | |
| background-color: var(--bg-body); | |
| color: var(--black); | |
| margin: 0; | |
| display: flex; | |
| flex-direction: column; | |
| min-height: 100vh; | |
| } | |
| /* --- HEADER --- */ | |
| header { | |
| background-color: var(--bg-body); | |
| border-top: 3px solid var(--orange); | |
| box-shadow: 0 1px 2px rgba(0,0,0,0.1); | |
| position: fixed; | |
| width: 100%; | |
| top: 0; | |
| z-index: 100; | |
| height: 50px; | |
| display: flex; | |
| align-items: center; | |
| padding: 0 20px; | |
| } | |
| .logo { | |
| font-size: 1.2rem; | |
| font-weight: bold; | |
| margin-right: 20px; | |
| display: flex; | |
| align-items: center; | |
| cursor: pointer; | |
| } | |
| .logo span:first-child { margin-right: 5px; } | |
| /* Stack Icon Mock */ | |
| .icon-stack { width: 25px; height: 25px; background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 37"><path d="M26 33v-9h4v13H0V24h4v9h22Z" fill="%23BCBBBB"/><path d="M21.5 0l-2.7 2 9.9 13.3 2.7-2L21.5 0ZM26 18.4L13.3 7.8l2.1-2.5 12.7 10.6-2.1 2.5ZM9.1 15.2l15 7 1.4-3-15-7-1.4 3Zm14 10.79l.68-2.95-16.1-3.35L7 23l16.1 2.99ZM23 30H7v-3h16v3Z" fill="%23F48024"/></svg>') no-repeat center; background-size: contain; } | |
| .search-bar { | |
| flex-grow: 1; | |
| max-width: 700px; | |
| position: relative; | |
| } | |
| .search-bar input { | |
| width: 100%; | |
| padding: 8px 10px 8px 35px; | |
| border: 1px solid #babfc4; | |
| border-radius: 3px; | |
| font-size: 13px; | |
| } | |
| .search-icon { | |
| position: absolute; | |
| left: 10px; | |
| top: 50%; | |
| transform: translateY(-50%); | |
| color: #888; | |
| } | |
| .nav-links { | |
| margin-left: auto; | |
| display: flex; | |
| gap: 15px; | |
| font-size: 13px; | |
| color: var(--black-700); | |
| } | |
| .nav-btn { | |
| padding: 8px 12px; | |
| border-radius: 3px; | |
| cursor: pointer; | |
| } | |
| .nav-btn.primary { background-color: #e1ecf4; color: #39739d; } | |
| .nav-btn.blue { background-color: var(--blue); color: var(--white); } | |
| /* --- LAYOUT --- */ | |
| .container { | |
| display: flex; | |
| max-width: 1264px; | |
| width: 100%; | |
| margin: 50px auto 0; | |
| flex: 1; | |
| } | |
| /* --- SIDEBAR --- */ | |
| .sidebar { | |
| width: 164px; | |
| flex-shrink: 0; | |
| padding: 20px 0; | |
| border-right: 1px solid var(--border); | |
| font-size: 13px; | |
| } | |
| .sidebar ul { list-style: none; padding: 0; margin: 0; } | |
| .sidebar li { margin-bottom: 5px; } | |
| .sidebar a { | |
| text-decoration: none; | |
| color: var(--black-700); | |
| display: block; | |
| padding: 8px 10px; | |
| } | |
| .sidebar a.active { | |
| font-weight: bold; | |
| color: var(--black); | |
| background-color: #f1f2f3; | |
| border-right: 3px solid var(--orange); | |
| } | |
| /* --- CONTENT --- */ | |
| .content { | |
| flex-grow: 1; | |
| padding: 24px; | |
| } | |
| .content-header { | |
| display: flex; | |
| justify-content: space-between; | |
| align-items: center; | |
| margin-bottom: 24px; | |
| } | |
| .content-header h1 { font-size: 27px; margin: 0; font-weight: 400; } | |
| .ask-btn { | |
| background-color: var(--blue); | |
| color: white; | |
| border: none; | |
| padding: 10px 15px; | |
| border-radius: 3px; | |
| font-size: 13px; | |
| cursor: pointer; | |
| box-shadow: inset 0 1px 0 0 rgba(255,255,255,0.4); | |
| } | |
| .filter-bar { | |
| display: flex; | |
| justify-content: flex-end; | |
| margin-bottom: 15px; | |
| border-bottom: 1px solid var(--border); | |
| padding-bottom: 15px; | |
| } | |
| .btn-group { border: 1px solid var(--black-700); border-radius: 3px; display: flex; } | |
| .btn-group button { | |
| background: white; | |
| border: none; | |
| border-right: 1px solid var(--black-700); | |
| padding: 8px 10px; | |
| font-size: 12px; | |
| cursor: pointer; | |
| color: var(--black-700); | |
| } | |
| .btn-group button:last-child { border-right: none; } | |
| .btn-group button.active { background-color: #e3e6e8; color: var(--black); } | |
| /* --- QUESTIONS LIST --- */ | |
| .question-item { | |
| display: flex; | |
| padding: 16px; | |
| border-bottom: 1px solid var(--border); | |
| } | |
| .stats { | |
| display: flex; | |
| flex-direction: column; | |
| align-items: flex-end; | |
| margin-right: 16px; | |
| font-size: 13px; | |
| gap: 6px; | |
| min-width: 60px; | |
| color: var(--black-700); | |
| } | |
| .stats .votes { color: var(--black); } | |
| .stats .answers { border: 1px solid #48a868; color: #48a868; padding: 2px 4px; border-radius: 3px; } | |
| .stats .answers.has-answers { background-color: #48a868; color: white; } | |
| .q-summary { flex-grow: 1; } | |
| .q-title { | |
| color: var(--blue-dark); | |
| font-size: 17px; | |
| margin: 0 0 5px 0; | |
| text-decoration: none; | |
| cursor: pointer; | |
| } | |
| .q-excerpt { | |
| font-size: 13px; | |
| color: #3b4045; | |
| margin: 0 0 8px 0; | |
| line-height: 1.4; | |
| display: -webkit-box; | |
| -webkit-line-clamp: 2; | |
| -webkit-box-orient: vertical; | |
| overflow: hidden; | |
| } | |
| .tags { display: flex; gap: 5px; margin-bottom: 10px; } | |
| .tag { | |
| background-color: #e1ecf4; | |
| color: #39739d; | |
| font-size: 12px; | |
| padding: 4px 6px; | |
| border-radius: 3px; | |
| text-decoration: none; | |
| } | |
| .user-card { | |
| display: flex; | |
| justify-content: flex-end; | |
| font-size: 12px; | |
| color: var(--black-700); | |
| } | |
| /* --- CHATBOT WIDGET --- */ | |
| .chat-toggle { | |
| position: fixed; | |
| bottom: 20px; | |
| right: 20px; | |
| width: 60px; | |
| height: 60px; | |
| background-color: var(--orange); | |
| border-radius: 50%; | |
| box-shadow: 0 4px 12px rgba(0,0,0,0.2); | |
| display: flex; | |
| justify-content: center; | |
| align-items: center; | |
| cursor: pointer; | |
| z-index: 1000; | |
| transition: transform 0.2s; | |
| } | |
| .chat-toggle:hover { transform: scale(1.05); } | |
| .chat-toggle svg { width: 30px; height: 30px; fill: white; } | |
| .chat-window { | |
| position: fixed; | |
| bottom: 90px; | |
| right: 20px; | |
| width: 350px; | |
| height: 500px; | |
| background-color: white; | |
| border: 1px solid var(--border); | |
| border-radius: 8px; | |
| box-shadow: 0 5px 20px rgba(0,0,0,0.15); | |
| display: flex; | |
| flex-direction: column; | |
| z-index: 999; | |
| transform-origin: bottom right; | |
| transform: scale(0); | |
| transition: transform 0.3s ease; | |
| overflow: hidden; | |
| font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; | |
| } | |
| .chat-window.open { transform: scale(1); } | |
| .chat-header { | |
| background-color: var(--orange); | |
| color: white; | |
| padding: 15px; | |
| font-weight: bold; | |
| display: flex; | |
| justify-content: space-between; | |
| align-items: center; | |
| } | |
| .chat-close { cursor: pointer; font-size: 1.2rem; } | |
| .chat-messages { | |
| flex-grow: 1; | |
| padding: 15px; | |
| overflow-y: auto; | |
| background-color: #f1f2f3; | |
| display: flex; | |
| flex-direction: column; | |
| gap: 10px; | |
| } | |
| .message { | |
| max-width: 85%; | |
| padding: 10px; | |
| border-radius: 8px; | |
| font-size: 14px; | |
| line-height: 1.4; | |
| word-wrap: break-word; | |
| } | |
| .message.bot { | |
| background-color: white; | |
| align-self: flex-start; | |
| border: 1px solid #e0e0e0; | |
| } | |
| .message.user { | |
| background-color: #dbeafe; /* Light blue */ | |
| align-self: flex-end; | |
| color: #1e40af; | |
| } | |
| .message strong { font-weight: bold; } | |
| .message code { | |
| background-color: #f6f6f6; | |
| padding: 2px 4px; | |
| border-radius: 3px; | |
| font-family: monospace; | |
| font-size: 90%; | |
| } | |
| .message pre { | |
| background-color: #f6f6f6; | |
| padding: 10px; | |
| border-radius: 5px; | |
| overflow-x: auto; | |
| margin: 5px 0; | |
| } | |
| .chat-input-area { | |
| padding: 10px; | |
| border-top: 1px solid var(--border); | |
| display: flex; | |
| gap: 5px; | |
| background: white; | |
| } | |
| .chat-input-area input { | |
| flex-grow: 1; | |
| padding: 10px; | |
| border: 1px solid var(--border); | |
| border-radius: 4px; | |
| outline: none; | |
| } | |
| .chat-input-area input:focus { border-color: var(--blue); } | |
| .chat-send { | |
| background-color: var(--blue); | |
| color: white; | |
| border: none; | |
| padding: 0 15px; | |
| border-radius: 4px; | |
| cursor: pointer; | |
| font-weight: bold; | |
| } | |
| .chat-send:disabled { background-color: #ccc; cursor: not-allowed; } | |
| /* Loading Dots */ | |
| .typing-indicator { font-style: italic; color: #888; font-size: 12px; margin-left: 5px; display: none; } | |
| </style> | |
| </head> | |
| <body> | |
| <header> | |
| <div class="logo"> | |
| <div class="icon-stack"></div> | |
| <span>stack</span><b>overflow</b> | |
| </div> | |
| <div class="search-bar"> | |
| <span class="search-icon">🔍</span> | |
| <input type="text" placeholder="Search..."> | |
| </div> | |
| <div class="nav-links"> | |
| <div class="nav-btn primary">Log in</div> | |
| <div class="nav-btn blue">Sign up</div> | |
| </div> | |
| </header> | |
| <div class="container"> | |
| <nav class="sidebar"> | |
| <ul> | |
| <li><a href="#" class="active">Home</a></li> | |
| <li><span style="padding: 8px 10px; color: #888; text-transform: uppercase; font-size: 11px;">Public</span></li> | |
| <li><a href="#">Questions</a></li> | |
| <li><a href="#">Tags</a></li> | |
| <li><a href="#">Users</a></li> | |
| <li><a href="#">Companies</a></li> | |
| </ul> | |
| </nav> | |
| <main class="content"> | |
| <div class="content-header"> | |
| <h1>Top Questions</h1> | |
| <button class="ask-btn">Ask Question</button> | |
| </div> | |
| <div class="filter-bar"> | |
| <div class="btn-group"> | |
| <button class="active">Interesting</button> | |
| <button>Hot</button> | |
| <button>Week</button> | |
| <button>Month</button> | |
| </div> | |
| </div> | |
| <div id="questions-list"> | |
| <div class="question-item"> | |
| <div class="stats"> | |
| <div class="votes"><strong>12</strong> votes</div> | |
| <div class="answers has-answers"><strong>4</strong> answers</div> | |
| <div class="views">123 views</div> | |
| </div> | |
| <div class="q-summary"> | |
| <div class="q-title">How do I merge two dictionaries in a single expression in Python?</div> | |
| <div class="q-excerpt">I want to merge two dictionaries into a new one. I have x = {'a': 1, 'b': 2} and y = {'b': 3, 'c': 4}. I want z = {'a': 1, 'b': 3, 'c': 4}. How do I do this effectively?</div> | |
| <div class="tags"> | |
| <a href="#" class="tag">python</a> | |
| <a href="#" class="tag">dictionary</a> | |
| <a href="#" class="tag">merge</a> | |
| </div> | |
| <div class="user-card">asked 2 min ago by <strong>py_dev_99</strong></div> | |
| </div> | |
| </div> | |
| <div class="question-item"> | |
| <div class="stats"> | |
| <div class="votes"><strong>5</strong> votes</div> | |
| <div class="answers"><strong>0</strong> answers</div> | |
| <div class="views">45 views</div> | |
| </div> | |
| <div class="q-summary"> | |
| <div class="q-title">Java Stream API - filtering and collecting a list of objects</div> | |
| <div class="q-excerpt">I have a list of Person objects. I want to filter out anyone under 18 and collect their names into a List<String>. What is the most concise way to do this using Streams?</div> | |
| <div class="tags"> | |
| <a href="#" class="tag">java</a> | |
| <a href="#" class="tag">stream-api</a> | |
| <a href="#" class="tag">lambda</a> | |
| </div> | |
| <div class="user-card">asked 15 min ago by <strong>java_guru</strong></div> | |
| </div> | |
| </div> | |
| <div class="question-item"> | |
| <div class="stats"> | |
| <div class="votes"><strong>0</strong> votes</div> | |
| <div class="answers"><strong>0</strong> answers</div> | |
| <div class="views">8 views</div> | |
| </div> | |
| <div class="q-summary"> | |
| <div class="q-title">Understanding Python's GIL (Global Interpreter Lock)</div> | |
| <div class="q-excerpt">Can someone explain why Python has a GIL and how it affects multi-threaded applications? Is it possible to bypass it for CPU-bound tasks?</div> | |
| <div class="tags"> | |
| <a href="#" class="tag">python</a> | |
| <a href="#" class="tag">multithreading</a> | |
| <a href="#" class="tag">gil</a> | |
| </div> | |
| <div class="user-card">asked 1 hour ago by <strong>concurrency_fan</strong></div> | |
| </div> | |
| </div> | |
| </div> | |
| </main> | |
| </div> | |
| <div class="chat-toggle" id="chat-toggle" title="Ask AI Helper"> | |
| <svg viewBox="0 0 24 24"> | |
| <path d="M20 2H4c-1.1 0-2 .9-2 2v18l4-4h14c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zm0 14H6l-2 2V4h16v12z"/> | |
| </svg> | |
| </div> | |
| <div class="chat-window" id="chat-window"> | |
| <div class="chat-header"> | |
| <span>Stack Overflow AI Helper</span> | |
| <span class="chat-close" id="chat-close">×</span> | |
| </div> | |
| <div class="chat-messages" id="chat-messages"> | |
| <div class="message bot"> | |
| Hello! I am an AI assistant powered by Gemini Flash 1.5. I can help you with <strong>Python</strong> and <strong>Java</strong> queries.<br><br>To get started, please paste your Gemini API Key below. (It will not be stored permanently). | |
| </div> | |
| </div> | |
| <div class="typing-indicator" id="typing-indicator">AI is typing...</div> | |
| <div class="chat-input-area"> | |
| <input type="text" id="chat-input" placeholder="Type a message..." autocomplete="off"> | |
| <button class="chat-send" id="chat-send">Send</button> | |
| </div> | |
| </div> | |
| <script> | |
| // --- CHAT UI LOGIC --- | |
| const toggleBtn = document.getElementById('chat-toggle'); | |
| const chatWindow = document.getElementById('chat-window'); | |
| const closeBtn = document.getElementById('chat-close'); | |
| const messagesContainer = document.getElementById('chat-messages'); | |
| const inputField = document.getElementById('chat-input'); | |
| const sendBtn = document.getElementById('chat-send'); | |
| const typingIndicator = document.getElementById('typing-indicator'); | |
| let apiKey = null; | |
| toggleBtn.addEventListener('click', () => { | |
| chatWindow.classList.toggle('open'); | |
| if(chatWindow.classList.contains('open')) inputField.focus(); | |
| }); | |
| closeBtn.addEventListener('click', () => { | |
| chatWindow.classList.remove('open'); | |
| }); | |
| // Add message to chat | |
| function addMessage(text, sender) { | |
| const div = document.createElement('div'); | |
| div.classList.add('message', sender); | |
| // Basic formatting for bot messages | |
| if (sender === 'bot') { | |
| // Convert simple markdown code blocks (```...```) to <pre> | |
| let formatted = text.replace(/```([\s\S]*?)```/g, '<pre>$1</pre>'); | |
| // Convert inline code (`...`) to <code> | |
| formatted = formatted.replace(/`([^`]+)`/g, '<code>$1</code>'); | |
| // Convert bold (**...**) | |
| formatted = formatted.replace(/\*\*(.*?)\*\*/g, '<strong>$1</strong>'); | |
| div.innerHTML = formatted; | |
| } else { | |
| div.textContent = text; | |
| } | |
| messagesContainer.appendChild(div); | |
| messagesContainer.scrollTop = messagesContainer.scrollHeight; | |
| } | |
| // --- GEMINI API LOGIC --- | |
| async function callGemini(prompt) { | |
| if (!apiKey) return; | |
| typingIndicator.style.display = 'block'; | |
| const systemInstruction = ` | |
| You are a helpful assistant on a Stack Overflow-style website. | |
| You are an expert in Python and Java. | |
| 1. If the user asks a question about Python or Java, answer it clearly with code examples where necessary. | |
| 2. If the user asks about other programming languages or general life topics, politely refuse and remind them you only handle Python and Java. | |
| 3. Keep answers concise and helpful. | |
| `; | |
| const fullPrompt = systemInstruction + "\n\nUser Question: " + prompt; | |
| const url = `https://generativelanguage.googleapis.com/v1beta/models/gemini-flash-latest:generateContent?key=${apiKey}`; | |
| try { | |
| const response = await fetch(url, { | |
| method: 'POST', | |
| headers: { 'Content-Type': 'application/json' }, | |
| body: JSON.stringify({ | |
| contents: [{ | |
| parts: [{ text: fullPrompt }] | |
| }] | |
| }) | |
| }); | |
| const data = await response.json(); | |
| if (data.error) { | |
| addMessage("Error: " + data.error.message, 'bot'); | |
| } else { | |
| const text = data.candidates[0].content.parts[0].text; | |
| addMessage(text, 'bot'); | |
| } | |
| } catch (err) { | |
| addMessage("Network Error: Unable to reach Gemini API.", 'bot'); | |
| console.error(err); | |
| } finally { | |
| typingIndicator.style.display = 'none'; | |
| } | |
| } | |
| async function handleSend() { | |
| const text = inputField.value.trim(); | |
| if (!text) return; | |
| // Clear input | |
| inputField.value = ''; | |
| // If API Key is not set yet, treat this input as the key | |
| if (!apiKey) { | |
| // Basic validation (Google API keys usually start with AIza) | |
| if (text.startsWith('AIza') && text.length > 20) { | |
| apiKey = text; | |
| addMessage('API Key accepted! How can I help you with Python or Java today?', 'bot'); | |
| } else { | |
| addMessage("That doesn't look like a valid Google API Key. It should start with 'AIza'. Please try again.", 'bot'); | |
| } | |
| return; | |
| } | |
| // Normal chat flow | |
| addMessage(text, 'user'); | |
| await callGemini(text); | |
| } | |
| sendBtn.addEventListener('click', handleSend); | |
| inputField.addEventListener('keypress', (e) => { | |
| if (e.key === 'Enter') handleSend(); | |
| }); | |
| </script> | |
| </body> | |
| </html> |