knowledge_qa.html 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>知识点询问 - AI 数字人答疑</title>
  7. <style>
  8. :root {
  9. --primary-color: #4a90e2;
  10. --sidebar-width: 250px;
  11. --header-height: 60px;
  12. }
  13. * { margin: 0; padding: 0; box-sizing: border-box; }
  14. body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; background: #f5f7fa; display: flex; height: 100vh; }
  15. .sidebar {
  16. width: var(--sidebar-width);
  17. background: #2c3e50;
  18. color: #ecf0f1;
  19. }
  20. .sidebar-header {
  21. height: var(--header-height);
  22. display: flex;
  23. align-items: center;
  24. justify-content: center;
  25. font-weight: bold;
  26. border-bottom: 1px solid #34495e;
  27. }
  28. .nav-links { list-style: none; padding: 20px 0; }
  29. .nav-links li { padding: 12px 20px; }
  30. .nav-links a { color: inherit; text-decoration: none; }
  31. .nav-links li:hover { background: #34495e; }
  32. .main-content { flex: 1; display: flex; flex-direction: column; }
  33. header {
  34. height: var(--header-height);
  35. background: #fff;
  36. box-shadow: 0 2px 5px rgba(0,0,0,0.05);
  37. display: flex;
  38. justify-content: space-between;
  39. align-items: center;
  40. padding: 0 20px;
  41. }
  42. .content-area {
  43. flex: 1;
  44. padding: 20px;
  45. overflow-y: auto;
  46. }
  47. .qa-container {
  48. max-width: 800px;
  49. margin: 0 auto;
  50. }
  51. .qa-input-row {
  52. display: flex;
  53. gap: 10px;
  54. margin-bottom: 20px;
  55. }
  56. .qa-input-row input {
  57. flex: 1;
  58. padding: 12px 16px;
  59. border: 1px solid #ddd;
  60. border-radius: 8px;
  61. font-size: 16px;
  62. }
  63. .qa-input-row button {
  64. padding: 12px 24px;
  65. background: var(--primary-color);
  66. color: white;
  67. border: none;
  68. border-radius: 8px;
  69. cursor: pointer;
  70. font-size: 16px;
  71. }
  72. .qa-input-row button:hover { background: #357abd; }
  73. .qa-input-row button:disabled { opacity: 0.6; cursor: not-allowed; }
  74. .answer-card {
  75. background: white;
  76. padding: 20px;
  77. border-radius: 8px;
  78. box-shadow: 0 2px 10px rgba(0,0,0,0.05);
  79. margin-top: 20px;
  80. white-space: pre-wrap;
  81. line-height: 1.6;
  82. }
  83. .answer-card.empty { display: none; }
  84. .digital-human-area {
  85. margin-top: 24px;
  86. border: 1px solid #eee;
  87. border-radius: 8px;
  88. overflow: hidden;
  89. background: #fafafa;
  90. }
  91. .digital-human-area iframe {
  92. width: 100%;
  93. height: 400px;
  94. border: none;
  95. }
  96. .hint { color: #666; font-size: 14px; margin-bottom: 12px; }
  97. </style>
  98. </head>
  99. <body>
  100. <div class="sidebar">
  101. <div class="sidebar-header">AI 教学系统</div>
  102. <ul class="nav-links">
  103. <li><a href="/dashboard">🏠 首页</a></li>
  104. <li><a href="/ai_assistant">🤖 AI 助手</a></li>
  105. <li><a href="/knowledge_qa">💬 知识点询问</a></li>
  106. <li><a href="/knowledge_graph">🔗 知识图谱</a></li>
  107. <li><a href="/daily_training">📚 每日训练</a></li>
  108. <li><a href="/wrong_questions">📝 错题集</a></li>
  109. <li><a href="/analysis">📊 学情分析</a></li>
  110. </ul>
  111. </div>
  112. <div class="main-content">
  113. <header>
  114. <h2>知识点询问</h2>
  115. <a href="/logout" style="color: #666;">退出</a>
  116. </header>
  117. <div class="content-area">
  118. <div class="qa-container">
  119. <p class="hint">输入初中化学知识点相关问题,系统将进行意图识别、知识图谱检索、大模型扩充后,以文字形式展示答案;完成后可前往「知识点题目推荐」巩固练习。</p>
  120. <div class="qa-input-row">
  121. <input type="text" id="questionInput" placeholder="例如:什么是电解质?氧化还原反应的条件是什么?" />
  122. <button type="button" id="askBtn">提问</button>
  123. </div>
  124. <div id="answerCard" class="answer-card empty"></div>
  125. <div class="digital-human-area">
  126. <p class="hint" style="padding: 8px;">AI 数字人展示区(可嵌入本地数字人服务 localhost:8880)</p>
  127. <iframe src="http://localhost:8880" title="AI 数字人"></iframe>
  128. </div>
  129. </div>
  130. </div>
  131. </div>
  132. <script>
  133. document.getElementById('askBtn').addEventListener('click', askQuestion);
  134. document.getElementById('questionInput').addEventListener('keypress', function(e) {
  135. if (e.key === 'Enter') askQuestion();
  136. });
  137. function askQuestion() {
  138. const input = document.getElementById('questionInput');
  139. const btn = document.getElementById('askBtn');
  140. const card = document.getElementById('answerCard');
  141. const q = (input.value || '').trim();
  142. if (!q) {
  143. alert('请输入问题');
  144. return;
  145. }
  146. btn.disabled = true;
  147. card.classList.add('empty');
  148. card.textContent = '正在检索知识图谱并生成回答…';
  149. fetch('/api/ask', {
  150. method: 'POST',
  151. headers: { 'Content-Type': 'application/json' },
  152. body: JSON.stringify({ question: q })
  153. })
  154. .then(r => r.json())
  155. .then(data => {
  156. btn.disabled = false;
  157. card.classList.remove('empty');
  158. if (data.ok) {
  159. card.textContent = data.answer;
  160. } else {
  161. card.textContent = '错误:' + (data.error || '请求失败');
  162. }
  163. })
  164. .catch(err => {
  165. btn.disabled = false;
  166. card.classList.remove('empty');
  167. card.textContent = '请求失败:' + err.message;
  168. });
  169. }
  170. </script>
  171. </body>
  172. </html>