Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -46,18 +46,140 @@ def image_to_base64(image_path):
|
|
| 46 |
mime = "image/png"
|
| 47 |
return f"data:{mime};base64,{encoded_string}"
|
| 48 |
|
| 49 |
-
# ================== User Guide Content ==================
|
| 50 |
USER_GUIDE_SECTIONS = {
|
| 51 |
-
"getting_started": "
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
}
|
| 62 |
|
| 63 |
# ================== CSS 样式表 ==================
|
|
@@ -69,11 +191,40 @@ CUSTOM_CSS = """
|
|
| 69 |
border-bottom: 2px solid #f3f4f6; margin-bottom: 15px;
|
| 70 |
}
|
| 71 |
|
| 72 |
-
/* User Guide
|
| 73 |
-
|
| 74 |
-
.
|
| 75 |
-
.
|
| 76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
|
| 78 |
/* Action 按钮加粗 & Tooltip */
|
| 79 |
.action-btn { font-weight: bold !important; font-size: 0.9rem !important; position: relative; overflow: visible !important; }
|
|
@@ -146,8 +297,10 @@ with gr.Blocks(title="Clare – Hanbridge AI Teaching Assistant", css=CUSTOM_CSS
|
|
| 146 |
info="See User Guide for mode definitions details."
|
| 147 |
)
|
| 148 |
|
| 149 |
-
# User Guide (
|
| 150 |
-
|
|
|
|
|
|
|
| 151 |
with gr.Accordion("Getting Started", open=False, elem_classes="clean-accordion"): gr.Markdown(USER_GUIDE_SECTIONS["getting_started"])
|
| 152 |
with gr.Accordion("Mode Definition", open=False, elem_classes="clean-accordion"): gr.Markdown(USER_GUIDE_SECTIONS["mode_definition"])
|
| 153 |
with gr.Accordion("How Clare Works", open=False, elem_classes="clean-accordion"): gr.Markdown(USER_GUIDE_SECTIONS["how_clare_works"])
|
|
@@ -179,17 +332,14 @@ with gr.Blocks(title="Clare – Hanbridge AI Teaching Assistant", css=CUSTOM_CSS
|
|
| 179 |
with gr.Row():
|
| 180 |
# Upload Column
|
| 181 |
with gr.Column(scale=1):
|
| 182 |
-
# 调大高度 height=160
|
| 183 |
syllabus_file = gr.File(
|
| 184 |
file_types=[".docx", ".pdf", ".pptx"],
|
| 185 |
file_count="single",
|
| 186 |
height=160,
|
| 187 |
label="Upload file (.docx/.pdf/.pptx)"
|
| 188 |
)
|
| 189 |
-
# 下拉框 + 查看文档按钮
|
| 190 |
with gr.Row():
|
| 191 |
doc_type = gr.Dropdown(choices=DOC_TYPES, value="Syllabus", label="File type", container=False, scale=3)
|
| 192 |
-
# 这里添加 "Loaded Docs" 按钮/指示器
|
| 193 |
docs_btn = gr.Button("📂 Loaded Docs", size="sm", variant="secondary", scale=2, min_width=80)
|
| 194 |
|
| 195 |
# Memory Line Column
|
|
@@ -229,8 +379,7 @@ with gr.Blocks(title="Clare – Hanbridge AI Teaching Assistant", css=CUSTOM_CSS
|
|
| 229 |
# === [Right Sidebar] ===
|
| 230 |
with gr.Column(scale=1, min_width=180):
|
| 231 |
|
| 232 |
-
#
|
| 233 |
-
# 上传区+MemoryLine 大约高度160px + Gap,设置 200px 左右比较稳妥
|
| 234 |
gr.HTML("<div style='height: 210px; width: 100%;'></div>")
|
| 235 |
|
| 236 |
gr.Markdown("### Actions")
|
|
@@ -250,9 +399,6 @@ with gr.Blocks(title="Clare – Hanbridge AI Teaching Assistant", css=CUSTOM_CSS
|
|
| 250 |
status_md = f"✅ **File Loaded:** {doc_type_val}\n\nAnalyzing content for Memory Line..."
|
| 251 |
return topics, rag_chunks, status_md
|
| 252 |
|
| 253 |
-
syllabus_file.change(update_course_and_rag, [syllabus_file, doc_type], [course_outline_state, rag_chunks_state, session_status])
|
| 254 |
-
|
| 255 |
-
# 简单的 Loaded Docs 提示逻辑
|
| 256 |
docs_btn.click(lambda: gr.Info("Current Context: Syllabus.pdf (Uploaded), Course_Intro.docx (System)", title="Loaded Documents"))
|
| 257 |
|
| 258 |
def respond(message, chat_history, course_outline, weaknesses, cognitive_state, rag_chunks, model, lang, mode, doc_type_val):
|
|
|
|
| 46 |
mime = "image/png"
|
| 47 |
return f"data:{mime};base64,{encoded_string}"
|
| 48 |
|
| 49 |
+
# ================== User Guide Content (已去除重复标题) ==================
|
| 50 |
USER_GUIDE_SECTIONS = {
|
| 51 |
+
"getting_started": """
|
| 52 |
+
Welcome to **Clare — Your Personalized AI Tutor**.
|
| 53 |
+
|
| 54 |
+
Clare is designed to support your learning through:
|
| 55 |
+
- Clear explanations of course concepts
|
| 56 |
+
- Socratic-style reasoning guidance
|
| 57 |
+
- Personalized reinforcement based on learning science
|
| 58 |
+
- Course-aligned answers using your uploaded materials
|
| 59 |
+
- Micro-quizzes & summaries to strengthen understanding
|
| 60 |
+
|
| 61 |
+
**To begin:**
|
| 62 |
+
1. Select your **Learning Mode** on the left
|
| 63 |
+
2. (Optional) Upload your **syllabus / slides / notes** at the top
|
| 64 |
+
3. Ask Clare any question about your course, assignment, or study plan.
|
| 65 |
+
""",
|
| 66 |
+
"mode_definition": """
|
| 67 |
+
Clare offers different teaching modes to match how you prefer to learn.
|
| 68 |
+
|
| 69 |
+
### Concept Explainer
|
| 70 |
+
Clear, structured explanations with examples — ideal for learning new topics.
|
| 71 |
+
|
| 72 |
+
### Socratic Tutor
|
| 73 |
+
Clare asks guiding questions instead of giving direct answers.
|
| 74 |
+
Helps you build reasoning and problem-solving skills.
|
| 75 |
+
|
| 76 |
+
### Exam Prep / Quiz
|
| 77 |
+
Generates short practice questions aligned with your course week.
|
| 78 |
+
Useful for self-testing and preparing for exams.
|
| 79 |
+
|
| 80 |
+
### Assignment Helper
|
| 81 |
+
Helps you interpret assignment prompts, plan structure, and understand requirements.
|
| 82 |
+
❗ Clare does **not** produce full assignment answers (academic integrity).
|
| 83 |
+
|
| 84 |
+
### Quick Summary
|
| 85 |
+
Gives brief summaries of slides, reading materials, or long questions.
|
| 86 |
+
""",
|
| 87 |
+
"how_clare_works": """
|
| 88 |
+
Clare combines **course context + learning science + AI reasoning** to generate answers.
|
| 89 |
+
|
| 90 |
+
Clare uses:
|
| 91 |
+
- **Your selected Learning Mode**: Determines tone, depth, and interaction style.
|
| 92 |
+
- **Your uploaded course files**: Syllabus, slides, or papers help align answers with your specific course.
|
| 93 |
+
- **Reinforcement learning cycle**: Answers may prioritize key concepts you’re likely to forget.
|
| 94 |
+
- **Adaptive explanation depth**: Clare can adjust complexity depending on your previous interactions.
|
| 95 |
+
- **Responsible AI principles**: Avoids harmful output and preserves academic integrity.
|
| 96 |
+
""",
|
| 97 |
+
"memory_line": """
|
| 98 |
+
**Memory Line** is a visualization of your *learning reinforcement cycle*.
|
| 99 |
+
|
| 100 |
+
Based on the **forgetting-curve model**, Clare organizes your review topics into:
|
| 101 |
+
- **T+0 (Current Week)** – new concepts
|
| 102 |
+
- **T+7** – first spaced review
|
| 103 |
+
- **T+14** – reinforcement review
|
| 104 |
+
- **T+30** – long-term consolidation
|
| 105 |
+
|
| 106 |
+
Clare uses these cycles to decide:
|
| 107 |
+
- Which concepts to reinforce today
|
| 108 |
+
- Which explanations to prioritize
|
| 109 |
+
- When to introduce quick review questions
|
| 110 |
+
|
| 111 |
+
**Review Now** will generate a small set of concepts that are due for spaced repetition.
|
| 112 |
+
""",
|
| 113 |
+
"learning_progress": """
|
| 114 |
+
The Learning Progress Report highlights:
|
| 115 |
+
- **Concepts mastered**
|
| 116 |
+
- **Concepts in progress**
|
| 117 |
+
- **Concepts due for review**
|
| 118 |
+
- Your recent **micro-quiz results**
|
| 119 |
+
- Suggested **next-step topics**
|
| 120 |
+
|
| 121 |
+
You can download a **summary** at any time to use as study notes.
|
| 122 |
+
""",
|
| 123 |
+
"how_files": """
|
| 124 |
+
Your uploaded syllabus / slides / notes help Clare:
|
| 125 |
+
|
| 126 |
+
- Align explanations with your exact course
|
| 127 |
+
- Use terminology consistent with your professor
|
| 128 |
+
- Improve factual accuracy
|
| 129 |
+
- Generate personalized reinforcement content
|
| 130 |
+
|
| 131 |
+
🔒 **Privacy**
|
| 132 |
+
- Files are used only within your session
|
| 133 |
+
- They are not kept as permanent training data
|
| 134 |
+
|
| 135 |
+
Accepted formats: **.docx / .pdf / .pptx**
|
| 136 |
+
""",
|
| 137 |
+
"micro_quiz": """
|
| 138 |
+
The **Micro-Quiz** function provides a:
|
| 139 |
+
|
| 140 |
+
- 1-minute self-check
|
| 141 |
+
- 1–3 questions based on your recent topics
|
| 142 |
+
- Instant feedback
|
| 143 |
+
|
| 144 |
+
Micro-quizzes strengthen your memory and are part of Clare’s reinforcement system.
|
| 145 |
+
""",
|
| 146 |
+
"summarization": """
|
| 147 |
+
Clare can summarize:
|
| 148 |
+
|
| 149 |
+
- Lecture notes
|
| 150 |
+
- Uploaded PDFs
|
| 151 |
+
- Long conversation threads
|
| 152 |
+
- Complex concepts
|
| 153 |
+
|
| 154 |
+
Summary styles can include:
|
| 155 |
+
- Bullet points
|
| 156 |
+
- Key ideas
|
| 157 |
+
- Study notes
|
| 158 |
+
- Comparison-style highlights.
|
| 159 |
+
""",
|
| 160 |
+
"export_conversation": """
|
| 161 |
+
You can export your chat session for:
|
| 162 |
+
|
| 163 |
+
- Study review
|
| 164 |
+
- Exam preparation
|
| 165 |
+
- Documentation for tutoring help
|
| 166 |
+
- Saving important explanations
|
| 167 |
+
|
| 168 |
+
Export format: **Markdown / plain text**.
|
| 169 |
+
""",
|
| 170 |
+
"faq": """
|
| 171 |
+
**Q: Does Clare give assignment answers?**
|
| 172 |
+
No. Clare assists with understanding and planning but does **not** generate full solutions.
|
| 173 |
+
|
| 174 |
+
**Q: Does Clare replace lectures or TA office hours?**
|
| 175 |
+
No. Clare supplements your learning by providing on-demand guidance.
|
| 176 |
+
|
| 177 |
+
**Q: Can Clare explain my professor’s slides?**
|
| 178 |
+
Yes — upload your slides so Clare can align explanations with your course.
|
| 179 |
+
|
| 180 |
+
**Q: What languages does Clare support?**
|
| 181 |
+
Currently: English & 简体中文.
|
| 182 |
+
"""
|
| 183 |
}
|
| 184 |
|
| 185 |
# ================== CSS 样式表 ==================
|
|
|
|
| 191 |
border-bottom: 2px solid #f3f4f6; margin-bottom: 15px;
|
| 192 |
}
|
| 193 |
|
| 194 |
+
/* --- User Guide 样式优化 --- */
|
| 195 |
+
|
| 196 |
+
/* 1. 最外层 User Guide (大标题) */
|
| 197 |
+
.main-user-guide {
|
| 198 |
+
border: none !important;
|
| 199 |
+
background: transparent !important;
|
| 200 |
+
}
|
| 201 |
+
.main-user-guide > .label-wrap span {
|
| 202 |
+
font-size: 1.2rem !important; /* 加大 */
|
| 203 |
+
font-weight: 800 !important; /* 加粗 */
|
| 204 |
+
color: #111827 !important; /* 深黑色 */
|
| 205 |
+
}
|
| 206 |
+
|
| 207 |
+
/* 2. 内部子菜单 (小标题) */
|
| 208 |
+
.clean-accordion {
|
| 209 |
+
border: none !important;
|
| 210 |
+
background: transparent !important;
|
| 211 |
+
box-shadow: none !important;
|
| 212 |
+
margin-bottom: 0px !important;
|
| 213 |
+
padding: 0 !important;
|
| 214 |
+
}
|
| 215 |
+
.clean-accordion > .label-wrap {
|
| 216 |
+
padding: 6px 0 !important;
|
| 217 |
+
border-bottom: 1px solid #f3f4f6 !important;
|
| 218 |
+
}
|
| 219 |
+
.clean-accordion > .label-wrap span {
|
| 220 |
+
font-size: 0.9rem !important; /* 比主标题小 */
|
| 221 |
+
font-weight: 500 !important; /* 中等粗细 */
|
| 222 |
+
color: #4b5563 !important; /* 深灰色 */
|
| 223 |
+
}
|
| 224 |
+
.clean-accordion > .label-wrap:hover span {
|
| 225 |
+
color: #000 !important;
|
| 226 |
+
text-decoration: underline;
|
| 227 |
+
}
|
| 228 |
|
| 229 |
/* Action 按钮加粗 & Tooltip */
|
| 230 |
.action-btn { font-weight: bold !important; font-size: 0.9rem !important; position: relative; overflow: visible !important; }
|
|
|
|
| 297 |
info="See User Guide for mode definitions details."
|
| 298 |
)
|
| 299 |
|
| 300 |
+
# User Guide (主标题加粗加大,子标题变小)
|
| 301 |
+
# 给最外层加上 elem_classes="main-user-guide"
|
| 302 |
+
with gr.Accordion("User Guide", open=True, elem_classes="main-user-guide"):
|
| 303 |
+
# 子项只保留 clean-accordion 样式
|
| 304 |
with gr.Accordion("Getting Started", open=False, elem_classes="clean-accordion"): gr.Markdown(USER_GUIDE_SECTIONS["getting_started"])
|
| 305 |
with gr.Accordion("Mode Definition", open=False, elem_classes="clean-accordion"): gr.Markdown(USER_GUIDE_SECTIONS["mode_definition"])
|
| 306 |
with gr.Accordion("How Clare Works", open=False, elem_classes="clean-accordion"): gr.Markdown(USER_GUIDE_SECTIONS["how_clare_works"])
|
|
|
|
| 332 |
with gr.Row():
|
| 333 |
# Upload Column
|
| 334 |
with gr.Column(scale=1):
|
|
|
|
| 335 |
syllabus_file = gr.File(
|
| 336 |
file_types=[".docx", ".pdf", ".pptx"],
|
| 337 |
file_count="single",
|
| 338 |
height=160,
|
| 339 |
label="Upload file (.docx/.pdf/.pptx)"
|
| 340 |
)
|
|
|
|
| 341 |
with gr.Row():
|
| 342 |
doc_type = gr.Dropdown(choices=DOC_TYPES, value="Syllabus", label="File type", container=False, scale=3)
|
|
|
|
| 343 |
docs_btn = gr.Button("📂 Loaded Docs", size="sm", variant="secondary", scale=2, min_width=80)
|
| 344 |
|
| 345 |
# Memory Line Column
|
|
|
|
| 379 |
# === [Right Sidebar] ===
|
| 380 |
with gr.Column(scale=1, min_width=180):
|
| 381 |
|
| 382 |
+
# Spacer
|
|
|
|
| 383 |
gr.HTML("<div style='height: 210px; width: 100%;'></div>")
|
| 384 |
|
| 385 |
gr.Markdown("### Actions")
|
|
|
|
| 399 |
status_md = f"✅ **File Loaded:** {doc_type_val}\n\nAnalyzing content for Memory Line..."
|
| 400 |
return topics, rag_chunks, status_md
|
| 401 |
|
|
|
|
|
|
|
|
|
|
| 402 |
docs_btn.click(lambda: gr.Info("Current Context: Syllabus.pdf (Uploaded), Course_Intro.docx (System)", title="Loaded Documents"))
|
| 403 |
|
| 404 |
def respond(message, chat_history, course_outline, weaknesses, cognitive_state, rag_chunks, model, lang, mode, doc_type_val):
|