Update app.py
Browse files
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 |
-
|
|
|
|
|
|
|
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):
|