SarahXia0405 commited on
Commit
66068c8
·
verified ·
1 Parent(s): 6e97a5c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -17
app.py CHANGED
@@ -1,6 +1,6 @@
1
- # app.py
2
- from typing import List, Dict, Tuple, Optional
3
  import gradio as gr
 
 
4
 
5
  from config import (
6
  DEFAULT_MODEL,
@@ -27,9 +27,10 @@ from rag_engine import (
27
  from syllabus_utils import extract_course_topics_from_file
28
 
29
  # ================== Assets (图片路径配置) ==================
 
30
  HANBRIDGE_LOGO_PATH = "hanbridge_logo.png"
31
- CLARE_LOGO_PATH = "clare_mascot.png"
32
- CLARE_RUN_PATH = "Clare_Run.png" # 已取消注释
33
 
34
  # ================== CSS (样式调整) ==================
35
  CUSTOM_CSS = """
@@ -58,7 +59,7 @@ CUSTOM_CSS = """
58
  padding: 12px;
59
  border-radius: 8px;
60
  background-color: #f9fafb;
61
- height: 100%; /* 填满高度 */
62
  }
63
  """
64
 
@@ -81,7 +82,8 @@ def get_user_guide_section(section_key: str) -> str:
81
 
82
  # ================== Gradio App ==================
83
 
84
- with gr.Blocks(title="Clare – Hanbridge AI Teaching Assistant", css=CUSTOM_CSS) as demo:
 
85
 
86
  # 状态变量
87
  course_outline_state = gr.State(DEFAULT_COURSE_TOPICS)
@@ -90,7 +92,6 @@ with gr.Blocks(title="Clare – Hanbridge AI Teaching Assistant", css=CUSTOM_CSS
90
  rag_chunks_state = gr.State([])
91
 
92
  # ============ 1. 顶部 Header (全宽布局) ============
93
- # 包含 CLARE_LOGO_PATH (左) 和 HANBRIDGE_LOGO_PATH (右)
94
  gr.HTML(
95
  f"""
96
  <div class="header-container">
@@ -122,7 +123,6 @@ with gr.Blocks(title="Clare – Hanbridge AI Teaching Assistant", css=CUSTOM_CSS
122
 
123
  # ============ [左侧] 控制面板 Sidebar ============
124
  with gr.Column(scale=1, min_width=200):
125
- # Reset 按钮
126
  clear_btn = gr.Button("Reset Conversation", variant="stop")
127
 
128
  gr.Markdown("### Model Settings")
@@ -196,10 +196,8 @@ with gr.Blocks(title="Clare – Hanbridge AI Teaching Assistant", css=CUSTOM_CSS
196
  </div>
197
  """
198
  )
199
- # 真实的 Review 按钮放在 HTML 下方
200
  review_btn = gr.Button("Review Now", size="sm", variant="primary")
201
-
202
- # 隐藏的 Session Status 用于逻辑传递
203
  session_status = gr.Markdown(visible=False)
204
 
205
  # --- Chat Interface ---
@@ -231,7 +229,6 @@ with gr.Blocks(title="Clare – Hanbridge AI Teaching Assistant", css=CUSTOM_CSS
231
  # ============ [右侧] 功能栏 Right Sidebar ============
232
  with gr.Column(scale=1, min_width=180):
233
  gr.Markdown("### Actions")
234
-
235
  export_btn = gr.Button("Export Conversation", size="sm")
236
  quiz_btn = gr.Button("Let's Try (Micro-Quiz)", size="sm")
237
  summary_btn = gr.Button("Summarization", size="sm")
@@ -246,7 +243,6 @@ with gr.Blocks(title="Clare – Hanbridge AI Teaching Assistant", css=CUSTOM_CSS
246
 
247
  # ================== Logic Bindings ==================
248
 
249
- # 1. File Upload Logic
250
  def update_course_and_rag(file, doc_type_val):
251
  topics = extract_course_topics_from_file(file, doc_type_val)
252
  rag_chunks = build_rag_chunks_from_file(file, doc_type_val)
@@ -259,7 +255,6 @@ with gr.Blocks(title="Clare – Hanbridge AI Teaching Assistant", css=CUSTOM_CSS
259
  outputs=[course_outline_state, rag_chunks_state, session_status],
260
  )
261
 
262
- # 2. Chat Logic
263
  def respond(message, chat_history, course_outline, weaknesses, cognitive_state, rag_chunks, model, lang, mode, doc_type_val):
264
  resolved_lang = detect_language(message or "", lang)
265
 
@@ -292,7 +287,6 @@ with gr.Blocks(title="Clare – Hanbridge AI Teaching Assistant", css=CUSTOM_CSS
292
  [user_input, chatbot, weakness_state, cognitive_state_state, session_status]
293
  )
294
 
295
- # 3. Action Buttons Logic
296
  def on_export(chat_history, course_outline, mode, weaknesses, cognitive_state):
297
  return export_conversation(chat_history, course_outline, mode, weaknesses, cognitive_state)
298
 
@@ -320,7 +314,6 @@ with gr.Blocks(title="Clare – Hanbridge AI Teaching Assistant", css=CUSTOM_CSS
320
  [result_display]
321
  )
322
 
323
- # 4. Reset Logic
324
  def clear_all():
325
  empty_state = {"confusion": 0, "mastery": 0}
326
  default_status = render_session_status("Concept Explainer", [], empty_state)
@@ -333,7 +326,6 @@ with gr.Blocks(title="Clare – Hanbridge AI Teaching Assistant", css=CUSTOM_CSS
333
  queue=False
334
  )
335
 
336
- # 5. User Guide Logic
337
  def show_guide(section):
338
  return get_user_guide_section(section)
339
 
 
 
 
1
  import gradio as gr
2
+ import os
3
+ from typing import List, Dict, Tuple, Optional
4
 
5
  from config import (
6
  DEFAULT_MODEL,
 
27
  from syllabus_utils import extract_course_topics_from_file
28
 
29
  # ================== Assets (图片路径配置) ==================
30
+ # 确保文件名与你上传到 Hugging Face Space 的文件名完全一致(区分大小写)
31
  HANBRIDGE_LOGO_PATH = "hanbridge_logo.png"
32
+ CLARE_LOGO_PATH = "clare_mascot.png" # 注意看截图里是 clare_mascot.png (小写c)
33
+ CLARE_RUN_PATH = "Clare_Run.png" # 截图里是 Clare_Run.png (大写C)
34
 
35
  # ================== CSS (样式调整) ==================
36
  CUSTOM_CSS = """
 
59
  padding: 12px;
60
  border-radius: 8px;
61
  background-color: #f9fafb;
62
+ height: 100%;
63
  }
64
  """
65
 
 
82
 
83
  # ================== Gradio App ==================
84
 
85
+ # 【关键修改点】:添加 allowed_paths=["."] 以允许读取当前目录下的图片文件
86
+ with gr.Blocks(title="Clare – Hanbridge AI Teaching Assistant", css=CUSTOM_CSS, allowed_paths=["."]) as demo:
87
 
88
  # 状态变量
89
  course_outline_state = gr.State(DEFAULT_COURSE_TOPICS)
 
92
  rag_chunks_state = gr.State([])
93
 
94
  # ============ 1. 顶部 Header (全宽布局) ============
 
95
  gr.HTML(
96
  f"""
97
  <div class="header-container">
 
123
 
124
  # ============ [左侧] 控制面板 Sidebar ============
125
  with gr.Column(scale=1, min_width=200):
 
126
  clear_btn = gr.Button("Reset Conversation", variant="stop")
127
 
128
  gr.Markdown("### Model Settings")
 
196
  </div>
197
  """
198
  )
199
+ # Review 按钮放在 HTML 下方
200
  review_btn = gr.Button("Review Now", size="sm", variant="primary")
 
 
201
  session_status = gr.Markdown(visible=False)
202
 
203
  # --- Chat Interface ---
 
229
  # ============ [右侧] 功能栏 Right Sidebar ============
230
  with gr.Column(scale=1, min_width=180):
231
  gr.Markdown("### Actions")
 
232
  export_btn = gr.Button("Export Conversation", size="sm")
233
  quiz_btn = gr.Button("Let's Try (Micro-Quiz)", size="sm")
234
  summary_btn = gr.Button("Summarization", size="sm")
 
243
 
244
  # ================== Logic Bindings ==================
245
 
 
246
  def update_course_and_rag(file, doc_type_val):
247
  topics = extract_course_topics_from_file(file, doc_type_val)
248
  rag_chunks = build_rag_chunks_from_file(file, doc_type_val)
 
255
  outputs=[course_outline_state, rag_chunks_state, session_status],
256
  )
257
 
 
258
  def respond(message, chat_history, course_outline, weaknesses, cognitive_state, rag_chunks, model, lang, mode, doc_type_val):
259
  resolved_lang = detect_language(message or "", lang)
260
 
 
287
  [user_input, chatbot, weakness_state, cognitive_state_state, session_status]
288
  )
289
 
 
290
  def on_export(chat_history, course_outline, mode, weaknesses, cognitive_state):
291
  return export_conversation(chat_history, course_outline, mode, weaknesses, cognitive_state)
292
 
 
314
  [result_display]
315
  )
316
 
 
317
  def clear_all():
318
  empty_state = {"confusion": 0, "mastery": 0}
319
  default_status = render_session_status("Concept Explainer", [], empty_state)
 
326
  queue=False
327
  )
328
 
 
329
  def show_guide(section):
330
  return get_user_guide_section(section)
331