Update app.py
Browse files
app.py
CHANGED
@@ -1491,11 +1491,17 @@ def process_text(text_input):
|
|
1491 |
|
1492 |
|
1493 |
|
1494 |
-
|
1495 |
-
|
|
|
|
|
|
|
|
|
1496 |
with open(filename, "wb") as f:
|
1497 |
-
f.write(
|
1498 |
-
|
|
|
|
|
1499 |
|
1500 |
def process_image(image_input):
|
1501 |
if image_input:
|
@@ -1529,8 +1535,16 @@ def process_image(image_input):
|
|
1529 |
f.write(image_response)
|
1530 |
|
1531 |
# Save copy of image with original filename
|
1532 |
-
filename_img = image_input.name
|
|
|
|
|
|
|
|
|
|
|
|
|
1533 |
save_image(image_input, filename_img)
|
|
|
|
|
1534 |
|
1535 |
return image_response
|
1536 |
|
@@ -1746,4 +1760,4 @@ if prompt := st.chat_input("GPT-4o Multimodal ChatBot - What can I help you with
|
|
1746 |
st.session_state.messages.append({"role": "assistant", "content": response})
|
1747 |
|
1748 |
if __name__ == "__main__":
|
1749 |
-
main()
|
|
|
1491 |
|
1492 |
|
1493 |
|
1494 |
+
|
1495 |
+
def create_file(filename, prompt, response, is_image=False):
|
1496 |
+
with open(filename, "w", encoding="utf-8") as f:
|
1497 |
+
f.write(prompt + "\n\n" + response)
|
1498 |
+
|
1499 |
+
def save_image(image, filename):
|
1500 |
with open(filename, "wb") as f:
|
1501 |
+
f.write(image.getbuffer())
|
1502 |
+
|
1503 |
+
def extract_boldface_terms(text):
|
1504 |
+
return re.findall(r'\*\*(.*?)\*\*', text)
|
1505 |
|
1506 |
def process_image(image_input):
|
1507 |
if image_input:
|
|
|
1535 |
f.write(image_response)
|
1536 |
|
1537 |
# Save copy of image with original filename
|
1538 |
+
#filename_img = image_input.name
|
1539 |
+
#save_image(image_input, filename_img)
|
1540 |
+
|
1541 |
+
# Extract boldface terms from image_response then autoname save file
|
1542 |
+
boldface_terms = extract_boldface_terms(image_response)
|
1543 |
+
filename_stem, extension = os.path.splitext(image_input.name)
|
1544 |
+
filename_img = f"{filename_stem}_{' '.join(boldface_terms)}{extension}"
|
1545 |
save_image(image_input, filename_img)
|
1546 |
+
filename_md = f"{filename_stem}_{'_'.join(boldface_terms)}.md"
|
1547 |
+
create_file(filename_md, '', image_response, True)
|
1548 |
|
1549 |
return image_response
|
1550 |
|
|
|
1760 |
st.session_state.messages.append({"role": "assistant", "content": response})
|
1761 |
|
1762 |
if __name__ == "__main__":
|
1763 |
+
main()
|