Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -134,6 +134,7 @@ def get_seo_tags(image_path, topical_map, attempts=0):
|
|
134 |
Using the description, create a 160 character caption. Make sure the caption is less than 160 characters.
|
135 |
Using the description, create 3 topic-relevant SEO tags for this image that will drive traffic to our website. The SEO tags must be two words or less. You must give 3 SEO tags.
|
136 |
Using the description, provide a topic-relevant SEO alt tag for the image that will enhance how the website is ranked on search engines.
|
|
|
137 |
Ignore all personal information within the image.
|
138 |
Be as specific as possible when identifying tools in the image.
|
139 |
|
@@ -144,6 +145,7 @@ def get_seo_tags(image_path, topical_map, attempts=0):
|
|
144 |
"caption": caption,
|
145 |
"seo": [seo],
|
146 |
"alt_tag": [alt tag],
|
|
|
147 |
}
|
148 |
"""
|
149 |
},
|
@@ -172,7 +174,7 @@ def get_seo_tags(image_path, topical_map, attempts=0):
|
|
172 |
# generates dictionary based on response
|
173 |
json_dict = ast.literal_eval(response.json()['choices'][0]['message']['content'])
|
174 |
|
175 |
-
keys = ['topic', 'description', 'caption', 'seo', 'alt_tag']
|
176 |
json_keys = []
|
177 |
json_keys = list(json_dict.keys())
|
178 |
|
@@ -266,7 +268,7 @@ def upload_image(image_path, upload_url):
|
|
266 |
return response
|
267 |
|
268 |
# creates the asset in the client's brand folder
|
269 |
-
def create_asset(client_name, collection_id, image_path, topical_map, tags=True, project_bool=False):
|
270 |
'''
|
271 |
Creates asset from image path. Also creates seo tags, topic, and alt tag for
|
272 |
image
|
@@ -283,7 +285,13 @@ def create_asset(client_name, collection_id, image_path, topical_map, tags=True,
|
|
283 |
caption = json_dict['caption']
|
284 |
seo_tags = json_dict['seo']
|
285 |
alt_tag = json_dict['alt_tag']
|
286 |
-
image_name =
|
|
|
|
|
|
|
|
|
|
|
|
|
287 |
|
288 |
headers = {
|
289 |
'Accept': 'application/json',
|
@@ -314,7 +322,7 @@ def create_asset(client_name, collection_id, image_path, topical_map, tags=True,
|
|
314 |
|
315 |
with NamedTemporaryFile(delete=True, suffix='.jpg') as temp_image:
|
316 |
# fp = TemporaryFile()
|
317 |
-
cv2.imwrite(temp_image.name, image)
|
318 |
# fp.seek(0)
|
319 |
response = requests.put(upload_url, data=temp_image)
|
320 |
# fp.close()
|
@@ -588,6 +596,7 @@ def import_client_data(client_name, zipfile, topical_map, password, project_bool
|
|
588 |
# gets all image files from the google drive folder
|
589 |
zip = ZipFile(zipfile.name)
|
590 |
img_list = get_imgs_from_folder([], zipfile)
|
|
|
591 |
print(img_list)
|
592 |
|
593 |
# iterates all images and puts them into brandfolder with AI elements
|
@@ -596,7 +605,8 @@ def import_client_data(client_name, zipfile, topical_map, password, project_bool
|
|
596 |
time.sleep(5)
|
597 |
img = zip.extract(img)
|
598 |
print(client_name)
|
599 |
-
create_asset(client_name, collection_id, img, topical_map, project_bool=project_bool)
|
|
|
600 |
gr.Info('Images have been uploaded!')
|
601 |
return "Images Uploaded"
|
602 |
|
|
|
134 |
Using the description, create a 160 character caption. Make sure the caption is less than 160 characters.
|
135 |
Using the description, create 3 topic-relevant SEO tags for this image that will drive traffic to our website. The SEO tags must be two words or less. You must give 3 SEO tags.
|
136 |
Using the description, provide a topic-relevant SEO alt tag for the image that will enhance how the website is ranked on search engines.
|
137 |
+
Using the description, provide a new file name for the image as well. Use hyphens for the filename. Do not include extension.
|
138 |
Ignore all personal information within the image.
|
139 |
Be as specific as possible when identifying tools in the image.
|
140 |
|
|
|
145 |
"caption": caption,
|
146 |
"seo": [seo],
|
147 |
"alt_tag": [alt tag],
|
148 |
+
"filename": filename
|
149 |
}
|
150 |
"""
|
151 |
},
|
|
|
174 |
# generates dictionary based on response
|
175 |
json_dict = ast.literal_eval(response.json()['choices'][0]['message']['content'])
|
176 |
|
177 |
+
keys = ['topic', 'description', 'caption', 'seo', 'alt_tag', 'filename']
|
178 |
json_keys = []
|
179 |
json_keys = list(json_dict.keys())
|
180 |
|
|
|
268 |
return response
|
269 |
|
270 |
# creates the asset in the client's brand folder
|
271 |
+
def create_asset(client_name, collection_id, image_path, topical_map, new_imgs, tags=True, project_bool=False):
|
272 |
'''
|
273 |
Creates asset from image path. Also creates seo tags, topic, and alt tag for
|
274 |
image
|
|
|
285 |
caption = json_dict['caption']
|
286 |
seo_tags = json_dict['seo']
|
287 |
alt_tag = json_dict['alt_tag']
|
288 |
+
image_name = json_dict['filename']
|
289 |
+
|
290 |
+
counter = 1
|
291 |
+
while image_name in new_imgs:
|
292 |
+
image_name = f'{image_name}_{counter}'
|
293 |
+
counter += 1
|
294 |
+
|
295 |
|
296 |
headers = {
|
297 |
'Accept': 'application/json',
|
|
|
322 |
|
323 |
with NamedTemporaryFile(delete=True, suffix='.jpg') as temp_image:
|
324 |
# fp = TemporaryFile()
|
325 |
+
cv2.imwrite(temp_image.name, image, [int(cv2.IMWRITE_JPEG_QUALITY), 95])
|
326 |
# fp.seek(0)
|
327 |
response = requests.put(upload_url, data=temp_image)
|
328 |
# fp.close()
|
|
|
596 |
# gets all image files from the google drive folder
|
597 |
zip = ZipFile(zipfile.name)
|
598 |
img_list = get_imgs_from_folder([], zipfile)
|
599 |
+
new_imgs = []
|
600 |
print(img_list)
|
601 |
|
602 |
# iterates all images and puts them into brandfolder with AI elements
|
|
|
605 |
time.sleep(5)
|
606 |
img = zip.extract(img)
|
607 |
print(client_name)
|
608 |
+
new_img = create_asset(client_name, collection_id, img, topical_map, new_imgs, project_bool=project_bool)
|
609 |
+
new_imgs.append(new_img)
|
610 |
gr.Info('Images have been uploaded!')
|
611 |
return "Images Uploaded"
|
612 |
|