Spaces:
Sleeping
Sleeping
File size: 11,891 Bytes
a978f0c 2e17793 a978f0c 2e17793 a978f0c 4c05cc0 a978f0c 2e17793 a978f0c 2e17793 a978f0c 2e17793 a978f0c 2e17793 a978f0c 2e17793 a978f0c 2e17793 a978f0c 2e17793 a978f0c 2e17793 a978f0c 2e17793 a978f0c | 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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 | <!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>κΈμ΅ RAG μμ€ν
- μ€ν μ°Έμ¬</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
padding: 20px;
}
.container {
max-width: 1200px;
margin: 0 auto;
background: white;
border-radius: 20px;
box-shadow: 0 20px 60px rgba(0,0,0,0.3);
overflow: hidden;
}
.header {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
padding: 30px;
text-align: center;
}
.header h1 {
font-size: 2.5em;
margin-bottom: 10px;
}
.header p {
font-size: 1.2em;
opacity: 0.9;
}
.main-content {
padding: 40px;
}
.api-key-section {
background: #f8f9fa;
padding: 20px;
border-radius: 10px;
margin-bottom: 30px;
}
.api-key-section h3 {
color: #667eea;
margin-bottom: 15px;
}
.input-group {
margin-bottom: 20px;
}
.input-group label {
display: block;
margin-bottom: 8px;
font-weight: 600;
color: #333;
}
.input-group input {
width: 100%;
padding: 12px;
border: 2px solid #e0e0e0;
border-radius: 8px;
font-size: 1em;
transition: border-color 0.3s;
}
.input-group input:focus {
outline: none;
border-color: #667eea;
}
.question-section {
margin-bottom: 30px;
}
.question-section textarea {
width: 100%;
padding: 15px;
border: 2px solid #e0e0e0;
border-radius: 8px;
font-size: 1em;
min-height: 120px;
resize: vertical;
font-family: inherit;
}
.question-section textarea:focus {
outline: none;
border-color: #667eea;
}
.examples {
display: flex;
gap: 10px;
flex-wrap: wrap;
margin-top: 15px;
}
.example-btn {
padding: 8px 16px;
background: #e8eaf6;
border: none;
border-radius: 20px;
cursor: pointer;
transition: all 0.3s;
font-size: 0.9em;
}
.example-btn:hover {
background: #667eea;
color: white;
transform: translateY(-2px);
}
.submit-btn {
width: 100%;
padding: 15px;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
border: none;
border-radius: 8px;
font-size: 1.1em;
font-weight: 600;
cursor: pointer;
transition: transform 0.3s;
}
.submit-btn:hover {
transform: translateY(-2px);
}
.submit-btn:disabled {
opacity: 0.6;
cursor: not-allowed;
transform: none;
}
.result-section {
margin-top: 30px;
padding: 25px;
background: #f8f9fa;
border-radius: 10px;
display: none;
}
.result-section.show {
display: block;
}
.answer {
background: white;
padding: 20px;
border-radius: 8px;
border-left: 4px solid #667eea;
line-height: 1.6;
}
.loading {
text-align: center;
padding: 40px;
}
.spinner {
border: 4px solid #f3f3f3;
border-top: 4px solid #667eea;
border-radius: 50%;
width: 50px;
height: 50px;
animation: spin 1s linear infinite;
margin: 0 auto;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
.error {
background: #fee;
color: #c33;
padding: 15px;
border-radius: 8px;
border-left: 4px solid #c33;
}
.info-box {
background: #e3f2fd;
padding: 15px;
border-radius: 8px;
margin-bottom: 20px;
border-left: 4px solid #2196f3;
}
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1>π κΈμ΅ RAG μμ€ν
</h1>
<p>λ©νμΈμ§ μμ΄μ νΈ κΈ°λ° κΈμ΅ μ§μμλ΅ μμ€ν
</p>
</div>
<div class="main-content">
<div class="info-box">
<strong>π― μ€ν μλ΄:</strong> μ΄ μμ€ν
μ κΈμ΅/κ²½μ λ
Όλ¬Έμ κΈ°λ°μΌλ‘ λ΅λ³μ μμ±ν©λλ€.
μ§λ¬Έμ μ
λ ₯νκ³ λ΅λ³μ νμΈν΄μ£ΌμΈμ. (API ν€ μ
λ ₯ λΆνμ)
</div>
<!-- API ν€λ λ°±μλ μλ²μμ κ΄λ¦¬ -->
<div class="question-section">
<div class="input-group">
<label for="question">π¬ μ§λ¬Έμ μ
λ ₯νμΈμ</label>
<textarea
id="question"
placeholder="μ: ν¬νΈν΄λ¦¬μ€ λ€κ°νμ ν¨κ³Όλ 무μμΈκ°μ?"
></textarea>
</div>
<div class="examples">
<button class="example-btn" onclick="setQuestion('ν¬νΈν΄λ¦¬μ€ λ€κ°νμ ν¨κ³Όλ 무μμΈκ°μ?')">
ν¬νΈν΄λ¦¬μ€ λ€κ°ν
</button>
<button class="example-btn" onclick="setQuestion('κΈμ΅μκΈ°μ μ£Όμ μμΈμ 무μμΈκ°μ?')">
κΈμ΅μκΈ° μμΈ
</button>
<button class="example-btn" onclick="setQuestion('ν¨μ¨μ μμ₯ κ°μ€μ΄λ 무μμΈκ°μ?')">
ν¨μ¨μ μμ₯ κ°μ€
</button>
<button class="example-btn" onclick="setQuestion('νλμ¬λ¬΄νμ μ£Όμ κ°λ
μ μ€λͺ
ν΄μ£ΌμΈμ.')">
νλμ¬λ¬΄ν
</button>
</div>
</div>
<button class="submit-btn" onclick="submitQuestion()" id="submitBtn">
π μ§λ¬ΈνκΈ°
</button>
<div class="result-section" id="resultSection">
<h3 style="margin-bottom: 15px; color: #667eea;">π λ΅λ³</h3>
<div id="resultContent"></div>
</div>
</div>
</div>
<script>
function setQuestion(text) {
document.getElementById('question').value = text;
}
// λ°±μλ API URL
const API_BASE_URL = 'https://hallucination-and-deception-for.onrender.com';
async function submitQuestion() {
const question = document.getElementById('question').value.trim();
if (!question) {
alert('μ§λ¬Έμ μ
λ ₯ν΄μ£ΌμΈμ.');
return;
}
const submitBtn = document.getElementById('submitBtn');
const resultSection = document.getElementById('resultSection');
const resultContent = document.getElementById('resultContent');
// λ‘λ© νμ
submitBtn.disabled = true;
submitBtn.textContent = 'μ²λ¦¬ μ€...';
resultSection.classList.add('show');
resultContent.innerHTML = `
<div class="loading">
<div class="spinner"></div>
<p style="margin-top: 20px;">λ΅λ³μ μμ±νκ³ μμ΅λλ€...</p>
</div>
`;
try {
// λ°±μλ API νΈμΆ
const response = await fetch(`${API_BASE_URL}/query`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
question: question,
top_k: 5,
enable_metacognition: true
})
});
if (!response.ok) {
throw new Error(`API μ€λ₯: ${response.status} - λ°±μλ μλ²λ₯Ό νμΈν΄μ£ΌμΈμ.`);
}
const data = await response.json();
const answer = data.answer;
const sources = data.sources || [];
// κ²°κ³Ό νμ
resultContent.innerHTML = `
<div class="answer">
<h4 style="color: #667eea; margin-bottom: 15px;">π λ΅λ³</h4>
<p style="white-space: pre-wrap; line-height: 1.8;">${answer}</p>
</div>
${sources.length > 0 ? `
<div style="margin-top: 20px; padding: 15px; background: white; border-radius: 8px;">
<h4 style="color: #667eea; margin-bottom: 10px;">π μ°Έκ³ λ¬Έμ (${sources.length}κ°)</h4>
${sources.map((source, i) => `
<div style="margin-bottom: 10px; padding: 10px; background: #f8f9fa; border-radius: 5px;">
<strong>[${i + 1}] ${source.title || source.source_filename || 'Unknown'}</strong>
<p style="margin-top: 5px; font-size: 0.9em; color: #666;">${(source.text || source.content || '').substring(0, 200)}...</p>
</div>
`).join('')}
</div>
` : ''}
${data.metacognition ? `
<div style="margin-top: 20px; padding: 15px; background: #fff3cd; border-radius: 8px; border-left: 4px solid #ffc107;">
<h4 style="color: #856404; margin-bottom: 10px;">π§ λ©νμΈμ§ λΆμ</h4>
<p style="font-size: 0.9em; color: #856404;">
<strong>λ°λ³΅ νμ:</strong> ${data.metacognition.iterations || 0}ν<br>
<strong>μ΅μ’
μ μ:</strong> ${data.metacognition.final_score || 0}/10
</p>
</div>
` : ''}
`;
} catch (error) {
resultContent.innerHTML = `
<div class="error">
<strong>β μ€λ₯ λ°μ</strong><br>
${error.message}<br><br>
<small>λ°±μλ μλ²κ° μ€ν μ€μΈμ§ νμΈνκ±°λ μ μ ν λ€μ μλν΄μ£ΌμΈμ.</small>
</div>
`;
} finally {
submitBtn.disabled = false;
submitBtn.textContent = 'π μ§λ¬ΈνκΈ°';
}
}
// Enter ν€λ‘ μ μΆ
document.getElementById('question').addEventListener('keydown', function(e) {
if (e.key === 'Enter' && e.ctrlKey) {
submitQuestion();
}
});
</script>
</body>
</html>
|