Initial commit of the RAG API application
هذا الالتزام موجود في:
179
rerank_test.html
Normal file
179
rerank_test.html
Normal file
@@ -0,0 +1,179 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>RAG Re-ranking Test</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
|
||||
margin: 0;
|
||||
padding: 20px;
|
||||
background-color: #f7f7f7;
|
||||
color: #333;
|
||||
}
|
||||
.container {
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
background: #fff;
|
||||
padding: 25px;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
|
||||
}
|
||||
h1 {
|
||||
text-align: center;
|
||||
color: #444;
|
||||
}
|
||||
.query-form {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
#query-input {
|
||||
flex-grow: 1;
|
||||
padding: 10px 15px;
|
||||
border: 1px solid #ccc;
|
||||
border-radius: 4px;
|
||||
font-size: 16px;
|
||||
}
|
||||
#query-button {
|
||||
padding: 10px 20px;
|
||||
border: none;
|
||||
background-color: #007bff;
|
||||
color: white;
|
||||
border-radius: 4px;
|
||||
font-size: 16px;
|
||||
cursor: pointer;
|
||||
transition: background-color 0.3s;
|
||||
}
|
||||
#query-button:hover {
|
||||
background-color: #0056b3;
|
||||
}
|
||||
.results-container {
|
||||
display: flex;
|
||||
gap: 20px;
|
||||
justify-content: space-between;
|
||||
}
|
||||
.results-column {
|
||||
width: 48%;
|
||||
}
|
||||
h2 {
|
||||
color: #555;
|
||||
border-bottom: 2px solid #eee;
|
||||
padding-bottom: 10px;
|
||||
}
|
||||
.result-item {
|
||||
background: #fafafa;
|
||||
border: 1px solid #eee;
|
||||
border-radius: 5px;
|
||||
padding: 15px;
|
||||
margin-bottom: 10px;
|
||||
box-shadow: 0 1px 3px rgba(0,0,0,0.05);
|
||||
}
|
||||
.result-item p {
|
||||
margin: 0 0 10px 0;
|
||||
white-space: pre-wrap; /* Preserve whitespace and newlines */
|
||||
}
|
||||
.result-item .score {
|
||||
font-weight: bold;
|
||||
color: #007bff;
|
||||
}
|
||||
.loader {
|
||||
text-align: center;
|
||||
padding: 20px;
|
||||
font-size: 18px;
|
||||
display: none; /* Hidden by default */
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="container">
|
||||
<h1>RAG Re-ranking Visualizer</h1>
|
||||
<div class="query-form">
|
||||
<input type="text" id="query-input" placeholder="Enter your query...">
|
||||
<button id="query-button">Search</button>
|
||||
</div>
|
||||
|
||||
<div class="loader" id="loader">Loading...</div>
|
||||
|
||||
<div class="results-container">
|
||||
<div class="results-column" id="initial-results-col">
|
||||
<h2>Initial Retrieval (Before Re-ranking)</h2>
|
||||
<div id="initial-results"></div>
|
||||
</div>
|
||||
<div class="results-column" id="reranked-results-col">
|
||||
<h2>Re-ranked Results (Top 5)</h2>
|
||||
<div id="reranked-results"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
const queryInput = document.getElementById('query-input');
|
||||
const queryButton = document.getElementById('query-button');
|
||||
const initialResultsDiv = document.getElementById('initial-results');
|
||||
const rerankedResultsDiv = document.getElementById('reranked-results');
|
||||
const loader = document.getElementById('loader');
|
||||
|
||||
queryButton.addEventListener('click', async () => {
|
||||
const query = queryInput.value;
|
||||
if (!query) {
|
||||
alert('Please enter a query.');
|
||||
return;
|
||||
}
|
||||
|
||||
initialResultsDiv.innerHTML = '';
|
||||
rerankedResultsDiv.innerHTML = '';
|
||||
loader.style.display = 'block';
|
||||
|
||||
try {
|
||||
const response = await fetch('http://127.0.0.1:8000/test-rerank/', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({ query: query, k: 5 }),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
displayResults(data.initial_results, initialResultsDiv);
|
||||
displayResults(data.reranked_results, rerankedResultsDiv);
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error fetching data:', error);
|
||||
alert('Failed to fetch results. Check the console for details.');
|
||||
} finally {
|
||||
loader.style.display = 'none';
|
||||
}
|
||||
});
|
||||
|
||||
function displayResults(results, element) {
|
||||
if (!results || results.length === 0) {
|
||||
element.innerHTML = '<p>No results found.</p>';
|
||||
return;
|
||||
}
|
||||
|
||||
results.forEach(item => {
|
||||
const div = document.createElement('div');
|
||||
div.className = 'result-item';
|
||||
|
||||
const scoreP = document.createElement('p');
|
||||
scoreP.innerHTML = `<span class="score">Score: ${item.score.toFixed(4)}</span>`;
|
||||
|
||||
const textP = document.createElement('p');
|
||||
textP.textContent = item.text;
|
||||
|
||||
div.appendChild(scoreP);
|
||||
div.appendChild(textP);
|
||||
element.appendChild(div);
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
المرجع في مشكلة جديدة
حظر مستخدم