Spaces:
Sleeping
Sleeping
| import os | |
| document.getElementById('avgResponseTime').textContent = data.avg_request_time_ms.toFixed(0) + 'ms'; | |
| document.getElementById('concurrentRequests').textContent = data.concurrent_requests; | |
| document.getElementById('requestsPerMinute').textContent = data.requests_per_minute; | |
| document.getElementById('todayRequests').textContent = data.today_requests; | |
| } | |
| } catch (error) { | |
| console.error('Error updating metrics:', error); | |
| } | |
| } | |
| function showLoading(show) { | |
| if (show) { | |
| loadingModal.classList.remove('hidden'); | |
| } else { | |
| loadingModal.classList.add('hidden'); | |
| } | |
| } | |
| function showNotification(message, type = 'info') { | |
| const notification = document.createElement('div'); | |
| notification.className = `fixed top-4 right-4 p-4 rounded-lg shadow-lg z-50 ${ | |
| type === 'error' ? 'bg-red-500' : 'bg-indigo-500' | |
| } text-white`; | |
| notification.innerHTML = ` | |
| <div class="flex items-center"> | |
| <i class="fas ${type === 'error' ? 'fa-exclamation-circle' : 'fa-info-circle'} mr-2"></i> | |
| <span>${message}</span> | |
| </div> | |
| `; | |
| document.body.appendChild(notification); | |
| setTimeout(() => { | |
| notification.style.opacity = '0'; | |
| notification.style.transition = 'opacity 0.5s'; | |
| setTimeout(() => { | |
| document.body.removeChild(notification); | |
| }, 500); | |
| }, 3000); | |
| } | |
| document.addEventListener('DOMContentLoaded', () => { | |
| addMixedItem(); | |
| updateMetrics(); | |
| setInterval(updateMetrics, 30000); | |
| }); | |
| </script> | |
| </body> | |
| </html>""") | |
| print("Initializing models...") | |
| with torch.inference_mode(): | |
| _ = model.generate( | |
| **tokenizer(["Hello"], return_tensors="pt").to(model.device), | |
| max_new_tokens=1, do_sample=False, use_cache=True | |
| ) | |
| print("🚀 Starting AI Content Moderator API...") | |
| if __name__ == "__main__": | |
| uvicorn.run(app, host="0.0.0.0", port=7860) |