Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -226,7 +226,13 @@ def export_chat(history):
|
|
226 |
def import_chat(file):
|
227 |
"""Import chat history from a JSONL file."""
|
228 |
try:
|
229 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
230 |
lines = [line.strip() for line in content.split("\n") if line.strip()]
|
231 |
|
232 |
messages = [json.loads(line) for line in lines]
|
|
|
226 |
def import_chat(file):
|
227 |
"""Import chat history from a JSONL file."""
|
228 |
try:
|
229 |
+
# Handle both file-like objects and NamedString objects
|
230 |
+
if hasattr(file, 'name'): # It's a NamedString from gr.UploadButton
|
231 |
+
with open(file.name, 'r', encoding='utf-8') as f:
|
232 |
+
content = f.read()
|
233 |
+
else: # It's a file-like object
|
234 |
+
content = file.read()
|
235 |
+
|
236 |
lines = [line.strip() for line in content.split("\n") if line.strip()]
|
237 |
|
238 |
messages = [json.loads(line) for line in lines]
|