Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -11,7 +11,7 @@ class XylariaChat:
|
|
11 |
|
12 |
# Initialize the inference client
|
13 |
self.client = InferenceClient(
|
14 |
-
model="Qwen/
|
15 |
token=self.hf_token
|
16 |
)
|
17 |
|
@@ -56,6 +56,7 @@ Capabilities:
|
|
56 |
"""
|
57 |
self.conversation_history = []
|
58 |
self.persistent_memory = {}
|
|
|
59 |
|
60 |
def get_response(self, user_input):
|
61 |
# Prepare messages with conversation context and persistent memory
|
@@ -105,20 +106,20 @@ Capabilities:
|
|
105 |
def create_interface(self):
|
106 |
# Local storage JavaScript functions (these are strings, not functions)
|
107 |
load_from_local_storage_js = """
|
108 |
-
|
109 |
const savedHistory = localStorage.getItem('xylaria_chat_history');
|
110 |
return savedHistory ? JSON.parse(savedHistory) : [];
|
111 |
}
|
112 |
"""
|
113 |
|
114 |
save_to_local_storage_js = """
|
115 |
-
|
116 |
localStorage.setItem('xylaria_chat_history', JSON.stringify(chatHistory));
|
117 |
}
|
118 |
"""
|
119 |
|
120 |
clear_local_storage_js = """
|
121 |
-
|
122 |
localStorage.removeItem('xylaria_chat_history');
|
123 |
}
|
124 |
"""
|
@@ -183,7 +184,7 @@ Capabilities:
|
|
183 |
label="Xylaria 1.4 Senoa",
|
184 |
height=500,
|
185 |
show_copy_button=True,
|
186 |
-
type="messages" # Use the 'messages' format
|
187 |
)
|
188 |
|
189 |
# Input row with improved layout
|
@@ -207,7 +208,7 @@ Capabilities:
|
|
207 |
fn=lambda: initial_chat_history.value,
|
208 |
inputs=None,
|
209 |
outputs=[chatbot],
|
210 |
-
|
211 |
)
|
212 |
|
213 |
# Submit functionality with local storage save
|
@@ -219,7 +220,7 @@ Capabilities:
|
|
219 |
fn=None,
|
220 |
inputs=[chatbot], # Pass chatbot history to JavaScript
|
221 |
outputs=None,
|
222 |
-
|
223 |
)
|
224 |
txt.submit(
|
225 |
fn=streaming_response,
|
@@ -229,7 +230,7 @@ Capabilities:
|
|
229 |
fn=None,
|
230 |
inputs=[chatbot], # Pass chatbot history to JavaScript
|
231 |
outputs=None,
|
232 |
-
|
233 |
)
|
234 |
|
235 |
# Clear conversation history with local storage clear
|
@@ -239,7 +240,9 @@ Capabilities:
|
|
239 |
outputs=[chatbot]
|
240 |
).then(
|
241 |
fn=None,
|
242 |
-
|
|
|
|
|
243 |
)
|
244 |
|
245 |
# Clear persistent memory and reset conversation with local storage clear
|
@@ -249,7 +252,9 @@ Capabilities:
|
|
249 |
outputs=[chatbot]
|
250 |
).then(
|
251 |
fn=None,
|
252 |
-
|
|
|
|
|
253 |
)
|
254 |
|
255 |
return demo
|
|
|
11 |
|
12 |
# Initialize the inference client
|
13 |
self.client = InferenceClient(
|
14 |
+
model="Qwen/QwQ-32B-Preview", # Changed model name
|
15 |
token=self.hf_token
|
16 |
)
|
17 |
|
|
|
56 |
"""
|
57 |
self.conversation_history = []
|
58 |
self.persistent_memory = {}
|
59 |
+
return []
|
60 |
|
61 |
def get_response(self, user_input):
|
62 |
# Prepare messages with conversation context and persistent memory
|
|
|
106 |
def create_interface(self):
|
107 |
# Local storage JavaScript functions (these are strings, not functions)
|
108 |
load_from_local_storage_js = """
|
109 |
+
async () => {
|
110 |
const savedHistory = localStorage.getItem('xylaria_chat_history');
|
111 |
return savedHistory ? JSON.parse(savedHistory) : [];
|
112 |
}
|
113 |
"""
|
114 |
|
115 |
save_to_local_storage_js = """
|
116 |
+
async (chatHistory) => {
|
117 |
localStorage.setItem('xylaria_chat_history', JSON.stringify(chatHistory));
|
118 |
}
|
119 |
"""
|
120 |
|
121 |
clear_local_storage_js = """
|
122 |
+
async () => {
|
123 |
localStorage.removeItem('xylaria_chat_history');
|
124 |
}
|
125 |
"""
|
|
|
184 |
label="Xylaria 1.4 Senoa",
|
185 |
height=500,
|
186 |
show_copy_button=True,
|
187 |
+
# type="messages" # Use the 'messages' format
|
188 |
)
|
189 |
|
190 |
# Input row with improved layout
|
|
|
208 |
fn=lambda: initial_chat_history.value,
|
209 |
inputs=None,
|
210 |
outputs=[chatbot],
|
211 |
+
js=load_from_local_storage_js
|
212 |
)
|
213 |
|
214 |
# Submit functionality with local storage save
|
|
|
220 |
fn=None,
|
221 |
inputs=[chatbot], # Pass chatbot history to JavaScript
|
222 |
outputs=None,
|
223 |
+
js=save_to_local_storage_js
|
224 |
)
|
225 |
txt.submit(
|
226 |
fn=streaming_response,
|
|
|
230 |
fn=None,
|
231 |
inputs=[chatbot], # Pass chatbot history to JavaScript
|
232 |
outputs=None,
|
233 |
+
js=save_to_local_storage_js
|
234 |
)
|
235 |
|
236 |
# Clear conversation history with local storage clear
|
|
|
240 |
outputs=[chatbot]
|
241 |
).then(
|
242 |
fn=None,
|
243 |
+
inputs=None,
|
244 |
+
outputs=None,
|
245 |
+
js=clear_local_storage_js
|
246 |
)
|
247 |
|
248 |
# Clear persistent memory and reset conversation with local storage clear
|
|
|
252 |
outputs=[chatbot]
|
253 |
).then(
|
254 |
fn=None,
|
255 |
+
inputs=None,
|
256 |
+
outputs=None,
|
257 |
+
js=clear_local_storage_js
|
258 |
)
|
259 |
|
260 |
return demo
|