Reality123b commited on
Commit
85e9a91
·
verified ·
1 Parent(s): ba3e6fe

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -32
app.py CHANGED
@@ -124,7 +124,7 @@ Capabilities:
124
 
125
  return "", updated_history
126
 
127
- # Custom CSS for Inter font and local storage script
128
  custom_css = """
129
  @import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');
130
 
@@ -143,29 +143,13 @@ Capabilities:
143
  }
144
  """
145
 
146
- local_storage_js = """
147
- function saveToLocalStorage(chatHistory) {
148
- localStorage.setItem('xylaria_chat_history', JSON.stringify(chatHistory));
149
- }
150
-
151
- function loadFromLocalStorage() {
152
- const savedHistory = localStorage.getItem('xylaria_chat_history');
153
- return savedHistory ? JSON.parse(savedHistory) : [];
154
- }
155
-
156
- function clearLocalStorage() {
157
- localStorage.removeItem('xylaria_chat_history');
158
- }
159
- """
160
-
161
- with gr.Blocks(theme='soft', css=custom_css, js=local_storage_js) as demo:
162
  # Chat interface with improved styling
163
  with gr.Column():
164
  chatbot = gr.Chatbot(
165
  label="Xylaria 1.4 Senoa",
166
  height=500,
167
- show_copy_button=True,
168
- value=gr.CSVDataset(local_storage_fn=lambda: "loadFromLocalStorage()")
169
  )
170
 
171
  # Input row with improved layout
@@ -182,22 +166,16 @@ Capabilities:
182
  clear = gr.Button("Clear Conversation")
183
  clear_memory = gr.Button("Clear Memory")
184
 
185
- # Submit functionality with streaming and local storage save
186
  btn.click(
187
  fn=streaming_response,
188
  inputs=[txt, chatbot],
189
  outputs=[txt, chatbot]
190
- ).then(
191
- fn=None, # JavaScript callback
192
- _js='(chatHistory) => saveToLocalStorage(chatHistory)'
193
  )
194
  txt.submit(
195
  fn=streaming_response,
196
  inputs=[txt, chatbot],
197
  outputs=[txt, chatbot]
198
- ).then(
199
- fn=None, # JavaScript callback
200
- _js='(chatHistory) => saveToLocalStorage(chatHistory)'
201
  )
202
 
203
  # Clear conversation history
@@ -205,9 +183,6 @@ Capabilities:
205
  fn=lambda: [],
206
  inputs=None,
207
  outputs=[chatbot]
208
- ).then(
209
- fn=None, # JavaScript callback
210
- _js='() => clearLocalStorage()'
211
  )
212
 
213
  # Clear persistent memory and reset conversation
@@ -215,9 +190,6 @@ Capabilities:
215
  fn=lambda: [],
216
  inputs=None,
217
  outputs=[chatbot]
218
- ).then(
219
- fn=None, # JavaScript callback
220
- _js='() => clearLocalStorage()'
221
  )
222
 
223
  return demo
 
124
 
125
  return "", updated_history
126
 
127
+ # Custom CSS for Inter font
128
  custom_css = """
129
  @import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');
130
 
 
143
  }
144
  """
145
 
146
+ with gr.Blocks(theme='soft', css=custom_css) as demo:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
147
  # Chat interface with improved styling
148
  with gr.Column():
149
  chatbot = gr.Chatbot(
150
  label="Xylaria 1.4 Senoa",
151
  height=500,
152
+ show_copy_button=True
 
153
  )
154
 
155
  # Input row with improved layout
 
166
  clear = gr.Button("Clear Conversation")
167
  clear_memory = gr.Button("Clear Memory")
168
 
169
+ # Submit functionality
170
  btn.click(
171
  fn=streaming_response,
172
  inputs=[txt, chatbot],
173
  outputs=[txt, chatbot]
 
 
 
174
  )
175
  txt.submit(
176
  fn=streaming_response,
177
  inputs=[txt, chatbot],
178
  outputs=[txt, chatbot]
 
 
 
179
  )
180
 
181
  # Clear conversation history
 
183
  fn=lambda: [],
184
  inputs=None,
185
  outputs=[chatbot]
 
 
 
186
  )
187
 
188
  # Clear persistent memory and reset conversation
 
190
  fn=lambda: [],
191
  inputs=None,
192
  outputs=[chatbot]
 
 
 
193
  )
194
 
195
  return demo