reedmayhew commited on
Commit
b87f064
·
verified ·
1 Parent(s): d589907

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -1
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
- content = file # Read the file directly as a string
 
 
 
 
 
 
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]