Phoenix21 commited on
Commit
3d23e89
·
verified ·
1 Parent(s): 9d38450

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -9
app.py CHANGED
@@ -10,34 +10,40 @@ def chat_interface_fn(message, history, session_id):
10
  # Ensure history is a list of dictionaries
11
  if history and isinstance(history[0], tuple):
12
  print("DEBUG: Converting history from tuple format to dictionary format.")
13
- history = [{"role": "user", "content": h[0]}, {"role": "assistant", "content": h[1]} for h in history]
14
-
 
 
 
 
 
 
15
  # 1) Get answer from the session-based memory pipeline
16
  answer = run_with_session_memory(message, session_id)
17
-
18
  # 2) Deduplicate consecutive identical exchanges
19
  if not history or history[-1]["content"] != answer:
20
  history.append({"role": "user", "content": message})
21
  history.append({"role": "assistant", "content": answer})
22
-
23
  # 3) Convert history to message dictionaries for display
24
  message_dicts = []
25
  for msg in history:
26
  message_dicts.append(msg)
27
-
28
  # Return the message dicts and updated history
29
  return message_dicts, history
30
 
31
  # Custom CSS for chat interface
32
  my_chat_css = """
33
  .gradio-container {
34
- margin: auto;
35
  }
36
  .user .wrap {
37
- text-align: right !important;
38
  }
39
  .assistant .wrap {
40
- text-align: left !important;
41
  }
42
  """
43
 
@@ -53,4 +59,4 @@ with gr.Blocks(css=my_chat_css) as demo:
53
  )
54
 
55
  # Launch the Gradio interface
56
- demo.launch()
 
10
  # Ensure history is a list of dictionaries
11
  if history and isinstance(history[0], tuple):
12
  print("DEBUG: Converting history from tuple format to dictionary format.")
13
+ history = [
14
+ msg for h in history
15
+ for msg in [
16
+ {"role": "user", "content": h[0]},
17
+ {"role": "assistant", "content": h[1]}
18
+ ]
19
+ ]
20
+
21
  # 1) Get answer from the session-based memory pipeline
22
  answer = run_with_session_memory(message, session_id)
23
+
24
  # 2) Deduplicate consecutive identical exchanges
25
  if not history or history[-1]["content"] != answer:
26
  history.append({"role": "user", "content": message})
27
  history.append({"role": "assistant", "content": answer})
28
+
29
  # 3) Convert history to message dictionaries for display
30
  message_dicts = []
31
  for msg in history:
32
  message_dicts.append(msg)
33
+
34
  # Return the message dicts and updated history
35
  return message_dicts, history
36
 
37
  # Custom CSS for chat interface
38
  my_chat_css = """
39
  .gradio-container {
40
+ margin: auto;
41
  }
42
  .user .wrap {
43
+ text-align: right !important;
44
  }
45
  .assistant .wrap {
46
+ text-align: left !important;
47
  }
48
  """
49
 
 
59
  )
60
 
61
  # Launch the Gradio interface
62
+ demo.launch()