Dannyar608 commited on
Commit
647dadd
·
verified ·
1 Parent(s): a7c9f79

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -15
app.py CHANGED
@@ -482,7 +482,7 @@ class TeachingAssistant:
482
  self.context_history = []
483
  self.max_context_length = 5 # Keep last 5 exchanges for context
484
 
485
- def generate_response(self, message: str, history: List[Tuple[str, str]]) -> str:
486
  """Generate personalized response based on student profile and context."""
487
  try:
488
  # Load profile (simplified - in real app would handle multiple profiles)
@@ -517,13 +517,15 @@ class TeachingAssistant:
517
  print(f"Error generating response: {str(e)}")
518
  return "I encountered an error processing your request. Please try again."
519
 
520
- def _update_context(self, message: str, history: List[Tuple[str, str]]) -> None:
521
  """Maintain conversation context."""
522
- self.context_history.append(("user", message))
523
  if history:
524
  for h in history[-self.max_context_length:]:
525
- self.context_history.append(("user", h[0]))
526
- self.context_history.append(("assistant", h[1]))
 
 
527
 
528
  # Trim to maintain max context length
529
  self.context_history = self.context_history[-(self.max_context_length*2):]
@@ -765,10 +767,6 @@ def create_interface():
765
  with gr.Column(scale=1):
766
  step5 = gr.Button("5. AI Assistant")
767
 
768
- # Tab navigation logic
769
- def navigate_to_tab(tab_index):
770
- return {tab: gr.update(visible=(i == tab_index)) for i, tab in enumerate(tabs)}
771
-
772
  # Main tabs
773
  with gr.Tabs() as tabs:
774
  # ===== TAB 1: Transcript Upload =====
@@ -949,26 +947,29 @@ def create_interface():
949
  title=""
950
  )
951
 
952
- # Tab navigation buttons
 
 
 
953
  step1.click(
954
  fn=lambda: navigate_to_tab(0),
955
- outputs={tab: tab for tab in tabs}
956
  )
957
  step2.click(
958
  fn=lambda: navigate_to_tab(1),
959
- outputs={tab: tab for tab in tabs}
960
  )
961
  step3.click(
962
  fn=lambda: navigate_to_tab(2),
963
- outputs={tab: tab for tab in tabs}
964
  )
965
  step4.click(
966
  fn=lambda: navigate_to_tab(3),
967
- outputs={tab: tab for tab in tabs}
968
  )
969
  step5.click(
970
  fn=lambda: navigate_to_tab(4),
971
- outputs={tab: tab for tab in tabs}
972
  )
973
 
974
  return app
 
482
  self.context_history = []
483
  self.max_context_length = 5 # Keep last 5 exchanges for context
484
 
485
+ def generate_response(self, message: str, history: List[List[Union[str, None]]]) -> str:
486
  """Generate personalized response based on student profile and context."""
487
  try:
488
  # Load profile (simplified - in real app would handle multiple profiles)
 
517
  print(f"Error generating response: {str(e)}")
518
  return "I encountered an error processing your request. Please try again."
519
 
520
+ def _update_context(self, message: str, history: List[List[Union[str, None]]]) -> None:
521
  """Maintain conversation context."""
522
+ self.context_history.append({"role": "user", "content": message})
523
  if history:
524
  for h in history[-self.max_context_length:]:
525
+ if h[0]: # User message
526
+ self.context_history.append({"role": "user", "content": h[0]})
527
+ if h[1]: # Assistant message
528
+ self.context_history.append({"role": "assistant", "content": h[1]})
529
 
530
  # Trim to maintain max context length
531
  self.context_history = self.context_history[-(self.max_context_length*2):]
 
767
  with gr.Column(scale=1):
768
  step5 = gr.Button("5. AI Assistant")
769
 
 
 
 
 
770
  # Main tabs
771
  with gr.Tabs() as tabs:
772
  # ===== TAB 1: Transcript Upload =====
 
947
  title=""
948
  )
949
 
950
+ # Tab navigation logic
951
+ def navigate_to_tab(tab_index: int):
952
+ return {tabs: gr.update(selected=tab_index)}
953
+
954
  step1.click(
955
  fn=lambda: navigate_to_tab(0),
956
+ outputs={tabs: tabs}
957
  )
958
  step2.click(
959
  fn=lambda: navigate_to_tab(1),
960
+ outputs={tabs: tabs}
961
  )
962
  step3.click(
963
  fn=lambda: navigate_to_tab(2),
964
+ outputs={tabs: tabs}
965
  )
966
  step4.click(
967
  fn=lambda: navigate_to_tab(3),
968
+ outputs={tabs: tabs}
969
  )
970
  step5.click(
971
  fn=lambda: navigate_to_tab(4),
972
+ outputs={tabs: tabs}
973
  )
974
 
975
  return app