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/Qwen-72B-Chat", # Changed model name
|
| 15 |
token=self.hf_token
|
| 16 |
)
|
| 17 |
|
|
@@ -103,18 +103,22 @@ Capabilities:
|
|
| 103 |
return prompt
|
| 104 |
|
| 105 |
def create_interface(self):
|
| 106 |
-
# Local storage JavaScript functions
|
| 107 |
-
|
| 108 |
-
function
|
| 109 |
-
localStorage.setItem('xylaria_chat_history', JSON.stringify(chatHistory));
|
| 110 |
-
}
|
| 111 |
-
|
| 112 |
-
function loadFromLocalStorage() {
|
| 113 |
const savedHistory = localStorage.getItem('xylaria_chat_history');
|
| 114 |
return savedHistory ? JSON.parse(savedHistory) : [];
|
| 115 |
}
|
|
|
|
| 116 |
|
| 117 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
localStorage.removeItem('xylaria_chat_history');
|
| 119 |
}
|
| 120 |
"""
|
|
@@ -196,8 +200,15 @@ Capabilities:
|
|
| 196 |
clear = gr.Button("Clear Conversation")
|
| 197 |
clear_memory = gr.Button("Clear Memory")
|
| 198 |
|
| 199 |
-
# Load chat history from local storage on page load
|
| 200 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 201 |
|
| 202 |
# Submit functionality with local storage save
|
| 203 |
btn.click(
|
|
@@ -208,7 +219,7 @@ Capabilities:
|
|
| 208 |
fn=None,
|
| 209 |
inputs=[chatbot], # Pass chatbot history to JavaScript
|
| 210 |
outputs=None,
|
| 211 |
-
_js=
|
| 212 |
)
|
| 213 |
txt.submit(
|
| 214 |
fn=streaming_response,
|
|
@@ -218,7 +229,7 @@ Capabilities:
|
|
| 218 |
fn=None,
|
| 219 |
inputs=[chatbot], # Pass chatbot history to JavaScript
|
| 220 |
outputs=None,
|
| 221 |
-
_js=
|
| 222 |
)
|
| 223 |
|
| 224 |
# Clear conversation history with local storage clear
|
|
@@ -228,7 +239,7 @@ Capabilities:
|
|
| 228 |
outputs=[chatbot]
|
| 229 |
).then(
|
| 230 |
fn=None,
|
| 231 |
-
_js=
|
| 232 |
)
|
| 233 |
|
| 234 |
# Clear persistent memory and reset conversation with local storage clear
|
|
@@ -238,7 +249,7 @@ Capabilities:
|
|
| 238 |
outputs=[chatbot]
|
| 239 |
).then(
|
| 240 |
fn=None,
|
| 241 |
-
_js=
|
| 242 |
)
|
| 243 |
|
| 244 |
return demo
|
|
|
|
| 11 |
|
| 12 |
# Initialize the inference client
|
| 13 |
self.client = InferenceClient(
|
| 14 |
+
model="Qwen/Qwen-72B-Chat", # Changed model name
|
| 15 |
token=self.hf_token
|
| 16 |
)
|
| 17 |
|
|
|
|
| 103 |
return prompt
|
| 104 |
|
| 105 |
def create_interface(self):
|
| 106 |
+
# Local storage JavaScript functions (these are strings, not functions)
|
| 107 |
+
load_from_local_storage_js = """
|
| 108 |
+
function() {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
const savedHistory = localStorage.getItem('xylaria_chat_history');
|
| 110 |
return savedHistory ? JSON.parse(savedHistory) : [];
|
| 111 |
}
|
| 112 |
+
"""
|
| 113 |
|
| 114 |
+
save_to_local_storage_js = """
|
| 115 |
+
function(chatHistory) {
|
| 116 |
+
localStorage.setItem('xylaria_chat_history', JSON.stringify(chatHistory));
|
| 117 |
+
}
|
| 118 |
+
"""
|
| 119 |
+
|
| 120 |
+
clear_local_storage_js = """
|
| 121 |
+
function() {
|
| 122 |
localStorage.removeItem('xylaria_chat_history');
|
| 123 |
}
|
| 124 |
"""
|
|
|
|
| 200 |
clear = gr.Button("Clear Conversation")
|
| 201 |
clear_memory = gr.Button("Clear Memory")
|
| 202 |
|
| 203 |
+
# Load chat history from local storage on page load
|
| 204 |
+
demo.load(
|
| 205 |
+
fn=None,
|
| 206 |
+
_js=load_from_local_storage_js # Pass the JS function as a string
|
| 207 |
+
).then(
|
| 208 |
+
fn=lambda x: x,
|
| 209 |
+
inputs=chatbot,
|
| 210 |
+
outputs=chatbot
|
| 211 |
+
)
|
| 212 |
|
| 213 |
# Submit functionality with local storage save
|
| 214 |
btn.click(
|
|
|
|
| 219 |
fn=None,
|
| 220 |
inputs=[chatbot], # Pass chatbot history to JavaScript
|
| 221 |
outputs=None,
|
| 222 |
+
_js=save_to_local_storage_js
|
| 223 |
)
|
| 224 |
txt.submit(
|
| 225 |
fn=streaming_response,
|
|
|
|
| 229 |
fn=None,
|
| 230 |
inputs=[chatbot], # Pass chatbot history to JavaScript
|
| 231 |
outputs=None,
|
| 232 |
+
_js=save_to_local_storage_js
|
| 233 |
)
|
| 234 |
|
| 235 |
# Clear conversation history with local storage clear
|
|
|
|
| 239 |
outputs=[chatbot]
|
| 240 |
).then(
|
| 241 |
fn=None,
|
| 242 |
+
_js=clear_local_storage_js
|
| 243 |
)
|
| 244 |
|
| 245 |
# Clear persistent memory and reset conversation with local storage clear
|
|
|
|
| 249 |
outputs=[chatbot]
|
| 250 |
).then(
|
| 251 |
fn=None,
|
| 252 |
+
_js=clear_local_storage_js
|
| 253 |
)
|
| 254 |
|
| 255 |
return demo
|