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>