Spaces:
Running

undefined / ai-lab.html
moazelgen's picture
index.tsx mport React, { useState, useRef, useEffect, useReducer, memo } from 'react';
297bb2c verified
Raw History Blame Contribute Delete
12.5 kB
<!DOCTYPE html>
<html lang="en" class="scroll-smooth">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>AI Lab | Cosmic Canvas</title>
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://unpkg.com/feather-icons"></script>
<script src="https://cdn.jsdelivr.net/npm/vanta@latest/dist/vanta.globe.min.js"></script>
<script type="module">
import { GoogleGenAI } from "https://aistudiocdn.com/@google/genai@^1.23.0";
const ai = new GoogleGenAI({ apiKey: "YOUR_API_KEY" }); // Replace with actual API key
window.ai = ai;
</script>
<style>
@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@300;400;500;600;700&display=swap');
body {
font-family: 'Space Grotesk', sans-serif;
}
#vanta-bg {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: -1;
}
.gradient-text {
background: linear-gradient(90deg, #0ea5e9 0%, #8b5cf6 100%);
-webkit-background-clip: text;
background-clip: text;
color: transparent;
}
.terminal {
background-color: #010409;
border: 1px solid #30363d;
color: #c9d1d9;
font-family: monospace;
}
</style>
</head>
<body class="bg-gray-900 text-white min-h-screen">
<div id="vanta-bg"></div>
<nav class="fixed w-full z-50 bg-gray-900/80 backdrop-blur-md">
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
<div class="flex justify-between h-16 items-center">
<div class="flex items-center">
<span class="text-2xl font-bold gradient-text">Cosmic Canvas</span>
</div>
<div class="hidden md:flex space-x-8">
<a href="index.html" class="text-white hover:text-primary-400 transition">Home</a>
<a href="gallery.html" class="text-white hover:text-primary-400 transition">Gallery</a>
<a href="ai-lab.html" class="text-white hover:text-primary-400 transition font-bold">AI Lab</a>
<a href="about.html" class="text-white hover:text-primary-400 transition">About</a>
<a href="chat.html" class="text-white hover:text-primary-400 transition">Chat</a>
<a href="tech-stack.html" class="text-white hover:text-primary-400 transition">Tech Stack</a>
<a href="tasks.html" class="text-white hover:text-primary-400 transition">Tasks</a>
<a href="external-chat.html" class="text-white hover:text-primary-400 transition">External Chat</a>
<a href="smart-chat.html" class="text-white hover:text-primary-400 transition">Smart Chat</a>
</div>
<button class="md:hidden text-white">
<i data-feather="menu"></i>
</button>
</div>
</div>
</nav>
<main class="pt-24 pb-16 px-4 sm:px-6 lg:px-8">
<section class="max-w-7xl mx-auto">
<h1 class="text-5xl md:text-7xl font-bold mb-6 text-center">
<span class="gradient-text">AI</span> Laboratory
</h1>
<div class="grid grid-cols-1 lg:grid-cols-2 gap-8 mt-12">
<div class="bg-gray-800/50 backdrop-blur-md p-6 rounded-xl border border-gray-700">
<h2 class="text-2xl font-bold mb-4">Terminal Interface</h2>
<div class="terminal p-4 h-64 overflow-y-auto mb-4" id="terminal-output">
<p>Legendary Terminal initialized...</p>
<p>Type 'help' for available commands</p>
</div>
<div class="flex">
<input type="text" id="terminal-input" class="flex-1 bg-gray-700 text-white px-4 py-2 rounded-l-lg focus:outline-none focus:ring-2 focus:ring-primary-500" placeholder="Enter command...">
<button onclick="executeCommand()" class="bg-primary-600 hover:bg-primary-700 text-white px-4 py-2 rounded-r-lg">
Execute
</button>
</div>
</div>
<div class="bg-gray-800/50 backdrop-blur-md p-6 rounded-xl border border-gray-700">
<h2 class="text-2xl font-bold mb-4">AI Playground</h2>
<div class="mb-4">
<label class="block text-gray-300 mb-2">Model</label>
<select id="ai-model" class="w-full bg-gray-700 text-white px-4 py-2 rounded-lg focus:outline-none focus:ring-2 focus:ring-primary-500">
<option value="gemini-pro">Gemini Pro</option>
<option value="gpt-4">GPT-4</option>
</select>
</div>
<div class="mb-4">
<label class="block text-gray-300 mb-2">Language</label>
<select id="ai-language" class="w-full bg-gray-700 text-white px-4 py-2 rounded-lg focus:outline-none focus:ring-2 focus:ring-primary-500">
<option value="en">English</option>
<option value="ar">العربية</option>
</select>
</div>
<div class="mb-4">
<label class="block text-gray-300 mb-2">Prompt</label>
<textarea id="ai-prompt" class="w-full bg-gray-700 text-white px-4 py-2 rounded-lg h-24 focus:outline-none focus:ring-2 focus:ring-primary-500" placeholder="اكتب رسالتك هنا / Type your message here..."></textarea>
</div>
<div id="ai-response" class="bg-gray-700 text-white p-4 rounded-lg mb-4 min-h-24 hidden">
<p class="text-gray-300">AI response will appear here...</p>
</div>
<div class="flex space-x-4">
<button id="ai-listen" class="flex-1 bg-secondary-600 hover:bg-secondary-700 text-white px-4 py-3 rounded-lg flex items-center justify-center">
<i data-feather="mic" class="mr-2"></i> Speak
</button>
<button id="ai-generate" class="flex-1 bg-primary-600 hover:bg-primary-700 text-white px-4 py-3 rounded-lg">
Generate Response
</button>
</div>
</div>
</div>
</section>
</main>
<script>
feather.replace();
// Initialize LegendaryTerminal integration
const terminalSocket = new WebSocket('ws://localhost:3000/terminal');
terminalSocket.onmessage = (event) => {
const data = JSON.parse(event.data);
if (data.type === 'terminal-output') {
const output = document.getElementById('terminal-output');
output.innerHTML += `<p>${data.content}</p>`;
output.scrollTop = output.scrollHeight;
}
};
// Speech recognition setup
const SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
const recognition = new SpeechRecognition();
recognition.lang = 'en-US';
recognition.interimResults = false;
recognition.maxAlternatives = 1;
document.getElementById('ai-language').addEventListener('change', function() {
recognition.lang = this.value === 'ar' ? 'ar-SA' : 'en-US';
});
document.getElementById('ai-listen').addEventListener('click', function() {
recognition.start();
this.innerHTML = '<i data-feather="mic-off" class="mr-2"></i> Listening...';
feather.replace();
});
recognition.onresult = function(event) {
const speechResult = event.results[0][0].transcript;
document.getElementById('ai-prompt').value = speechResult;
document.getElementById('ai-listen').innerHTML = '<i data-feather="mic" class="mr-2"></i> Speak';
feather.replace();
};
recognition.onerror = function(event) {
console.error('Speech recognition error', event.error);
document.getElementById('ai-listen').innerHTML = '<i data-feather="mic" class="mr-2"></i> Speak';
feather.replace();
};
recognition.onend = function() {
document.getElementById('ai-listen').innerHTML = '<i data-feather="mic" class="mr-2"></i> Speak';
feather.replace();
};
// AI Response handling
document.getElementById('ai-generate').addEventListener('click', async function() {
const prompt = document.getElementById('ai-prompt').value;
const language = document.getElementById('ai-language').value;
const responseElement = document.getElementById('ai-response');
if (!prompt.trim()) return;
responseElement.classList.remove('hidden');
responseElement.innerHTML = '<p class="text-gray-300">جار المعالجة... / Processing...</p>';
try {
// In a real implementation, you would call your AI API here
const response = await simulateAIResponse(prompt, language);
// Display response with appropriate RTL/LTR direction
const dir = language === 'ar' ? 'rtl' : 'ltr';
responseElement.innerHTML = `<p dir="${dir}" class="${language === 'ar' ? 'text-right' : ''}">${response}</p>`;
// Speak the response
speakResponse(response, language);
} catch (error) {
responseElement.innerHTML = `<p class="text-red-400">Error: ${error.message}</p>`;
}
});
function simulateAIResponse(prompt, language) {
return new Promise((resolve) => {
setTimeout(() => {
if (language === 'ar') {
resolve(`هذا رد من الذكاء الاصطناعي على رسالتك: "${prompt}". يمكنني فهم العربية والإنجليزية.`);
} else {
resolve(`This is an AI response to your message: "${prompt}". I can understand both English and Arabic.`);
}
}, 1500);
});
}
function speakResponse(text, language) {
const utterance = new SpeechSynthesisUtterance(text);
utterance.lang = language === 'ar' ? 'ar-SA' : 'en-US';
speechSynthesis.speak(utterance);
}
// Terminal functionality - integrated with LegendaryTerminal
function executeCommand() {
const input = document.getElementById('terminal-input').value;
const output = document.getElementById('terminal-output');
output.innerHTML += `<p><span class="text-green-400">$ ${input}</span></p>`;
document.getElementById('terminal-input').value = '';
output.scrollTop = output.scrollHeight;
// Send command to LegendaryTerminal backend
terminalSocket.send(JSON.stringify({
type: 'terminal-command',
command: input
}));
}
// WebSocket cleanup on page unload
window.addEventListener('beforeunload', () => {
terminalSocket.close();
});
// Initialize Vanta.js background
VANTA.GLOBE({
el: "#vanta-bg",
mouseControls: true,
touchControls: true,
gyroControls: false,
minHeight: 200.00,
minWidth: 200.00,
scale: 1.00,
scaleMobile: 1.00,
color: 0x3b82f6,
backgroundColor: 0x111827
});
</script>
<style>
#terminal-output {
font-family: 'Space Grotesk', monospace;
white-space: pre-wrap;
line-height: 1.5;
}
#terminal-input {
font-family: 'Space Grotesk', monospace;
}
</style>
</body>
</html>