freeCS-dot-org commited on
Commit
f4f5376
·
verified ·
1 Parent(s): 6e8269f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -1
app.py CHANGED
@@ -49,7 +49,6 @@ class ConversationManager:
49
  def get_user_history(self):
50
  return self.user_history
51
 
52
- conversation_manager = ConversationManager()
53
 
54
  device = "cuda" # for GPU usage or "cpu" for CPU usage
55
 
@@ -80,7 +79,12 @@ def stream_chat(
80
  top_p: float = 1.0,
81
  top_k: int = 1,
82
  penalty: float = 1.1,
 
83
  ):
 
 
 
 
84
  print(f'\nNew Chat Request:')
85
  print(f'Message: {message}')
86
  print(f'History from UI: {history}')
@@ -153,6 +157,7 @@ def stream_chat(
153
  yield formatted_buffer
154
 
155
  chatbot = gr.Chatbot(height=600, placeholder=PLACEHOLDER)
 
156
 
157
  with gr.Blocks(css=CSS, theme="soft") as demo:
158
  gr.HTML(TITLE)
@@ -215,6 +220,7 @@ with gr.Blocks(css=CSS, theme="soft") as demo:
215
  label="Repetition penalty",
216
  render=False,
217
  ),
 
218
  ],
219
  examples=[
220
  ["Help me study vocabulary: write a sentence for me to fill in the blank, and I'll try to pick the correct option."],
 
49
  def get_user_history(self):
50
  return self.user_history
51
 
 
52
 
53
  device = "cuda" # for GPU usage or "cpu" for CPU usage
54
 
 
79
  top_p: float = 1.0,
80
  top_k: int = 1,
81
  penalty: float = 1.1,
82
+ conversation_manager: ConversationManager = None # Pass the manager as argument
83
  ):
84
+ # Initialize the conversation manager for the first time only
85
+ if conversation_manager is None:
86
+ conversation_manager = ConversationManager()
87
+
88
  print(f'\nNew Chat Request:')
89
  print(f'Message: {message}')
90
  print(f'History from UI: {history}')
 
157
  yield formatted_buffer
158
 
159
  chatbot = gr.Chatbot(height=600, placeholder=PLACEHOLDER)
160
+ conversation_manager_session_state = gr.State(ConversationManager())
161
 
162
  with gr.Blocks(css=CSS, theme="soft") as demo:
163
  gr.HTML(TITLE)
 
220
  label="Repetition penalty",
221
  render=False,
222
  ),
223
+ conversation_manager_session_state, # Add the state to the input
224
  ],
225
  examples=[
226
  ["Help me study vocabulary: write a sentence for me to fill in the blank, and I'll try to pick the correct option."],