Spaces:
Running
Running
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Cloudflare LLaMA 2 Chat</title> | |
<script src="https://cdn.tailwindcss.com"></script> | |
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css"> | |
<style> | |
.chat-container { | |
height: calc(100vh - 180px); | |
} | |
.message-animation { | |
animation: fadeIn 0.3s ease-in-out; | |
} | |
@keyframes fadeIn { | |
from { opacity: 0; transform: translateY(10px); } | |
to { opacity: 1; transform: translateY(0); } | |
} | |
.typing-indicator span { | |
animation: bounce 1.5s infinite ease-in-out; | |
display: inline-block; | |
} | |
.typing-indicator span:nth-child(2) { | |
animation-delay: 0.2s; | |
} | |
.typing-indicator span:nth-child(3) { | |
animation-delay: 0.4s; | |
} | |
@keyframes bounce { | |
0%, 100% { transform: translateY(0); } | |
50% { transform: translateY(-5px); } | |
} | |
.model-selector:hover .model-dropdown { | |
display: block; | |
} | |
</style> | |
</head> | |
<body class="bg-gray-100"> | |
<div class="container mx-auto max-w-4xl px-4 py-8"> | |
<!-- Header --> | |
<header class="flex items-center justify-between mb-8"> | |
<div class="flex items-center"> | |
<div class="w-10 h-10 bg-blue-500 rounded-lg flex items-center justify-center mr-3"> | |
<i class="fas fa-cloud text-white text-xl"></i> | |
</div> | |
<h1 class="text-2xl font-bold text-gray-800">Cloudflare AI</h1> | |
</div> | |
<div class="relative model-selector"> | |
<button class="bg-white px-4 py-2 rounded-lg shadow-sm border border-gray-200 flex items-center"> | |
<span class="font-medium">LLaMA 2 7B (int8)</span> | |
<i class="fas fa-chevron-down ml-2 text-gray-500 text-xs"></i> | |
</button> | |
<div class="model-dropdown hidden absolute right-0 mt-2 w-48 bg-white rounded-md shadow-lg z-10 border border-gray-200"> | |
<div class="px-4 py-2 border-b border-gray-100 bg-gray-50 text-gray-500 text-xs uppercase font-semibold">Text Generation</div> | |
<div class="px-4 py-3 hover:bg-blue-50 cursor-pointer font-medium text-blue-600"> | |
<i class="fas fa-check mr-2"></i> LLaMA 2 7B (int8) | |
</div> | |
<div class="px-4 py-3 hover:bg-gray-50 cursor-pointer text-gray-700">LLaMA 2 13B (int8)</div> | |
<div class="px-4 py-3 hover:bg-gray-50 cursor-pointer text-gray-700">LLaMA 2 70B (int8)</div> | |
</div> | |
</div> | |
</header> | |
<!-- Model Info Card --> | |
<div class="bg-white rounded-xl shadow-sm p-6 mb-8 border border-gray-200"> | |
<div class="flex items-start"> | |
<div class="bg-blue-100 p-3 rounded-lg mr-4"> | |
<i class="fas fa-robot text-blue-500 text-xl"></i> | |
</div> | |
<div> | |
<h2 class="text-lg font-bold text-gray-800 mb-1">Meta/LLaMA-2-7B-chat-int8</h2> | |
<p class="text-gray-600 mb-3">A 7 billion parameter version of the LLaMA 2 language model, optimized for chat and quantized to 8-bit for efficient inference.</p> | |
<div class="flex flex-wrap gap-2"> | |
<span class="bg-gray-100 text-gray-700 px-3 py-1 rounded-full text-xs font-medium">7B Parameters</span> | |
<span class="bg-gray-100 text-gray-700 px-3 py-1 rounded-full text-xs font-medium">8-bit Quantized</span> | |
<span class="bg-gray-100 text-gray-700 px-3 py-1 rounded-full text-xs font-medium">Chat Optimized</span> | |
<span class="bg-gray-100 text-gray-700 px-3 py-1 rounded-full text-xs font-medium">Context: 4096 tokens</span> | |
</div> | |
</div> | |
</div> | |
</div> | |
<!-- Chat Container --> | |
<div class="bg-white rounded-xl shadow-sm border border-gray-200 overflow-hidden"> | |
<!-- Messages --> | |
<div class="chat-container overflow-y-auto p-4 space-y-4" id="chat-messages"> | |
<div class="flex items-start"> | |
<div class="bg-gray-200 p-2 rounded-lg mr-3"> | |
<i class="fas fa-robot text-gray-600"></i> | |
</div> | |
<div class="bg-gray-100 rounded-lg px-4 py-3 max-w-[85%] message-animation"> | |
<p class="text-gray-800">Hello! I'm LLaMA 2, a large language model running on Cloudflare's infrastructure. How can I assist you today?</p> | |
</div> | |
</div> | |
</div> | |
<!-- Input Area --> | |
<div class="border-t border-gray-200 p-4 bg-gray-50"> | |
<form id="chat-form" class="flex items-end"> | |
<div class="flex-grow mr-3"> | |
<textarea | |
id="user-input" | |
rows="1" | |
class="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 resize-none" | |
placeholder="Message LLaMA 2..." | |
required | |
></textarea> | |
</div> | |
<button | |
type="submit" | |
class="bg-blue-600 hover:bg-blue-700 text-white px-5 py-3 rounded-lg transition-colors duration-200 flex items-center justify-center" | |
> | |
<i class="fas fa-paper-plane mr-2"></i> | |
<span>Send</span> | |
</button> | |
</form> | |
<div class="mt-2 text-xs text-gray-500 flex items-center"> | |
<i class="fas fa-info-circle mr-1"></i> | |
<span>LLaMA 2 may produce inaccurate information. Consider checking important information.</span> | |
</div> | |
</div> | |
</div> | |
<!-- API Info --> | |
<div class="mt-6 bg-white rounded-xl shadow-sm p-6 border border-gray-200"> | |
<h3 class="font-bold text-gray-800 mb-3 flex items-center"> | |
<i class="fas fa-code mr-2 text-blue-500"></i> | |
API Usage | |
</h3> | |
<div class="bg-gray-800 rounded-lg p-4 mb-4 overflow-x-auto"> | |
<pre class="text-gray-300 text-sm"><code>curl -X POST \ | |
https://api.cloudflare.com/client/v4/accounts/{account_id}/ai/run/@cf/meta/llama-2-7b-chat-int8 \ | |
-H "Authorization: Bearer {api_token}" \ | |
-H "Content-Type: application/json" \ | |
-d '{"messages":[{"role":"user","content":"Explain quantum computing"}]}'</code></pre> | |
</div> | |
<div class="flex items-center text-sm text-gray-600"> | |
<i class="fas fa-link mr-2"></i> | |
<a href="https://developers.cloudflare.com/workers-ai/models/text-generation/" class="text-blue-500 hover:underline">View API documentation</a> | |
</div> | |
</div> | |
</div> | |
<script> | |
document.addEventListener('DOMContentLoaded', function() { | |
const chatForm = document.getElementById('chat-form'); | |
const userInput = document.getElementById('user-input'); | |
const chatMessages = document.getElementById('chat-messages'); | |
// Auto-resize textarea | |
userInput.addEventListener('input', function() { | |
this.style.height = 'auto'; | |
this.style.height = (this.scrollHeight) + 'px'; | |
}); | |
// Sample responses to simulate the model | |
const sampleResponses = [ | |
"I'm an AI assistant based on Meta's LLaMA 2 model. I can help answer questions, explain concepts, or assist with creative writing.", | |
"LLaMA 2 is a collection of pretrained and fine-tuned generative text models ranging in scale from 7 billion to 70 billion parameters.", | |
"The int8 quantization reduces the model's memory footprint while maintaining reasonable accuracy, making it more efficient to run.", | |
"Cloudflare's Workers AI platform allows you to run models like me at the edge, close to your users for low latency.", | |
"I can understand and generate human-like text, but I don't have real-time information or access to the internet." | |
]; | |
chatForm.addEventListener('submit', function(e) { | |
e.preventDefault(); | |
const message = userInput.value.trim(); | |
if (!message) return; | |
// Add user message | |
addMessage('user', message); | |
userInput.value = ''; | |
userInput.style.height = 'auto'; | |
// Show typing indicator | |
const typingId = showTypingIndicator(); | |
// Simulate API delay and response | |
setTimeout(() => { | |
// Remove typing indicator | |
removeTypingIndicator(typingId); | |
// Get random sample response | |
const response = sampleResponses[Math.floor(Math.random() * sampleResponses.length)]; | |
// Add AI response | |
addMessage('ai', response); | |
}, 1500 + Math.random() * 2000); // Random delay between 1.5-3.5s | |
}); | |
function addMessage(role, content) { | |
const messageDiv = document.createElement('div'); | |
messageDiv.className = 'flex items-start message-animation'; | |
if (role === 'user') { | |
messageDiv.innerHTML = ` | |
<div class="ml-auto max-w-[85%] flex flex-row-reverse"> | |
<div class="bg-gray-200 p-2 rounded-lg ml-3"> | |
<i class="fas fa-user text-gray-600"></i> | |
</div> | |
<div class="bg-blue-100 rounded-lg px-4 py-3"> | |
<p class="text-gray-800">${content}</p> | |
</div> | |
</div> | |
`; | |
} else { | |
messageDiv.innerHTML = ` | |
<div class="bg-gray-200 p-2 rounded-lg mr-3"> | |
<i class="fas fa-robot text-gray-600"></i> | |
</div> | |
<div class="bg-gray-100 rounded-lg px-4 py-3 max-w-[85%]"> | |
<p class="text-gray-800">${content}</p> | |
</div> | |
`; | |
} | |
chatMessages.appendChild(messageDiv); | |
chatMessages.scrollTop = chatMessages.scrollHeight; | |
} | |
function showTypingIndicator() { | |
const id = 'typing-' + Date.now(); | |
const typingDiv = document.createElement('div'); | |
typingDiv.id = id; | |
typingDiv.className = 'flex items-start'; | |
typingDiv.innerHTML = ` | |
<div class="bg-gray-200 p-2 rounded-lg mr-3"> | |
<i class="fas fa-robot text-gray-600"></i> | |
</div> | |
<div class="bg-gray-100 rounded-lg px-4 py-3 max-w-[85%] typing-indicator"> | |
<span class="inline-block w-2 h-2 bg-gray-500 rounded-full"></span> | |
<span class="inline-block w-2 h-2 bg-gray-500 rounded-full ml-1"></span> | |
<span class="inline-block w-2 h-2 bg-gray-500 rounded-full ml-1"></span> | |
</div> | |
`; | |
chatMessages.appendChild(typingDiv); | |
chatMessages.scrollTop = chatMessages.scrollHeight; | |
return id; | |
} | |
function removeTypingIndicator(id) { | |
const element = document.getElementById(id); | |
if (element) { | |
element.remove(); | |
} | |
} | |
}); | |
</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=privateuserh/llm" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body> | |
</html> |