Update app.py
Browse files
    	
        app.py
    CHANGED
    
    | 
         @@ -184,15 +184,7 @@ def moderations(): 
     | 
|
| 184 | 
         
             
                        concurrent_requests -= 1
         
     | 
| 185 | 
         | 
| 186 | 
         
             
            @app.route('/v1/metrics', methods=['GET'])
         
     | 
| 187 | 
         
            -
            def metrics():
         
     | 
| 188 | 
         
            -
                auth_header = request.headers.get('Authorization')
         
     | 
| 189 | 
         
            -
                if not auth_header or not auth_header.startswith("Bearer "):
         
     | 
| 190 | 
         
            -
                    return jsonify({"error": "Unauthorized"}), 401
         
     | 
| 191 | 
         
            -
                
         
     | 
| 192 | 
         
            -
                provided_api_key = auth_header.split(" ")[1]
         
     | 
| 193 | 
         
            -
                if provided_api_key != API_KEY:
         
     | 
| 194 | 
         
            -
                    return jsonify({"error": "Unauthorized"}), 401
         
     | 
| 195 | 
         
            -
                
         
     | 
| 196 | 
         
             
                return jsonify(get_performance_metrics())
         
     | 
| 197 | 
         | 
| 198 | 
         
             
            def create_directories_and_files():
         
     | 
| 
         @@ -340,11 +332,6 @@ def create_directories_and_files(): 
     | 
|
| 340 | 
         | 
| 341 | 
         
             
                        <div class="bg-white dark:bg-gray-800 rounded-xl shadow-lg p-6">
         
     | 
| 342 | 
         
             
                            <form id="apiTestForm">
         
     | 
| 343 | 
         
            -
                                <div class="mb-6">
         
     | 
| 344 | 
         
            -
                                    <label class="block text-sm font-medium mb-2" for="apiKey">API Key</label>
         
     | 
| 345 | 
         
            -
                                    <input type="password" id="apiKey" class="w-full px-4 py-2 rounded-lg border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 focus:outline-none focus:ring-2 focus:ring-primary-500" placeholder="Enter your API key">
         
     | 
| 346 | 
         
            -
                                </div>
         
     | 
| 347 | 
         
            -
                                
         
     | 
| 348 | 
         
             
                                <div class="mb-6">
         
     | 
| 349 | 
         
             
                                    <label class="block text-sm font-medium mb-2">Text Inputs</label>
         
     | 
| 350 | 
         
             
                                    <div id="textInputsContainer">
         
     | 
| 
         @@ -485,11 +472,8 @@ def create_directories_and_files(): 
     | 
|
| 485 | 
         
             
                    }
         
     | 
| 486 | 
         | 
| 487 | 
         
             
                    async function fetchMetrics() {
         
     | 
| 488 | 
         
            -
                        const apiKey = document.getElementById('apiKey').value || 'temp-key-for-metrics';
         
     | 
| 489 | 
         
             
                        try {
         
     | 
| 490 | 
         
            -
                            const response = await fetch('/v1/metrics' 
     | 
| 491 | 
         
            -
                                headers: { 'Authorization': 'Bearer ' + apiKey }
         
     | 
| 492 | 
         
            -
                            });
         
     | 
| 493 | 
         
             
                            if (!response.ok) {
         
     | 
| 494 | 
         
             
                                const error = await response.json();
         
     | 
| 495 | 
         
             
                                console.error('Failed to fetch metrics:', error.error);
         
     | 
| 
         @@ -562,8 +546,6 @@ def create_directories_and_files(): 
     | 
|
| 562 | 
         
             
                    document.getElementById('apiTestForm').addEventListener('submit', async (e) => {
         
     | 
| 563 | 
         
             
                        e.preventDefault();
         
     | 
| 564 | 
         | 
| 565 | 
         
            -
                        const apiKey = document.getElementById('apiKey').value;
         
     | 
| 566 | 
         
            -
                        if (!apiKey) { alert('Please enter your API key'); return; }
         
     | 
| 567 | 
         | 
| 568 | 
         
             
                        const texts = Array.from(document.querySelectorAll('#textInputsContainer textarea'))
         
     | 
| 569 | 
         
             
                                            .map(t => t.value.trim()).filter(Boolean);
         
     | 
| 
         @@ -579,7 +561,7 @@ def create_directories_and_files(): 
     | 
|
| 579 | 
         
             
                        try {
         
     | 
| 580 | 
         
             
                            const response = await fetch('/v1/moderations', {
         
     | 
| 581 | 
         
             
                                method: 'POST',
         
     | 
| 582 | 
         
            -
                                headers: { 'Content-Type': 'application/json' 
     | 
| 583 | 
         
             
                                body: JSON.stringify({ input: texts.length === 1 ? texts[0] : texts })
         
     | 
| 584 | 
         
             
                            });
         
     | 
| 585 | 
         | 
| 
         | 
|
| 184 | 
         
             
                        concurrent_requests -= 1
         
     | 
| 185 | 
         | 
| 186 | 
         
             
            @app.route('/v1/metrics', methods=['GET'])
         
     | 
| 187 | 
         
            +
            def metrics():    
         
     | 
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 188 | 
         
             
                return jsonify(get_performance_metrics())
         
     | 
| 189 | 
         | 
| 190 | 
         
             
            def create_directories_and_files():
         
     | 
| 
         | 
|
| 332 | 
         | 
| 333 | 
         
             
                        <div class="bg-white dark:bg-gray-800 rounded-xl shadow-lg p-6">
         
     | 
| 334 | 
         
             
                            <form id="apiTestForm">
         
     | 
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 335 | 
         
             
                                <div class="mb-6">
         
     | 
| 336 | 
         
             
                                    <label class="block text-sm font-medium mb-2">Text Inputs</label>
         
     | 
| 337 | 
         
             
                                    <div id="textInputsContainer">
         
     | 
| 
         | 
|
| 472 | 
         
             
                    }
         
     | 
| 473 | 
         | 
| 474 | 
         
             
                    async function fetchMetrics() {
         
     | 
| 
         | 
|
| 475 | 
         
             
                        try {
         
     | 
| 476 | 
         
            +
                            const response = await fetch('/v1/metrics');
         
     | 
| 
         | 
|
| 
         | 
|
| 477 | 
         
             
                            if (!response.ok) {
         
     | 
| 478 | 
         
             
                                const error = await response.json();
         
     | 
| 479 | 
         
             
                                console.error('Failed to fetch metrics:', error.error);
         
     | 
| 
         | 
|
| 546 | 
         
             
                    document.getElementById('apiTestForm').addEventListener('submit', async (e) => {
         
     | 
| 547 | 
         
             
                        e.preventDefault();
         
     | 
| 548 | 
         | 
| 
         | 
|
| 
         | 
|
| 549 | 
         | 
| 550 | 
         
             
                        const texts = Array.from(document.querySelectorAll('#textInputsContainer textarea'))
         
     | 
| 551 | 
         
             
                                            .map(t => t.value.trim()).filter(Boolean);
         
     | 
| 
         | 
|
| 561 | 
         
             
                        try {
         
     | 
| 562 | 
         
             
                            const response = await fetch('/v1/moderations', {
         
     | 
| 563 | 
         
             
                                method: 'POST',
         
     | 
| 564 | 
         
            +
                                headers: { 'Content-Type': 'application/json' },
         
     | 
| 565 | 
         
             
                                body: JSON.stringify({ input: texts.length === 1 ? texts[0] : texts })
         
     | 
| 566 | 
         
             
                            });
         
     | 
| 567 | 
         |