Tonic commited on
Commit
e67c4d9
·
1 Parent(s): e535f32

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -1
app.py CHANGED
@@ -102,13 +102,17 @@ def _parse_text(text):
102
  lines[i] = "<br>" + line
103
  text = "".join(lines)
104
  return text
 
105
  def save_image(image_file, uploaded_file_dir):
106
  upload_dir = Path(uploaded_file_dir) / "uploads"
107
  upload_dir.mkdir(parents=True, exist_ok=True)
108
  filename = secrets.token_hex(10) + Path(image_file.name).suffix
109
  file_path = upload_dir / filename
110
  with open(file_path, "wb") as f:
111
- f.write(image_file.read())
 
 
 
112
  return str(file_path)
113
 
114
  def add_file(history, task_history, file):
 
102
  lines[i] = "<br>" + line
103
  text = "".join(lines)
104
  return text
105
+
106
  def save_image(image_file, uploaded_file_dir):
107
  upload_dir = Path(uploaded_file_dir) / "uploads"
108
  upload_dir.mkdir(parents=True, exist_ok=True)
109
  filename = secrets.token_hex(10) + Path(image_file.name).suffix
110
  file_path = upload_dir / filename
111
  with open(file_path, "wb") as f:
112
+ if isinstance(image_file, gr.NamedString):
113
+ f.write(image_file.value.encode())
114
+ else:
115
+ f.write(image_file.read())
116
  return str(file_path)
117
 
118
  def add_file(history, task_history, file):