Download index.html from maxwar/mwai: direct link, hf CLI and curl.
- Browser
- Download file 41.3 kB
-
https://huggingface.co/spaces/maxwar/mwai/resolve/main/index.html
- Command line
-
hf download hf://spaces/maxwar/mwai/index.html
-
curl -L -o index.html https://huggingface.co/spaces/maxwar/mwai/resolve/main/index.html
41.3 kB
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>MWAI</title> | |
| <script src="https://cdn.tailwindcss.com"></script> | |
| <script src="https://cdn.jsdelivr.net/npm/react@18.2.0/umd/react.development.js"></script> | |
| <script src="https://cdn.jsdelivr.net/npm/react-dom@18.2.0/umd/react-dom.development.js"></script> | |
| <script src="https://cdn.jsdelivr.net/npm/@babel/standalone@7.20.15/babel.min.js"></script> | |
| <script src="https://cdn.jsdelivr.net/npm/marked@4.0.12/marked.min.js"></script> | |
| <script src="https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.33.0/min/vs/loader.min.js"></script> | |
| <script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.18.5/xlsx.full.min.js"></script> | |
| <script src="https://challenges.cloudflare.com/turnstile/v0/api.js" async defer></script> | |
| <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet"> | |
| <style> | |
| :root { | |
| --blur-amount: 10px; | |
| --neumorphic-shadow: 4px 4px 8px rgba(0, 0, 0, 0.15), -4px -4px 8px rgba(255, 255, 255, 0.7); | |
| --neumorphic-shadow-dark: 4px 4px 8px rgba(0, 0, 0, 0.3), -4px -4px 8px rgba(255, 255, 255, 0.1); | |
| } | |
| @keyframes slideIn { | |
| from { transform: translateY(20px); opacity: 0; } | |
| to { transform: translateY(0); opacity: 1; } | |
| } | |
| @keyframes blink { | |
| 50% { opacity: 0; } | |
| } | |
| @keyframes pulse { | |
| 0% { transform: scale(1); } | |
| 50% { transform: scale(1.1); } | |
| 100% { transform: scale(1); } | |
| } | |
| .message-enter { animation: slideIn 0.3s ease-out; } | |
| .typing-cursor::after { | |
| content: '|'; | |
| display: inline-block; | |
| animation: blink 0.7s infinite; | |
| margin-left: 2px; | |
| } | |
| .tooltip { position: relative; } | |
| .tooltip:hover::after { | |
| content: attr(data-tooltip); | |
| position: absolute; | |
| bottom: 100%; | |
| left: 50%; | |
| transform: translateX(-50%); | |
| background: #1f2937; | |
| color: white; | |
| padding: 4px 8px; | |
| border-radius: 4px; | |
| font-size: 12px; | |
| white-space: nowrap; | |
| z-index: 10; | |
| } | |
| .markdown-body { | |
| font-family: 'Inter', sans-serif; | |
| line-height: 1.6; | |
| color: inherit; | |
| } | |
| .markdown-body h1, .markdown-body h2, .markdown-body h3 { | |
| font-weight: 600; | |
| margin: 0.5em 0; | |
| } | |
| .markdown-body p { margin: 0.5em 0; } | |
| .markdown-body ul, .markdown-body ol { | |
| margin: 0.5em 0; | |
| padding-left: 1.5em; | |
| } | |
| .markdown-body code { | |
| background: rgba(0, 0, 0, 0.1); | |
| padding: 2px 4px; | |
| border-radius: 4px; | |
| font-family: 'Courier New', monospace; | |
| } | |
| .markdown-body pre { | |
| background: rgba(0, 0, 0, 0.1); | |
| padding: 1em; | |
| border-radius: 4px; | |
| overflow-x: auto; | |
| } | |
| .markdown-body strong { font-weight: 600; } | |
| .markdown-body em { font-style: italic; } | |
| #editor, #canvas, #data-preview { height: 100%; width: 100%; } | |
| .glassmorphic { | |
| background: rgba(255, 255, 255, 0.1); | |
| backdrop-filter: blur(var(--blur-amount)); | |
| -webkit-backdrop-filter: blur(var(--blur-amount)); | |
| border: 1px solid rgba(255, 255, 255, 0.2); | |
| box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); | |
| } | |
| .neumorphic { | |
| border-radius: 12px; | |
| box-shadow: var(--neumorphic-shadow); | |
| } | |
| .dark .neumorphic { | |
| box-shadow: var(--neumorphic-shadow-dark); | |
| } | |
| .tab { | |
| transition: all 0.3s ease; | |
| } | |
| .tab.active { | |
| background: rgba(79, 70, 229, 0.3); | |
| color: white; | |
| transform: scale(1.05); | |
| } | |
| .loading-spinner { | |
| border: 4px solid rgba(0, 0, 0, 0.1); | |
| border-left-color: #4f46e5; | |
| border-radius: 50%; | |
| width: 24px; | |
| height: 24px; | |
| animation: spin 1s linear infinite; | |
| } | |
| @keyframes spin { | |
| to { transform: rotate(360deg); } | |
| } | |
| .pulse { | |
| animation: pulse 1.5s infinite; | |
| } | |
| .dropzone { | |
| border: 2px dashed #4f46e5; | |
| transition: all 0.3s ease; | |
| } | |
| .dropzone.dragover { | |
| background: rgba(79, 70, 229, 0.1); | |
| border-color: #7c3aed; | |
| } | |
| </style> | |
| </head> | |
| <body className="min-h-screen flex items-center justify-center transition-colors duration-300"> | |
| <div id="root"></div> | |
| <script type="text/javascript"> | |
| var gk_isXlsx = false; | |
| var gk_xlsxFileLookup = {}; | |
| var gk_fileData = {}; | |
| function filledCell(cell) { | |
| return cell !== '' && cell != null; | |
| } | |
| function loadFileData(filename) { | |
| if (gk_isXlsx && gk_xlsxFileLookup[filename]) { | |
| try { | |
| var workbook = XLSX.read(gk_fileData[filename], { type: 'base64' }); | |
| var firstSheetName = workbook.SheetNames[0]; | |
| var worksheet = workbook.Sheets[firstSheetName]; | |
| var jsonData = XLSX.utils.sheet_to_json(worksheet, { header: 1, blankrows: false, defval: '' }); | |
| var filteredData = jsonData.filter(row => row.some(filledCell)); | |
| var headerRowIndex = filteredData.findIndex((row, index) => | |
| row.filter(filledCell).length >= filteredData[index + 1]?.filter(filledCell).length | |
| ); | |
| if (headerRowIndex === -1 || headerRowIndex > 25) { | |
| headerRowIndex = 0; | |
| } | |
| var csv = XLSX.utils.aoa_to_sheet(filteredData.slice(headerRowIndex)); | |
| csv = XLSX.utils.sheet_to_csv(csv, { header: 1 }); | |
| return csv; | |
| } catch (e) { | |
| console.error(e); | |
| return ""; | |
| } | |
| } | |
| return gk_fileData[filename] || ""; | |
| } | |
| </script> | |
| <script type="text/babel"> | |
| const { useState, useEffect, useRef } = React; | |
| const API_KEY = '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'; | |
| const API_URL = 'https://openrouter.ai/api/v1/chat/completions'; | |
| const currentModel = 'meta-llama/llama-3.1-8b-instruct'; | |
| const ChatApp = () => { | |
| const [messages, setMessages] = useState(() => { | |
| const saved = localStorage.getItem('chatMessages'); | |
| return saved ? JSON.parse(saved) : []; | |
| }); | |
| const [input, setInput] = useState(''); | |
| const [isLoading, setIsLoading] = useState(false); | |
| const [typingText, setTypingText] = useState(''); | |
| const [deepSearch, setDeepSearch] = useState(false); | |
| const [thinkMode, setThinkMode] = useState(false); | |
| const [darkMode, setDarkMode] = useState(() => { | |
| return localStorage.getItem('darkMode') === 'true'; | |
| }); | |
| const [activeTab, setActiveTab] = useState('chat'); | |
| const [showCodeEditor, setShowCodeEditor] = useState(false); | |
| const [code, setCode] = useState(''); | |
| const [previewUrl, setPreviewUrl] = useState(''); | |
| const [files, setFiles] = useState([]); | |
| const [selectedFile, setSelectedFile] = useState(null); | |
| const [brushSize, setBrushSize] = useState(5); | |
| const [brushColor, setBrushColor] = useState('#000000'); | |
| const [calcInput, setCalcInput] = useState(''); | |
| const [calcResult, setCalcResult] = useState(''); | |
| const [isRecording, setIsRecording] = useState(false); | |
| const chatAreaRef = useRef(null); | |
| const editorRef = useRef(null); | |
| const canvasRef = useRef(null); | |
| const monacoRef = useRef(null); | |
| const mediaRecorderRef = useRef(null); | |
| const drawingContextRef = useRef(null); | |
| const isDrawingRef = useRef(false); | |
| useEffect(() => { | |
| localStorage.setItem('chatMessages', JSON.stringify(messages)); | |
| localStorage.setItem('darkMode', darkMode); | |
| document.body.className = `min-h-screen flex items-center justify-center transition-colors duration-300 ${darkMode ? 'bg-gray-900 dark' : 'bg-gray-100'}`; | |
| if (chatAreaRef.current) { | |
| chatAreaRef.current.scrollTop = chatAreaRef.current.scrollHeight; | |
| } | |
| }, [messages, darkMode]); | |
| useEffect(() => { | |
| if (isLoading) { | |
| const loadingMessages = [ | |
| thinkMode ? 'Thinking deeply...' : deepSearch ? 'Searching the web...' : 'Processing...', | |
| 'Analyzing your query...', | |
| 'Generating response...', | |
| ]; | |
| let currentIndex = 0; | |
| let charIndex = 0; | |
| const typeInterval = setInterval(() => { | |
| const currentMessage = loadingMessages[currentIndex]; | |
| if (charIndex <= currentMessage.length) { | |
| setTypingText(currentMessage.slice(0, charIndex)); | |
| charIndex++; | |
| } else { | |
| charIndex = 0; | |
| currentIndex = (currentIndex + 1) % loadingMessages.length; | |
| } | |
| }, 50); | |
| return () => clearInterval(typeInterval); | |
| } else { | |
| setTypingText(''); | |
| } | |
| }, [isLoading, thinkMode, deepSearch]); | |
| useEffect(() => { | |
| if (showCodeEditor && !monacoRef.current) { | |
| require.config({ paths: { 'vs': 'https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.33.0/min/vs' } }); | |
| require(['vs/editor/editor.main'], () => { | |
| monacoRef.current = monaco.editor.create(editorRef.current, { | |
| value: code, | |
| language: 'html', | |
| theme: darkMode ? 'vs-dark' : 'vs', | |
| automaticLayout: true, | |
| minimap: { enabled: false }, | |
| fontSize: 14, | |
| }); | |
| monacoRef.current.onDidChangeModelContent(() => { | |
| const newCode = monacoRef.current.getValue(); | |
| setCode(newCode); | |
| updatePreview(newCode); | |
| }); | |
| }); | |
| } | |
| return () => { | |
| if (monacoRef.current) { | |
| monacoRef.current.dispose(); | |
| monacoRef.current = null; | |
| } | |
| }; | |
| }, [showCodeEditor, darkMode]); | |
| useEffect(() => { | |
| if (monacoRef.current) { | |
| monacoRef.current.updateOptions({ theme: darkMode ? 'vs-dark' : 'vs' }); | |
| } | |
| }, [darkMode]); | |
| useEffect(() => { | |
| if (activeTab === 'drawing' && canvasRef.current) { | |
| const canvas = canvasRef.current; | |
| const ctx = canvas.getContext('2d'); | |
| drawingContextRef.current = ctx; | |
| canvas.width = canvas.offsetWidth; | |
| canvas.height = canvas.offsetHeight; | |
| ctx.lineCap = 'round'; | |
| ctx.lineJoin = 'round'; | |
| } | |
| }, [activeTab, darkMode]); | |
| const updatePreview = (code) => { | |
| const blob = new Blob([code], { type: 'text/html' }); | |
| const url = URL.createObjectURL(blob); | |
| setPreviewUrl(url); | |
| return () => URL.revokeObjectURL(url); | |
| }; | |
| const sendMessage = async (prompt = null) => { | |
| const message = prompt || input.trim(); | |
| if (!message) return; | |
| const newUserMessage = { | |
| role: 'user', | |
| content: message, | |
| timestamp: new Date().toISOString(), | |
| }; | |
| setMessages(prev => [...prev, newUserMessage]); | |
| setInput(''); | |
| setIsLoading(true); | |
| try { | |
| if (thinkMode) await new Promise(resolve => setTimeout(resolve, 1000)); | |
| if (deepSearch) await new Promise(resolve => setTimeout(resolve, 1500)); | |
| const isCodeRequest = /generate.*(html|css|javascript|web|website|page)|create.*(html|css|javascript|web|website|page)|make.*(html|css|javascript|web|website|page)/i.test(message); | |
| const response = await fetch(API_URL, { | |
| method: 'POST', | |
| headers: { | |
| 'Content-Type': 'application/json', | |
| 'Authorization': `Bearer ${API_KEY}`, | |
| }, | |
| body: JSON.stringify({ | |
| model: currentModel, | |
| messages: [...messages, newUserMessage].map(m => ({ | |
| role: m.role, | |
| content: isCodeRequest | |
| ? m.content + ' Provide a complete HTML file with embedded CSS and JavaScript, wrapped in a single code block.' | |
| : m.content + (deepSearch ? ' [DeepSearch enabled]' : '') + (thinkMode ? ' [Think mode enabled]' : '') | |
| })), | |
| max_tokens: 4096, | |
| }), | |
| }); | |
| if (!response.ok) throw new Error('API request failed'); | |
| const data = await response.json(); | |
| let botMessageContent = data.choices[0].message.content; | |
| if (isCodeRequest) { | |
| const codeMatch = botMessageContent.match(/```(?:html)?\n([\s\S]*?)\n```/); | |
| if (codeMatch && codeMatch[1]) { | |
| setCode(codeMatch[1]); | |
| setShowCodeEditor(true); | |
| setActiveTab('code'); | |
| updatePreview(codeMatch[1]); | |
| botMessageContent = 'I have generated the code. You can view and edit it in the code editor under the Code tab, with a live preview.'; | |
| } else { | |
| botMessageContent = 'Sorry, I couldn’t extract valid HTML/CSS/JS code from the response. Please try again.'; | |
| } | |
| } | |
| const botMessage = { | |
| role: 'bot', | |
| content: botMessageContent, | |
| timestamp: new Date().toISOString(), | |
| }; | |
| setMessages(prev => [...prev, botMessage]); | |
| } catch (error) { | |
| setMessages(prev => [...prev, { | |
| role: 'bot', | |
| content: `Error: ${error.message}`, | |
| timestamp: new Date().toISOString(), | |
| }]); | |
| } finally { | |
| setIsLoading(false); | |
| } | |
| }; | |
| const handleKeyPress = (e) => { | |
| if (e.key === 'Enter' && !e.shiftKey) { | |
| e.preventDefault(); | |
| sendMessage(); | |
| } | |
| }; | |
| const clearChat = () => { | |
| setMessages([]); | |
| setShowCodeEditor(false); | |
| setCode(''); | |
| setPreviewUrl(''); | |
| setFiles([]); | |
| setSelectedFile(null); | |
| setCalcInput(''); | |
| setCalcResult(''); | |
| if (canvasRef.current) { | |
| const ctx = canvasRef.current.getContext('2d'); | |
| ctx.clearRect(0, 0, canvasRef.current.width, canvasRef.current.height); | |
| } | |
| localStorage.removeItem('chatMessages'); | |
| }; | |
| const downloadChat = () => { | |
| const chatJson = JSON.stringify(messages, null, 2); | |
| const blob = new Blob([chatJson], { type: 'application/json' }); | |
| const url = URL.createObjectURL(blob); | |
| const a = document.createElement('a'); | |
| a.href = url; | |
| a.download = `chat_${new Date().toISOString()}.json`; | |
| a.click(); | |
| URL.revokeObjectURL(url); | |
| }; | |
| const copyMessage = (content) => { | |
| navigator.clipboard.writeText(content); | |
| alert('Message copied to clipboard!'); | |
| }; | |
| const formatTimestamp = (timestamp) => { | |
| return new Date(timestamp).toLocaleString(); | |
| }; | |
| const renderMarkdown = (text) => { | |
| return { __html: marked.parse(text, { breaks: true }) }; | |
| }; | |
| const handleFileUpload = (e) => { | |
| const uploadedFiles = Array.from(e.target.files || e.dataTransfer.files); | |
| uploadedFiles.forEach(file => { | |
| const reader = new FileReader(); | |
| reader.onload = (event) => { | |
| const data = event.target.result; | |
| const fileName = file.name; | |
| gk_fileData[fileName] = data.split(',')[1]; | |
| if (fileName.endsWith('.xlsx') || fileName.endsWith('.xls')) { | |
| gk_isXlsx = true; | |
| gk_xlsxFileLookup[fileName] = true; | |
| } | |
| setFiles(prev => [...prev, { name: fileName, data: loadFileData(fileName) }]); | |
| }; | |
| reader.readAsDataURL(file); | |
| }); | |
| }; | |
| const handleDragOver = (e) => { | |
| e.preventDefault(); | |
| e.currentTarget.classList.add('dragover'); | |
| }; | |
| const handleDragLeave = (e) => { | |
| e.currentTarget.classList.remove('dragover'); | |
| }; | |
| const handleDrop = (e) => { | |
| e.preventDefault(); | |
| e.currentTarget.classList.remove('dragover'); | |
| handleFileUpload(e); | |
| }; | |
| const handleFileSelect = (file) => { | |
| setSelectedFile(file); | |
| }; | |
| const handleCanvasMouseDown = (e) => { | |
| isDrawingRef.current = true; | |
| const ctx = drawingContextRef.current; | |
| ctx.beginPath(); | |
| ctx.moveTo(e.nativeEvent.offsetX, e.nativeEvent.offsetY); | |
| }; | |
| const handleCanvasMouseMove = (e) => { | |
| if (!isDrawingRef.current) return; | |
| const ctx = drawingContextRef.current; | |
| ctx.lineWidth = brushSize; | |
| ctx.strokeStyle = brushColor; | |
| ctx.lineTo(e.nativeEvent.offsetX, e.nativeEvent.offsetY); | |
| ctx.stroke(); | |
| }; | |
| const handleCanvasMouseUp = () => { | |
| isDrawingRef.current = false; | |
| drawingContextRef.current.closePath(); | |
| }; | |
| const clearCanvas = () => { | |
| if (canvasRef.current) { | |
| const ctx = canvasRef.current.getContext('2d'); | |
| ctx.clearRect(0, 0, canvasRef.current.width, canvasRef.current.height); | |
| } | |
| }; | |
| const calculate = () => { | |
| try { | |
| const result = eval(calcInput.replace(/[^0-9+\-*/().]/g, '')); | |
| setCalcResult(result.toString()); | |
| } catch (error) { | |
| setCalcResult('Error'); | |
| } | |
| }; | |
| const handleCalcKeyPress = (e) => { | |
| if (e.key === 'Enter') { | |
| calculate(); | |
| } | |
| }; | |
| const startRecording = async () => { | |
| try { | |
| const stream = await navigator.mediaDevices.getUserMedia({ audio: true }); | |
| mediaRecorderRef.current = new MediaRecorder(stream); | |
| mediaRecorderRef.current.start(); | |
| setIsRecording(true); | |
| mediaRecorderRef.current.ondataavailable = (e) => { | |
| // Placeholder for handling recorded audio | |
| console.log('Audio data available'); | |
| }; | |
| mediaRecorderRef.current.onstop = () => { | |
| stream.getTracks().forEach(track => track.stop()); | |
| }; | |
| } catch (error) { | |
| alert('Microphone access denied or unavailable'); | |
| } | |
| }; | |
| const stopRecording = () => { | |
| if (mediaRecorderRef.current) { | |
| mediaRecorderRef.current.stop(); | |
| setIsRecording(false); | |
| } | |
| }; | |
| const suggestions = [ | |
| { text: 'Plan for higher education', prompt: 'Plan for higher education' }, | |
| { text: '9.9 vs 9.11: Which one is bigger?', prompt: '9.9 vs 9.11: Which one is bigger?' }, | |
| { text: 'How many r\'s in strawberry?', prompt: 'How many r\'s are in the word strawberry?' }, | |
| { text: 'Compose a 10-line poem', prompt: 'Compose a 10-line poem' }, | |
| { text: 'Draft a portfolio management plan', prompt: 'Draft up a portfolio management plan' }, | |
| { text: 'Generate a simple HTML webpage', prompt: 'Generate a simple HTML webpage' }, | |
| ]; | |
| return ( | |
| <div className={`max-w-5xl w-full mx-auto rounded-2xl shadow-2xl overflow-hidden transition-colors duration-300 glassmorphic ${darkMode ? 'bg-gray-800/50 text-white' : 'bg-white/50 text-gray-900'}`}> | |
| <header className={`p-4 flex justify-between items-center ${darkMode ? 'bg-gradient-to-r from-indigo-900 to-purple-900' : 'bg-gradient-to-r from-indigo-600 to-purple-600'} text-white glassmorphic`}> | |
| <div> | |
| <h1 className="text-2xl font-bold tracking-tight">MWAI</h1> | |
| <p className="text-sm opacity-80">Powered by MWAI | Model: LLaMA 3.1 8B</p> | |
| </div> | |
| <div className="flex gap-4"> | |
| <button onClick={clearChat} className="tooltip neumorphic p-2 hover:opacity-80" data-tooltip="Clear All"> | |
| <img src="https://img.icons8.com/ios-filled/50/trash.png" alt="Clear" className="w-6 h-6 filter invert" /> | |
| </button> | |
| <button onClick={downloadChat} className="tooltip neumorphic p-2 hover:opacity-80" data-tooltip="Download Chat"> | |
| <img src="https://img.icons8.com/ios-filled/50/download.png" alt="Download" className="w-6 h-6 filter invert" /> | |
| </button> | |
| <button onClick={() => setDarkMode(!darkMode)} className="tooltip neumorphic p-2 hover:opacity-80" data-tooltip={darkMode ? 'Light Mode' : 'Dark Mode'}> | |
| <img src={`https://img.icons8.com/ios-filled/50/${darkMode ? 'sun' : 'moon'}.png`} alt="Toggle Theme" className="w-6 h-6 filter invert" /> | |
| </button> | |
| </div> | |
| </header> | |
| <div className={`p-4 border-b ${darkMode ? 'bg-gray-700/50' : 'bg-gray-50/50'} glassmorphic`}> | |
| <div className="flex flex-wrap gap-2"> | |
| {['chat', 'code', 'data', 'drawing', 'calculator'].map(tab => ( | |
| <button | |
| key={tab} | |
| onClick={() => setActiveTab(tab)} | |
| className={`px-4 py-2 rounded-full text-sm font-medium transition-all duration-200 transform hover:scale-105 tab neumorphic ${activeTab === tab ? 'active' : darkMode ? 'bg-gray-600/50 text-gray-200' : 'bg-gray-200/50 text-gray-700'}`} | |
| > | |
| {tab.charAt(0).toUpperCase() + tab.slice(1)} | |
| </button> | |
| ))} | |
| <button | |
| onClick={() => setDeepSearch(!deepSearch)} | |
| className={`px-4 py-2 rounded-full text-sm font-medium transition-all duration-200 transform hover:scale-105 neumorphic ${deepSearch ? 'bg-indigo-600 text-white' : darkMode ? 'bg-gray-600/50 text-gray-200' : 'bg-gray-200/50 text-gray-700'}`} | |
| > | |
| DeepSearch {deepSearch ? 'On' : 'Off'} | |
| </button> | |
| <button | |
| onClick={() => setThinkMode(!thinkMode)} | |
| className={`px-4 py-2 rounded-full text-sm font-medium transition-all duration-200 transform hover:scale-105 neumorphic ${thinkMode ? 'bg-purple-600 text-white' : darkMode ? 'bg-gray-600/50 text-gray-200' : 'bg-gray-200/50 text-gray-700'}`} | |
| > | |
| Think Mode {thinkMode ? 'On' : 'Off'} | |
| </button> | |
| </div> | |
| </div> | |
| <div className="p-6"> | |
| {activeTab === 'chat' && ( | |
| <div ref={chatAreaRef} className={`h-[600px] p-6 rounded-lg overflow-y-auto ${darkMode ? 'bg-gray-800/50' : 'bg-white/50'} glassmorphic`}> | |
| {messages.map((msg, index) => ( | |
| <div | |
| key={index} | |
| className={`mb-4 p-4 rounded-lg max-w-[80%] message-enter flex flex-col gap-2 neumorphic ${msg.role === 'user' ? darkMode ? 'bg-indigo-900/50 ml-auto text-right' : 'bg-indigo-100/50 ml-auto text-right' : darkMode ? 'bg-gray-700/50 mr-auto' : 'bg-gray-100/50 mr-auto'}`} | |
| > | |
| <div className="flex justify-between items-center"> | |
| <span className="text-xs opacity-70">{formatTimestamp(msg.timestamp)}</span> | |
| <button | |
| onClick={() => copyMessage(msg.content)} | |
| className="tooltip text-xs opacity-70 hover:opacity-100" | |
| data-tooltip="Copy Message" | |
| > | |
| <img src="https://img.icons8.com/ios-filled/50/copy.png" alt="Copy" className={`w-4 h-4 ${darkMode ? 'filter invert' : ''}`} /> | |
| </button> | |
| </div> | |
| {msg.role === 'bot' ? ( | |
| <div className="markdown-body text-sm" dangerouslySetInnerHTML={renderMarkdown(msg.content)} /> | |
| ) : ( | |
| <p className="text-sm whitespace-pre-wrap">{msg.content}</p> | |
| )} | |
| </div> | |
| ))} | |
| {isLoading && ( | |
| <div className={`mb-4 p-4 rounded-lg ${darkMode ? 'bg-gray-700/50' : 'bg-gray-100/50'} mr-auto text-sm ${darkMode ? 'text-gray-400' : 'text-gray-500'} message-enter typing-cursor neumorphic`}> | |
| {typingText} | |
| </div> | |
| )} | |
| </div> | |
| )} | |
| {activeTab === 'code' && ( | |
| <div className={`h-[600px] p-6 rounded-lg ${darkMode ? 'bg-gray-800/50' : 'bg-white/50'} glassmorphic`}> | |
| {showCodeEditor ? ( | |
| <div> | |
| <div className="flex justify-between items-center mb-4"> | |
| <h2 className="text-lg font-semibold">Code Editor & Preview</h2> | |
| <button | |
| onClick={() => setShowCodeEditor(false)} | |
| className="px-4 py-2 bg-red-600 text-white rounded-lg hover:bg-red-700 transition-all duration-200 neumorphic" | |
| > | |
| Close Editor | |
| </button> | |
| </div> | |
| <div className="grid grid-cols-2 gap-4 h-[500px]"> | |
| <div id="editor" ref={editorRef} className="border rounded-lg overflow-hidden"></div> | |
| <iframe | |
| src={previewUrl} | |
| className="border rounded-lg bg-white" | |
| title="Code Preview" | |
| ></iframe> | |
| </div> | |
| </div> | |
| ) : ( | |
| <div className="flex items-center justify-center h-full"> | |
| <p className="text-gray-500">No code generated yet. Try asking for a webpage!</p> | |
| </div> | |
| )} | |
| </div> | |
| )} | |
| {activeTab === 'data' && ( | |
| <div className={`h-[600px] p-6 rounded-lg ${darkMode ? 'bg-gray-800/50' : 'bg-white/50'} glassmorphic`}> | |
| <div className="grid grid-cols-3 gap-4 h-full"> | |
| <div className="col-span-1 flex flex-col gap-4"> | |
| <div | |
| className={`p-4 rounded-lg dropzone ${darkMode ? 'bg-gray-700/50' : 'bg-gray-100/50'} neumorphic`} | |
| onDragOver={handleDragOver} | |
| onDragLeave={handleDragLeave} | |
| onDrop={handleDrop} | |
| > | |
| <input | |
| type="file" | |
| onChange={handleFileUpload} | |
| accept=".csv,.xlsx,.xls" | |
| className="hidden" | |
| id="file-upload" | |
| /> | |
| <label htmlFor="file-upload" className="cursor-pointer flex flex-col items-center"> | |
| <img src="https://img.icons8.com/ios-filled/50/upload.png" alt="Upload" className={`w-8 h-8 ${darkMode ? 'filter invert' : ''}`} /> | |
| <p className="text-sm">Drag & drop or click to upload CSV/XLSX</p> | |
| </label> | |
| </div> | |
| <div className="overflow-y-auto max-h-[500px]"> | |
| {files.map((file, index) => ( | |
| <div | |
| key={index} | |
| onClick={() => handleFileSelect(file)} | |
| className={`p-2 rounded-lg cursor-pointer transition-all duration-200 ${selectedFile?.name === file.name ? 'bg-indigo-600 text-white' : darkMode ? 'bg-gray-600/50 text-gray-200' : 'bg-gray-200/50 text-gray-700'} neumorphic mb-2`} | |
| > | |
| {file.name} | |
| </div> | |
| ))} | |
| </div> | |
| </div> | |
| <div className="col-span-2"> | |
| {selectedFile ? ( | |
| <div className="h-[550px] overflow-auto p-4 rounded-lg neumorphic" id="data-preview"> | |
| <pre className="text-sm">{selectedFile.data}</pre> | |
| </div> | |
| ) : ( | |
| <div className="flex items-center justify-center h-full"> | |
| <p className="text-gray-500">Select a file to preview</p> | |
| </div> | |
| )} | |
| </div> | |
| </div> | |
| </div> | |
| )} | |
| {activeTab === 'drawing' && ( | |
| <div className={`h-[600px] p-6 rounded-lg ${darkMode ? 'bg-gray-800/50' : 'bg-white/50'} glassmorphic`}> | |
| <div className="flex justify-between items-center mb-4"> | |
| <div className="flex gap-4"> | |
| <input | |
| type="range" | |
| min="1" | |
| max="50" | |
| value={brushSize} | |
| onChange={(e) => setBrushSize(e.target.value)} | |
| className="w-32" | |
| /> | |
| <input | |
| type="color" | |
| value={brushColor} | |
| onChange={(e) => setBrushColor(e.target.value)} | |
| /> | |
| </div> | |
| <button | |
| onClick={clearCanvas} | |
| className="px-4 py-2 bg-red-600 text-white rounded-lg hover:bg-red-700 transition-all duration-200 neumorphic" | |
| > | |
| Clear Canvas | |
| </button> | |
| </div> | |
| <canvas | |
| ref={canvasRef} | |
| id="canvas" | |
| className="border rounded-lg bg-white w-full h-[500px]" | |
| onMouseDown={handleCanvasMouseDown} | |
| onMouseMove={handleCanvasMouseMove} | |
| onMouseUp={handleCanvasMouseUp} | |
| onMouseLeave={handleCanvasMouseUp} | |
| ></canvas> | |
| </div> | |
| )} | |
| {activeTab === 'calculator' && ( | |
| <div className={`h-[600px] p-6 rounded-lg ${darkMode ? 'bg-gray-800/50' : 'bg-white/50'} glassmorphic`}> | |
| <div className="max-w-md mx-auto"> | |
| <input | |
| value={calcInput} | |
| onChange={(e) => setCalcInput(e.target.value)} | |
| onKeyPress={handleCalcKeyPress} | |
| placeholder="Enter expression (e.g., 2 + 2)" | |
| className={`w-full p-3 mb-4 border-none rounded-lg focus:outline-none focus:ring-2 focus:ring-indigo-500 ${darkMode ? 'bg-gray-600/50 text-gray-200 placeholder-gray-400' : 'bg-gray-100/50 text-gray-900 placeholder-gray-500'} neumorphic`} | |
| /> | |
| <button | |
| onClick={calculate} | |
| className="w-full p-3 bg-indigo-600 text-white rounded-lg hover:bg-indigo-700 transition-all duration-200 neumorphic" | |
| > | |
| Calculate | |
| </button> | |
| {calcResult && ( | |
| <div className={`mt-4 p-4 rounded-lg ${darkMode ? 'bg-gray-700/50' : 'bg-gray-100/50'} neumorphic`}> | |
| <p className="text-lg font-semibold">Result: {calcResult}</p> | |
| </div> | |
| )} | |
| </div> | |
| </div> | |
| )} | |
| </div> | |
| <div className={`p-4 border-t ${darkMode ? 'bg-gray-700/50' : 'bg-gray-50/50'} glassmorphic`}> | |
| <div className="flex flex-wrap gap-2 mb-4"> | |
| {suggestions.map((sug, index) => ( | |
| <button | |
| key={index} | |
| onClick={() => sendMessage(sug.prompt)} | |
| className={`px-4 py-2 rounded-full text-sm transition-all duration-200 transform hover:scale-105 neumorphic ${darkMode ? 'bg-gray-600/50 text-gray-200 hover:bg-indigo-900/50' : 'bg-gray-100/50 text-gray-700 hover:bg-indigo-100/50'}`} | |
| > | |
| {sug.text} | |
| </button> | |
| ))} | |
| </div> | |
| <div className="flex items-center gap-3"> | |
| <textarea | |
| value={input} | |
| onChange={(e) => setInput(e.target.value)} | |
| onKeyPress={handleKeyPress} | |
| placeholder="Type your message..." | |
| className={`flex-1 p-3 border-none rounded-lg focus:outline-none focus:ring-2 focus:ring-indigo-500 resize-none h-12 transition-colors duration-300 ${darkMode ? 'bg-gray-600/50 text-gray-200 placeholder-gray-400' : 'bg-gray-100/50 text-gray-900 placeholder-gray-500'} neumorphic`} | |
| /> | |
| <button | |
| onClick={isRecording ? stopRecording : startRecording} | |
| className={`p-3 rounded-lg transition-all duration-200 transform hover:scale-105 neumorphic ${isRecording ? 'bg-red-600 pulse' : 'bg-indigo-600'}`} | |
| > | |
| <img src="https://img.icons8.com/ios-filled/50/microphone.png" alt="Record" className="w-6 h-6 filter invert" /> | |
| </button> | |
| <button | |
| onClick={() => sendMessage()} | |
| className="p-3 bg-indigo-600 text-white rounded-lg hover:bg-indigo-700 transition-all duration-200 transform hover:scale-105 neumorphic" | |
| > | |
| <img src="https://img.icons8.com/ios-filled/50/send.png" alt="Send" className="w-6 h-6 filter invert" /> | |
| </button> | |
| </div> | |
| </div> | |
| </div> | |
| ); | |
| }; | |
| ReactDOM.render(<ChatApp />, document.getElementById('root')); | |
| </script> | |
| </body> | |
| </html> |