File size: 2,342 Bytes
54ba978
87f60ba
 
 
 
cb79076
688f230
87f60ba
688f230
 
87f60ba
 
 
 
 
 
cb79076
 
87f60ba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
688f230
 
87f60ba
 
 
 
 
 
 
 
 
 
478bcd0
cb79076
87f60ba
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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)