Spaces:
Running
Running
Download index.html from greatisiw92/m: direct link, hf CLI and curl.
- Browser
- Download file 36.6 kB
-
https://huggingface.co/spaces/greatisiw92/m/resolve/main/index.html
- Command line
-
hf download hf://spaces/greatisiw92/m/index.html
-
curl -L -o index.html https://huggingface.co/spaces/greatisiw92/m/resolve/main/index.html
36.6 kB
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>Bitcoin Tracker with AI Assistant</title> | |
| <script src="https://cdn.tailwindcss.com"></script> | |
| <script src="https://cdn.jsdelivr.net/npm/chart.js"></script> | |
| <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css"> | |
| <style> | |
| @keyframes pulse { | |
| 0%, 100% { opacity: 1; } | |
| 50% { opacity: 0.5; } | |
| } | |
| .animate-pulse { | |
| animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite; | |
| } | |
| .gradient-bg { | |
| background: linear-gradient(135deg, #1e3a8a 0%, #1e40af 50%, #1d4ed8 100%); | |
| } | |
| .price-change-up { | |
| color: #10b981; | |
| } | |
| .price-change-down { | |
| color: #ef4444; | |
| } | |
| .blink { | |
| animation: blink 1s step-end infinite; | |
| } | |
| @keyframes blink { | |
| 50% { opacity: 0; } | |
| } | |
| .chat-container { | |
| position: fixed; | |
| bottom: 20px; | |
| right: 20px; | |
| width: 350px; | |
| z-index: 1000; | |
| transition: transform 0.3s ease; | |
| } | |
| .chat-collapsed { | |
| transform: translateY(calc(100% - 50px)); | |
| } | |
| .messages-container { | |
| height: 300px; | |
| overflow-y: auto; | |
| scrollbar-width: thin; | |
| scrollbar-color: #3b82f6 #1e293b; | |
| } | |
| .messages-container::-webkit-scrollbar { | |
| width: 6px; | |
| } | |
| .messages-container::-webkit-scrollbar-track { | |
| background: #1e293b; | |
| } | |
| .messages-container::-webkit-scrollbar-thumb { | |
| background-color: #3b82f6; | |
| border-radius: 6px; | |
| } | |
| .typing-indicator { | |
| display: inline-flex; | |
| gap: 3px; | |
| } | |
| .typing-dot { | |
| width: 6px; | |
| height: 6px; | |
| background-color: #94a3b8; | |
| border-radius: 50%; | |
| animation: typing 1.4s infinite ease-in-out; | |
| } | |
| .typing-dot:nth-child(1) { | |
| animation-delay: 0s; | |
| } | |
| .typing-dot:nth-child(2) { | |
| animation-delay: 0.2s; | |
| } | |
| .typing-dot:nth-child(3) { | |
| animation-delay: 0.4s; | |
| } | |
| @keyframes typing { | |
| 0%, 60%, 100% { transform: translateY(0); } | |
| 30% { transform: translateY(-5px); } | |
| } | |
| </style> | |
| </head> | |
| <body class="bg-gray-900 text-white min-h-screen"> | |
| <div class="gradient-bg fixed top-0 left-0 w-full h-1/2 -z-10"></div> | |
| <div class="container mx-auto px-4 py-8"> | |
| <header class="flex justify-between items-center mb-8"> | |
| <div> | |
| <h1 class="text-3xl font-bold flex items-center"> | |
| <i class="fab fa-bitcoin text-yellow-500 mr-3"></i> | |
| <span>Bitcoin Tracker</span> | |
| </h1> | |
| <p class="text-gray-300">Real-time Bitcoin price and market data with AI Assistant</p> | |
| </div> | |
| <div class="flex items-center space-x-4"> | |
| <div class="bg-gray-800 px-4 py-2 rounded-lg flex items-center"> | |
| <i class="fas fa-sync-alt mr-2"></i> | |
| <span id="last-updated" class="text-sm">Loading...</span> | |
| </div> | |
| <div id="api-status" class="bg-gray-800 px-3 py-1 rounded-lg text-sm flex items-center"> | |
| <span class="w-2 h-2 rounded-full mr-2 bg-yellow-500 animate-pulse"></span> | |
| <span>Connecting...</span> | |
| </div> | |
| </div> | |
| </header> | |
| <div class="grid grid-cols-1 md:grid-cols-3 gap-6 mb-8"> | |
| <!-- Price Card --> | |
| <div class="bg-gray-800 p-6 rounded-xl border border-gray-700"> | |
| <div class="flex justify-between items-start mb-4"> | |
| <div> | |
| <h3 class="text-lg font-semibold text-gray-300">Bitcoin (BTC/USD)</h3> | |
| <div class="flex items-center mt-1"> | |
| <i class="fab fa-bitcoin text-yellow-500 text-2xl mr-2"></i> | |
| <span class="text-xl font-bold">$<span id="current-price">--.--</span></span> | |
| </div> | |
| </div> | |
| <div class="flex items-center"> | |
| <span id="price-change" class="px-2 py-1 rounded-md">0.00%</span> | |
| </div> | |
| </div> | |
| <div class="flex justify-between items-center mt-2"> | |
| <div class="text-center"> | |
| <p class="text-sm text-gray-400">24h High</p> | |
| <p class="font-medium" id="high-24h">--.--</p> | |
| </div> | |
| <div class="text-center"> | |
| <p class="text-sm text-gray-400">24h Low</p> | |
| <p class="font-medium" id="low-24h">--.--</p> | |
| </div> | |
| <div class="text-center"> | |
| <p class="text-sm text-gray-400">24h Volume</p> | |
| <p class="font-medium" id="vol-24h">--.--</p> | |
| </div> | |
| </div> | |
| </div> | |
| <!-- Market Stats --> | |
| <div class="bg-gray-800 p-6 rounded-xl border border-gray-700"> | |
| <h3 class="text-lg font-semibold text-gray-300 mb-4">Market Data</h3> | |
| <div class="space-y-4"> | |
| <div class="flex justify-between"> | |
| <span class="text-gray-400">Market Cap</span> | |
| <span id="market-cap">--.--</span> | |
| </div> | |
| <div class="flex justify-between"> | |
| <span class="text-gray-400">Circulating Supply</span> | |
| <span id="circulating-supply">--.--</span> | |
| </div> | |
| <div class="flex justify-between"> | |
| <span class="text-gray-400">Total Supply</span> | |
| <span id="total-supply">--.--</span> | |
| </div> | |
| <div class="flex justify-between"> | |
| <span class="text-gray-400">ATH</span> | |
| <span id="ath">--.--</span> | |
| </div> | |
| </div> | |
| </div> | |
| <!-- Dominance & Rank --> | |
| <div class="bg-gray-800 p-6 rounded-xl border border-gray-700"> | |
| <h3 class="text-lg font-semibold text-gray-300 mb-4">Market Position</h3> | |
| <div class="space-y-4"> | |
| <div class="flex justify-between"> | |
| <span class="text-gray-400">Market Cap Rank</span> | |
| <span id="market-cap-rank">--</span> | |
| </div> | |
| <div class="flex justify-between"> | |
| <span class="text-gray-400">Market Cap Dominance</span> | |
| <span id="market-cap-dominance">--.--%</span> | |
| </div> | |
| <div class="flex justify-between"> | |
| <span class="text-gray-400">Price Change (1h)</span> | |
| <span id="price-change-1h">--.--%</span> | |
| </div> | |
| <div class="flex justify-between"> | |
| <span class="text-gray-400">Price Change (24h)</span> | |
| <span id="price-change-24h">--.--%</span> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <!-- Chart Section --> | |
| <div class="bg-gray-800 p-6 rounded-xl border border-gray-700 mb-8"> | |
| <div class="flex justify-between items-center mb-4"> | |
| <h3 class="text-lg font-semibold">Price History (Last 7 Days)</h3> | |
| <div class="flex space-x-2"> | |
| <button class="time-btn active bg-gray-700 px-3 py-1 rounded-md text-sm" data-range="1">24h</button> | |
| <button class="time-btn bg-gray-700 px-3 py-1 rounded-md text-sm" data-range="7">7d</button> | |
| <button class="time-btn bg-gray-700 px-3 py-1 rounded-md text-sm" data-range="30">30d</button> | |
| <button class="time-btn bg-gray-700 px-3 py-1 rounded-md text-sm" data-range="90">90d</button> | |
| </div> | |
| </div> | |
| <div class="h-80"> | |
| <canvas id="price-chart"></canvas> | |
| </div> | |
| </div> | |
| <!-- Additional Data --> | |
| <div class="grid grid-cols-1 md:grid-cols-2 gap-6 mb-8"> | |
| <!-- Price Changes --> | |
| <div class="bg-gray-800 p-6 rounded-xl border border-gray-700"> | |
| <h3 class="text-lg font-semibold text-gray-300 mb-4">Price Changes</h3> | |
| <div class="grid grid-cols-2 gap-4"> | |
| <div class="bg-gray-900 p-3 rounded-lg"> | |
| <p class="text-sm text-gray-400">Last 1 hour</p> | |
| <p id="change-1h" class="text-xl"></p> | |
| </div> | |
| <div class="bg-gray-900 p-3 rounded-lg"> | |
| <p class="text-sm text-gray-400">Last 24 hours</p> | |
| <p id="change-24h" class="text-xl"></p> | |
| </div> | |
| <div class="bg-gray-900 p-3 rounded-lg"> | |
| <p class="text-sm text-gray-400">Last 7 days</p> | |
| <p id="change-7d" class="text-xl"></p> | |
| </div> | |
| <div class="bg-gray-900 p-3 rounded-lg"> | |
| <p class="text-sm text-gray-400">Last 30 days</p> | |
| <p id="change-30d" class="text-xl"></p> | |
| </div> | |
| </div> | |
| </div> | |
| <!-- Developer Data --> | |
| <div class="bg-gray-800 p-6 rounded-xl border border-gray-700"> | |
| <h3 class="text-lg font-semibold text-gray-300 mb-4">Developer Data</h3> | |
| <div class="space-y-4"> | |
| <div class="flex justify-between"> | |
| <span class="text-gray-400">GitHub Stars</span> | |
| <span id="github-stars">--</span> | |
| </div> | |
| <div class="flex justify-between"> | |
| <span class="text-gray-400">GitHub Forks</span> | |
| <span id="github-forks">--</span> | |
| </div> | |
| <div class="flex justify-between"> | |
| <span class="text-gray-400">GitHub Subscribers</span> | |
| <span id="github-subscribers">--</span> | |
| </div> | |
| <div class="flex justify-between"> | |
| <span class="text-gray-400">Last Updated</span> | |
| <span id="last-updated-api">--</span> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <footer class="mt-12 text-center text-gray-400 text-sm"> | |
| <p>© 2023 Bitcoin Tracker. Data provided by CoinGecko API.</p> | |
| <p class="mt-1">API Status: <span id="api-status-text" class="font-medium text-yellow-400">Loading...</span></p> | |
| </footer> | |
| </div> | |
| <!-- AI Chat Container --> | |
| <div class="chat-container"> | |
| <div class="bg-gray-800 rounded-t-xl shadow-xl border border-gray-700 overflow-hidden"> | |
| <div class="bg-gray-900 px-4 py-3 flex justify-between items-center cursor-pointer" id="chat-header"> | |
| <div class="flex items-center"> | |
| <i class="fas fa-robot text-blue-400 mr-2"></i> | |
| <h3 class="font-semibold">Bitcoin AI Assistant</h3> | |
| </div> | |
| <button id="chat-toggle"> | |
| <i class="fas fa-chevron-down text-gray-400"></i> | |
| </button> | |
| </div> | |
| <div class="messages-container p-4 bg-gray-800" id="messages"> | |
| <div class="mb-4"> | |
| <div class="bg-blue-900/40 rounded-lg p-3 max-w-[80%] inline-block"> | |
| <p class="text-sm">Hello! I'm your Bitcoin assistant. Ask me anything about cryptocurrency markets, technical analysis, or Bitcoin fundamentals.</p> | |
| </div> | |
| </div> | |
| </div> | |
| <div class="bg-gray-900 px-4 py-3 border-t border-gray-700"> | |
| <div class="flex space-x-2"> | |
| <input type="text" id="user-input" class="flex-1 bg-gray-800 border border-gray-700 rounded-lg px-4 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent" placeholder="Ask about Bitcoin..." autocomplete="off"> | |
| <button id="send-btn" class="bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded-lg transition"> | |
| <i class="fas fa-paper-plane"></i> | |
| </button> | |
| </div> | |
| <p class="text-xs text-gray-500 mt-2">This AI uses Gemini to analyze crypto data</p> | |
| </div> | |
| </div> | |
| </div> | |
| <!-- Loading indicator template --> | |
| <template id="loading-indicator"> | |
| <div class="mb-4 clear-both"> | |
| <div class="bg-gray-700 rounded-lg p-3 max-w-[80%] inline-block"> | |
| <div class="typing-indicator"> | |
| <div class="typing-dot"></div> | |
| <div class="typing-dot"></div> | |
| <div class="typing-dot"></div> | |
| </div> | |
| </div> | |
| </div> | |
| </template> | |
| <script> | |
| document.addEventListener('DOMContentLoaded', function() { | |
| // Gemini API Key | |
| const GEMINI_API_KEY = 'AIzaSyBBf3joWs5xiqswrBaI8zIGjv337CIzGmA'; | |
| // Elements | |
| const currentPriceEl = document.getElementById('current-price'); | |
| const priceChangeEl = document.getElementById('price-change'); | |
| const high24hEl = document.getElementById('high-24h'); | |
| const low24hEl = document.getElementById('low-24h'); | |
| const vol24hEl = document.getElementById('vol-24h'); | |
| const lastUpdatedEl = document.getElementById('last-updated'); | |
| const apiStatusEl = document.getElementById('api-status'); | |
| const apiStatusText = document.getElementById('api-status-text'); | |
| const timeBtns = document.querySelectorAll('.time-btn'); | |
| // Market data elements | |
| const marketCapEl = document.getElementById('market-cap'); | |
| const circulatingSupplyEl = document.getElementById('circulating-supply'); | |
| const totalSupplyEl = document.getElementById('total-supply'); | |
| const athEl = document.getElementById('ath'); | |
| const marketCapRankEl = document.getElementById('market-cap-rank'); | |
| const marketCapDominanceEl = document.getElementById('market-cap-dominance'); | |
| const priceChange1hEl = document.getElementById('price-change-1h'); | |
| const priceChange24hEl = document.getElementById('price-change-24h'); | |
| // Price changes | |
| const change1hEl = document.getElementById('change-1h'); | |
| const change24hEl = document.getElementById('change-24h'); | |
| const change7dEl = document.getElementById('change-7d'); | |
| const change30dEl = document.getElementById('change-30d'); | |
| // Developer data | |
| const githubStarsEl = document.getElementById('github-stars'); | |
| const githubForksEl = document.getElementById('github-forks'); | |
| const githubSubscribersEl = document.getElementById('github-subscribers'); | |
| const lastUpdatedApiEl = document.getElementById('last-updated-api'); | |
| // Chart setup | |
| const ctx = document.getElementById('price-chart').getContext('2d'); | |
| let priceChart = new Chart(ctx, { | |
| type: 'line', | |
| data: { | |
| labels: [], | |
| datasets: [{ | |
| label: 'BTC/USD', | |
| data: [], | |
| borderColor: '#3b82f6', | |
| backgroundColor: 'rgba(59, 130, 246, 0.1)', | |
| borderWidth: 2, | |
| fill: true, | |
| tension: 0.4, | |
| pointRadius: 0 | |
| }] | |
| }, | |
| options: { | |
| responsive: true, | |
| maintainAspectRatio: false, | |
| scales: { | |
| x: { | |
| grid: { | |
| display: false, | |
| color: 'rgba(255, 255, 255, 0.1)' | |
| }, | |
| ticks: { | |
| color: 'rgba(255, 255, 255, 0.7)' | |
| } | |
| }, | |
| y: { | |
| grid: { | |
| color: 'rgba(255, 255, 255, 0.1)' | |
| }, | |
| ticks: { | |
| color: 'rgba(255, 255, 255, 0.7)' | |
| } | |
| } | |
| }, | |
| plugins: { | |
| legend: { | |
| display: false | |
| }, | |
| tooltip: { | |
| mode: 'index', | |
| intersect: false, | |
| backgroundColor: 'rgba(17, 24, 39, 0.9)', | |
| titleColor: 'rgba(255, 255, 255, 0.9)', | |
| bodyColor: 'rgba(255, 255, 255, 0.7)', | |
| borderColor: 'rgba(255, 255, 255, 0.1)', | |
| borderWidth: 1 | |
| } | |
| }, | |
| interaction: { | |
| mode: 'nearest', | |
| axis: 'x', | |
| intersect: false | |
| } | |
| } | |
| }); | |
| // Chat elements | |
| const chatContainer = document.querySelector('.chat-container'); | |
| const chatHeader = document.getElementById('chat-header'); | |
| const chatToggle = document.getElementById('chat-toggle'); | |
| const messagesContainer = document.getElementById('messages'); | |
| const userInput = document.getElementById('user-input'); | |
| const sendBtn = document.getElementById('send-btn'); | |
| const loadingTemplate = document.getElementById('loading-indicator'); | |
| let isChatOpen = true; | |
| let currentBitcoinData = {}; | |
| // Format numbers | |
| function formatNumber(num) { | |
| if (num >= 1000000000) { | |
| return (num / 1000000000).toFixed(2) + 'B'; | |
| } | |
| if (num >= 1000000) { | |
| return (num / 1000000).toFixed(2) + 'M'; | |
| } | |
| if (num >= 1000) { | |
| return (num / 1000).toFixed(2) + 'K'; | |
| } | |
| return num.toFixed(2); | |
| } | |
| function formatCurrency(num) { | |
| return '$' + num.toLocaleString('en-US', {minimumFractionDigits: 2, maximumFractionDigits: 2}); | |
| } | |
| function formatBTC(num) { | |
| return num.toLocaleString('en-US', {maximumFractionDigits: 8}); | |
| } | |
| // Update price change color | |
| function updateChangeColor(element, change) { | |
| element.classList.remove('price-change-up', 'price-change-down'); | |
| if (change > 0) { | |
| element.classList.add('price-change-up'); | |
| } else if (change < 0) { | |
| element.classList.add('price-change-down'); | |
| } | |
| } | |
| // Update API status | |
| function updateApiStatus(status) { | |
| const statusEl = apiStatusEl.firstElementChild; | |
| if (status === 'connected') { | |
| statusEl.classList.remove('bg-yellow-500', 'animate-pulse'); | |
| statusEl.classList.add('bg-green-500'); | |
| apiStatusText.textContent = 'Connected'; | |
| apiStatusText.className = 'font-medium text-green-400'; | |
| } else if (status === 'error') { | |
| statusEl.classList.remove('bg-yellow-500', 'animate-pulse'); | |
| statusEl.classList.add('bg-red-500'); | |
| apiStatusText.textContent = 'Connection Error'; | |
| apiStatusText.className = 'font-medium text-red-400 blink'; | |
| } else { | |
| statusEl.classList.add('bg-yellow-500', 'animate-pulse'); | |
| statusEl.classList.remove('bg-green-500', 'bg-red-500'); | |
| apiStatusText.textContent = 'Loading...'; | |
| apiStatusText.className = 'font-medium text-yellow-400'; | |
| } | |
| } | |
| // Fetch data from CoinGecko API | |
| async function fetchBitcoinData() { | |
| try { | |
| updateApiStatus('loading'); | |
| // Fetch current Bitcoin data | |
| const response = await fetch('https://api.coingecko.com/api/v3/coins/bitcoin?localization=false&tickers=false&market_data=true&community_data=true&developer_data=true&sparkline=false'); | |
| if (!response.ok) { | |
| throw new Error('API request failed'); | |
| } | |
| const data = await response.json(); | |
| currentBitcoinData = data; | |
| // Update UI with real data | |
| const price = data.market_data.current_price.usd; | |
| const priceChange24h = data.market_data.price_change_percentage_24h; | |
| currentPriceEl.textContent = price.toLocaleString('en-US', {minimumFractionDigits: 2, maximumFractionDigits: 2}); | |
| high24hEl.textContent = formatCurrency(data.market_data.high_24h.usd); | |
| low24hEl.textContent = formatCurrency(data.market_data.low_24h.usd); | |
| vol24hEl.textContent = formatCurrency(data.market_data.total_volume.usd); | |
| priceChangeEl.textContent = priceChange24h.toFixed(2) + '%'; | |
| updateChangeColor(priceChangeEl, priceChange24h); | |
| // Update market data | |
| marketCapEl.textContent = formatCurrency(data.market_data.market_cap.usd); | |
| circulatingSupplyEl.textContent = formatBTC(data.market_data.circulating_supply); | |
| totalSupplyEl.textContent = formatBTC(data.market_data.total_supply || data.market_data.circulating_supply); | |
| athEl.textContent = formatCurrency(data.market_data.ath.usd); | |
| marketCapRankEl.textContent = data.market_cap_rank; | |
| marketCapDominanceEl.textContent = data.market_data.market_cap_percentage.btc.toFixed(2) + '%'; | |
| // Update price changes | |
| priceChange1hEl.textContent = data.market_data.price_change_percentage_1h_in_currency.usd.toFixed(2) + '%'; | |
| updateChangeColor(priceChange1hEl, data.market_data.price_change_percentage_1h_in_currency.usd); | |
| priceChange24hEl.textContent = data.market_data.price_change_percentage_24h_in_currency.usd.toFixed(2) + '%'; | |
| updateChangeColor(priceChange24hEl, data.market_data.price_change_percentage_24h_in_currency.usd); | |
| // Update price change cards | |
| change1hEl.textContent = data.market_data.price_change_percentage_1h_in_currency.usd.toFixed(2) + '%'; | |
| updateChangeColor(change1hEl, data.market_data.price_change_percentage_1h_in_currency.usd); | |
| change24hEl.textContent = data.market_data.price_change_percentage_24h_in_currency.usd.toFixed(2) + '%'; | |
| updateChangeColor(change24hEl, data.market_data.price_change_percentage_24h_in_currency.usd); | |
| change7dEl.textContent = data.market_data.price_change_percentage_7d_in_currency.usd.toFixed(2) + '%'; | |
| updateChangeColor(change7dEl, data.market_data.price_change_percentage_7d_in_currency.usd); | |
| change30dEl.textContent = data.market_data.price_change_percentage_30d_in_currency.usd.toFixed(2) + '%'; | |
| updateChangeColor(change30dEl, data.market_data.price_change_percentage_30d_in_currency.usd); | |
| // Update developer data | |
| githubStarsEl.textContent = formatNumber(data.developer_data.stars); | |
| githubForksEl.textContent = formatNumber(data.developer_data.forks); | |
| githubSubscribersEl.textContent = formatNumber(data.developer_data.subscribers); | |
| lastUpdatedApiEl.textContent = new Date(data.last_updated).toLocaleString(); | |
| // Update last updated time | |
| lastUpdatedEl.textContent = new Date().toLocaleTimeString(); | |
| updateApiStatus('connected'); | |
| // Fetch historical data for chart | |
| await fetchHistoricalData(7); | |
| } catch (error) { | |
| console.error('Error fetching Bitcoin data:', error); | |
| updateApiStatus('error'); | |
| lastUpdatedEl.textContent = 'Error loading data'; | |
| // Retry after 10 seconds | |
| setTimeout(fetchBitcoinData, 10000); | |
| } | |
| } | |
| // Fetch historical data for chart | |
| async function fetchHistoricalData(days) { | |
| try { | |
| const response = await fetch(`https://api.coingecko.com/api/v3/coins/bitcoin/market_chart?vs_currency=usd&days=${days}`); | |
| if (!response.ok) { | |
| throw new Error('Historical data request failed'); | |
| } | |
| const data = await response.json(); | |
| // Process data for Chart.js | |
| const prices = data.prices; | |
| const labels = []; | |
| const chartData = []; | |
| // Create appropriate labels based on time range | |
| prices.forEach(([timestamp, price]) => { | |
| const date = new Date(timestamp); | |
| if (days === 1) { | |
| // For 24h chart, show hours:minutes | |
| labels.push(date.toLocaleTimeString([], {hour: '2-digit', minute:'2-digit'})); | |
| } else { | |
| // For multi-day charts, show short date | |
| labels.push(date.toLocaleDateString([], {month: 'short', day: 'numeric'})); | |
| } | |
| chartData.push(price); | |
| }); | |
| // Update chart | |
| priceChart.data.labels = labels; | |
| priceChart.data.datasets[0].data = chartData; | |
| priceChart.update(); | |
| } catch (error) { | |
| console.error('Error fetching historical data:', error); | |
| } | |
| } | |
| // Time interval buttons | |
| timeBtns.forEach(btn => { | |
| btn.addEventListener('click', function() { | |
| timeBtns.forEach(b => b.classList.remove('active')); | |
| this.classList.add('active'); | |
| const days = parseInt(this.dataset.range); | |
| fetchHistoricalData(days); | |
| }); | |
| }); | |
| // Chat functionality | |
| function toggleChat() { | |
| isChatOpen = !isChatOpen; | |
| chatContainer.classList.toggle('chat-collapsed'); | |
| if (isChatOpen) { | |
| chatToggle.innerHTML = '<i class="fas fa-chevron-down text-gray-400"></i>'; | |
| setTimeout(() => { | |
| messagesContainer.scrollTop = messagesContainer.scrollHeight; | |
| }, 100); | |
| } else { | |
| chatToggle.innerHTML = '<i class="fas fa-chevron-up text-gray-400"></i>'; | |
| } | |
| } | |
| function addMessage(role, content) { | |
| const messageDiv = document.createElement('div'); | |
| messageDiv.className = `mb-4 clear-both ${role === 'user' ? 'text-right' : ''}`; | |
| const bubble = document.createElement('div'); | |
| bubble.className = `rounded-lg p-3 max-w-[80%] inline-block ${ | |
| role === 'user' | |
| ? 'bg-blue-600 text-white float-right' | |
| : 'bg-blue-900/40' | |
| }`; | |
| bubble.innerHTML = `<p class="text-sm">${content}</p>`; | |
| messageDiv.appendChild(bubble); | |
| messagesContainer.appendChild(messageDiv); | |
| // Scroll to the new message | |
| messagesContainer.scrollTop = messagesContainer.scrollHeight; | |
| return bubble; | |
| } | |
| function showLoading() { | |
| const loadingClone = loadingTemplate.content.cloneNode(true); | |
| const loadingDiv = loadingClone.querySelector('div'); | |
| messagesContainer.appendChild(loadingDiv); | |
| messagesContainer.scrollTop = messagesContainer.scrollHeight; | |
| return loadingDiv; | |
| } | |
| function removeLoading(loadingDiv) { | |
| if (loadingDiv && loadingDiv.parentNode) { | |
| loadingDiv.parentNode.removeChild(loadingDiv); | |
| } | |
| } | |
| async function sendMessageToAI(message) { | |
| const loadingDiv = showLoading(); | |
| const timestamp = new Date().toLocaleTimeString(); | |
| try { | |
| // Prepare the context with current Bitcoin data | |
| const currentPrice = currentBitcoinData.market_data.current_price.usd; | |
| const priceChange24h = currentBitcoinData.market_data.price_change_percentage_24h; | |
| const marketCap = currentBitcoinData.market_data.market_cap.usd; | |
| const context = `You are a Bitcoin and cryptocurrency expert assistant. The current Bitcoin data is: | |
| - Price: $${currentPrice.toLocaleString('en-US', {minimumFractionDigits: 2, maximumFractionDigits: 2})} | |
| - 24h Change: ${priceChange24h.toFixed(2)}% | |
| - Market Cap: $${formatNumber(marketCap)} | |
| - Current Time: ${timestamp} | |
| When asked about price predictions, give thoughtful analysis but emphasize that crypto markets are volatile.`; | |
| const requestBody = { | |
| contents: [{ | |
| parts: [{ | |
| text: `${context}\n\nUser Question: ${message}` | |
| }] | |
| }], | |
| safetySettings: [ | |
| { | |
| category: "HARM_CATEGORY_HARASSMENT", | |
| threshold: "BLOCK_NONE" | |
| }, | |
| { | |
| category: "HARM_CATEGORY_HATE_SPEECH", | |
| threshold: "BLOCK_NONE" | |
| }, | |
| { | |
| category: "HARM_CATEGORY_SEXUALLY_EXPLICIT", | |
| threshold: "BLOCK_NONE" | |
| }, | |
| { | |
| category: "HARM_CATEGORY_DANGEROUS_CONTENT", | |
| threshold: "BLOCK_NONE" | |
| } | |
| ], | |
| generationConfig: { | |
| temperature: 0.7, | |
| topP: 0.8, | |
| topK: 40 | |
| } | |
| }; | |
| const response = await fetch(`https://generativelanguage.googleapis.com/v1beta/models/gemini-pro:generateContent?key=${GEMINI_API_KEY}`, { | |
| method: 'POST', | |
| headers: { | |
| 'Content-Type': 'application/json' | |
| }, | |
| body: JSON.stringify(requestBody) | |
| }); | |
| if (!response.ok) { | |
| throw new Error('AI request failed'); | |
| } | |
| const data = await response.json(); | |
| const aiResponse = data.candidates[0].content.parts[0].text; | |
| removeLoading(loadingDiv); | |
| return aiResponse; | |
| } catch (error) { | |
| console.error('Error calling Gemini API:', error); | |
| removeLoading(loadingDiv); | |
| return "I'm sorry, I couldn't process your request. Please try again later."; | |
| } | |
| } | |
| async function handleUserMessage() { | |
| const message = userInput.value.trim(); | |
| if (!message) return; | |
| // Add user message | |
| addMessage('user', message); | |
| userInput.value = ''; | |
| // Get AI response | |
| const aiResponse = await sendMessageToAI(message); | |
| // Add AI response | |
| const responseBubble = addMessage('assistant', aiResponse); | |
| // Highlight numbers and percentages in the response | |
| const text = responseBubble.querySelector('p'); | |
| text.innerHTML = text.innerHTML.replace( | |
| /(\$?\d{1,3}(,\d{3})*(\.\d+)?%?)/g, | |
| '<span class="text-blue-300">$1</span>' | |
| ); | |
| } | |
| // Chat event listeners | |
| chatHeader.addEventListener('click', toggleChat); | |
| userInput.addEventListener('keypress', (e) => { | |
| if (e.key === 'Enter') { | |
| handleUserMessage(); | |
| } | |
| }); | |
| sendBtn.addEventListener('click', handleUserMessage); | |
| // Initial fetch | |
| fetchBitcoinData(); | |
| // Refresh data every 60 seconds | |
| setInterval(fetchBitcoinData, 60000); | |
| }); | |
| </script> | |
| <p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=greatisiw92/m" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body> | |
| </html> |