Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Update app.py
Browse files
app.py
CHANGED
@@ -1540,10 +1540,19 @@ def create_file(filename, prompt, response, is_image=False):
|
|
1540 |
with open(filename, "w", encoding="utf-8") as f:
|
1541 |
f.write(prompt + "\n\n" + response)
|
1542 |
|
1543 |
-
def
|
1544 |
with open(filename, "wb") as f:
|
1545 |
f.write(image.getbuffer())
|
1546 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1547 |
def extract_boldface_terms(text):
|
1548 |
return re.findall(r'\*\*(.*?)\*\*', text)
|
1549 |
|
|
|
1540 |
with open(filename, "w", encoding="utf-8") as f:
|
1541 |
f.write(prompt + "\n\n" + response)
|
1542 |
|
1543 |
+
def save_image_old2(image, filename):
|
1544 |
with open(filename, "wb") as f:
|
1545 |
f.write(image.getbuffer())
|
1546 |
|
1547 |
+
# Now filename length protected for linux and windows filename lengths
|
1548 |
+
def save_image(image, filename):
|
1549 |
+
max_filename_length = min(os.pathconf('/', 'PC_NAME_MAX'), 255, 260) # Linux: 255, Windows: 260 (including path)
|
1550 |
+
filename_stem, extension = os.path.splitext(filename)
|
1551 |
+
truncated_stem = filename_stem[:max_filename_length - len(extension)] if len(filename) > max_filename_length else filename_stem
|
1552 |
+
filename = f"{truncated_stem}{extension}"
|
1553 |
+
with open(filename, "wb") as f:
|
1554 |
+
f.write(image.getbuffer())
|
1555 |
+
|
1556 |
def extract_boldface_terms(text):
|
1557 |
return re.findall(r'\*\*(.*?)\*\*', text)
|
1558 |
|