Update app.py
Browse files
app.py
CHANGED
@@ -1552,6 +1552,7 @@ def save_image(image, filename):
|
|
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)
|
@@ -1587,16 +1588,12 @@ def process_image(image_input):
|
|
1587 |
with open(filename_md, "w", encoding="utf-8") as f:
|
1588 |
f.write(image_response)
|
1589 |
|
1590 |
-
# Save copy of image with original filename
|
1591 |
-
#filename_img = image_input.name
|
1592 |
-
#save_image(image_input, filename_img)
|
1593 |
-
|
1594 |
# Extract boldface terms from image_response then autoname save file
|
1595 |
boldface_terms = extract_boldface_terms(image_response)
|
1596 |
filename_stem, extension = os.path.splitext(image_input.name)
|
1597 |
filename_img = f"{filename_stem}_{' '.join(boldface_terms)}{extension}"
|
1598 |
-
save_image(image_input, filename_img)
|
1599 |
-
filename_md =
|
1600 |
create_file(filename_md, '', image_response, True)
|
1601 |
|
1602 |
return image_response
|
|
|
1552 |
filename = f"{truncated_stem}{extension}"
|
1553 |
with open(filename, "wb") as f:
|
1554 |
f.write(image.getbuffer())
|
1555 |
+
return filename
|
1556 |
|
1557 |
def extract_boldface_terms(text):
|
1558 |
return re.findall(r'\*\*(.*?)\*\*', text)
|
|
|
1588 |
with open(filename_md, "w", encoding="utf-8") as f:
|
1589 |
f.write(image_response)
|
1590 |
|
|
|
|
|
|
|
|
|
1591 |
# Extract boldface terms from image_response then autoname save file
|
1592 |
boldface_terms = extract_boldface_terms(image_response)
|
1593 |
filename_stem, extension = os.path.splitext(image_input.name)
|
1594 |
filename_img = f"{filename_stem}_{' '.join(boldface_terms)}{extension}"
|
1595 |
+
newfilename = save_image(image_input, filename_img)
|
1596 |
+
filename_md = newfilename.replace('.png', '.md')
|
1597 |
create_file(filename_md, '', image_response, True)
|
1598 |
|
1599 |
return image_response
|