Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -10,6 +10,7 @@ import time
|
|
10 |
from zipfile import ZipFile
|
11 |
import gradio as gr
|
12 |
from docx import Document
|
|
|
13 |
|
14 |
# FUNCTIONS
|
15 |
|
@@ -74,10 +75,22 @@ def get_seo_tags(image_path, topical_map, attempts=0):
|
|
74 |
topic_list = [topic.strip() for topic in topic_list]
|
75 |
topic_list.insert(0, "irrelevant")
|
76 |
|
77 |
-
# base64 upload of the image to OpenAI
|
78 |
def encode_image(image_path):
|
79 |
-
|
80 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
|
82 |
print(image_path)
|
83 |
base64_image = encode_image(image_path)
|
|
|
10 |
from zipfile import ZipFile
|
11 |
import gradio as gr
|
12 |
from docx import Document
|
13 |
+
from io import BytesIO
|
14 |
|
15 |
# FUNCTIONS
|
16 |
|
|
|
75 |
topic_list = [topic.strip() for topic in topic_list]
|
76 |
topic_list.insert(0, "irrelevant")
|
77 |
|
|
|
78 |
def encode_image(image_path):
|
79 |
+
# Check the file extension to determine if it is a HEIC file
|
80 |
+
if image_path.lower().endswith('.heic'):
|
81 |
+
# Load the HEIC image
|
82 |
+
image = Image.open(image_path)
|
83 |
+
# Convert the image to JPEG format in memory
|
84 |
+
with BytesIO() as img_buffer:
|
85 |
+
image.save(img_buffer, format='JPEG')
|
86 |
+
# Seek to the beginning of the stream
|
87 |
+
img_buffer.seek(0)
|
88 |
+
# Read the JPEG image data and encode it in base64
|
89 |
+
return base64.b64encode(img_buffer.read()).decode('utf-8')
|
90 |
+
else:
|
91 |
+
# Handle other image types directly
|
92 |
+
with open(image_path, "rb") as image_file:
|
93 |
+
return base64.b64encode(image_file.read()).decode('utf-8')
|
94 |
|
95 |
print(image_path)
|
96 |
base64_image = encode_image(image_path)
|