Spaces:
No application file
No application file
Download client.html from Erenuo/RAG_IR_API: direct link, hf CLI and curl.
- Browser
- Download file 6.01 kB
-
https://huggingface.co/spaces/Erenuo/RAG_IR_API/resolve/main/client.html
- Command line
-
hf download hf://spaces/Erenuo/RAG_IR_API/client.html
-
curl -L -o client.html https://huggingface.co/spaces/Erenuo/RAG_IR_API/resolve/main/client.html
6.01 kB
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>Intent Recognition API Client</title> | |
| <script src="https://cdn.tailwindcss.com"></script> | |
| <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet"> | |
| <style> | |
| body { font-family: 'Inter', sans-serif; } | |
| .spinner { | |
| border: 4px solid rgba(0, 0, 0, 0.1); | |
| width: 36px; height: 36px; border-radius: 50%; | |
| border-left-color: #09f; | |
| animation: spin 1s ease infinite; | |
| } | |
| @keyframes spin { | |
| 0% { transform: rotate(0deg); } | |
| 100% { transform: rotate(360deg); } | |
| } | |
| </style> | |
| </head> | |
| <body class="bg-gray-100 flex items-center justify-center min-h-screen"> | |
| <div class="w-full max-w-2xl mx-auto bg-white rounded-xl shadow-lg p-8"> | |
| <div class="text-center mb-8"> | |
| <h1 class="text-3xl font-bold text-gray-800">Intent Recognizer</h1> | |
| <p class="text-gray-500 mt-2">Enter a sentence to find its top intents using the API.</p> | |
| </div> | |
| <div class="space-y-4"> | |
| <textarea id="query-input" class="w-full h-24 p-4 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500" placeholder="e.g., can you reduce the price on the house in islington"></textarea> | |
| <button id="submit-btn" class="w-full bg-blue-600 text-white font-semibold py-3 px-4 rounded-lg hover:bg-blue-700"> | |
| Recognize Intent | |
| </button> | |
| </div> | |
| <div id="results-container" class="mt-8 hidden"> | |
| <h2 class="text-2xl font-semibold text-gray-700 mb-4 border-b pb-2">API Response</h2> | |
| <div id="results-content" class="space-y-6 bg-gray-50 p-6 rounded-lg"> | |
| <!-- Results will be injected here --> | |
| </div> | |
| </div> | |
| <div id="loading-spinner" class="hidden justify-center mt-8"> | |
| <div class="spinner"></div> | |
| </div> | |
| <div id="error-message" class="hidden mt-6 p-4 bg-red-100 text-red-700 border border-red-300 rounded-lg"></div> | |
| </div> | |
| <script> | |
| const submitBtn = document.getElementById('submit-btn'); | |
| const queryInput = document.getElementById('query-input'); | |
| const resultsContainer = document.getElementById('results-container'); | |
| const resultsContent = document.getElementById('results-content'); | |
| const loadingSpinner = document.getElementById('loading-spinner'); | |
| const errorMessage = document.getElementById('error-message'); | |
| const API_URL = "http://127.0.0.1:8000/recognize-intent/"; | |
| submitBtn.addEventListener('click', async () => { | |
| const query = queryInput.value.trim(); | |
| if (!query) { return; } | |
| loadingSpinner.style.display = 'flex'; | |
| resultsContainer.style.display = 'none'; | |
| errorMessage.style.display = 'none'; | |
| resultsContent.innerHTML = ''; | |
| try { | |
| const response = await fetch(API_URL, { | |
| method: 'POST', | |
| headers: { 'Content-Type': 'application/json' }, | |
| body: JSON.stringify({ text: query }), | |
| }); | |
| if (!response.ok) { | |
| const errorData = await response.json(); | |
| throw new Error(errorData.detail || `API request failed: ${response.status}`); | |
| } | |
| const data = await response.json(); | |
| displayResults(data); | |
| } catch (error) { | |
| displayError(error); | |
| } finally { | |
| loadingSpinner.style.display = 'none'; | |
| } | |
| }); | |
| function displayResults(data) { | |
| resultsContainer.style.display = 'block'; | |
| // FIX: The API now returns a `predictions` array. We must loop through it. | |
| // The error occurs when trying to access `data.confidence_score` which no longer exists. | |
| // The correct value is inside each `prediction` object as `prediction.score`. | |
| data.predictions.forEach((prediction, index) => { | |
| const intent = prediction.intent; | |
| const score = prediction.score.toFixed(4); // Accessing score from the prediction object | |
| const resultBlock = ` | |
| <div> | |
| <div class="flex justify-between items-center"> | |
| <span class="text-sm font-bold text-gray-500">Prediction #${index + 1}</span> | |
| </div> | |
| <div class="mt-2 grid grid-cols-2 gap-4"> | |
| <div class="flex flex-col"> | |
| <span class="text-sm font-medium text-gray-500">Recognized Intent</span> | |
| <span class="text-lg font-semibold text-gray-800">${intent}</span> | |
| </div> | |
| <div class="flex flex-col"> | |
| <span class="text-sm font-medium text-gray-500">Confidence Score</span> | |
| <span class="text-lg font-semibold text-gray-800">${score}</span> | |
| </div> | |
| </div> | |
| </div> | |
| `; | |
| // Add a divider if it's not the last item | |
| resultsContent.innerHTML += resultBlock + (index < data.predictions.length - 1 ? '<hr class="my-3">' : ''); | |
| }); | |
| } | |
| function displayError(error) { | |
| errorMessage.style.display = 'block'; | |
| errorMessage.textContent = `An error occurred: ${error.message}. Please ensure the API server is running.`; | |
| } | |
| </script> | |
| </body> | |
| </html> | |