Spaces:
Runtime error
Runtime error
Update bf_trigger.py
Browse files- bf_trigger.py +31 -3
bf_trigger.py
CHANGED
@@ -302,8 +302,32 @@ def get_seo_tags(image_url, topical_map, new_imgs, attempts=0, max_attempts=5):
|
|
302 |
print("Exception during API call:", str(e))
|
303 |
return get_seo_tags(image_url, topical_map, new_imgs, attempts=attempts + 1)
|
304 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
305 |
# creates the asset in the client's brand folder
|
306 |
-
def create_ai_asset(asset_dict, topical_map, collection_name, new_imgs, tags=True):
|
307 |
'''
|
308 |
Creates asset from image path. Also creates seo tags, topic, and alt tag for
|
309 |
image
|
@@ -346,6 +370,10 @@ def create_ai_asset(asset_dict, topical_map, collection_name, new_imgs, tags=Tru
|
|
346 |
alt_tag = json_dict['alt_tag']
|
347 |
image_name = json_dict['filename']
|
348 |
|
|
|
|
|
|
|
|
|
349 |
headers = {
|
350 |
'Content-Type': 'application/json',
|
351 |
'Authorization': brandfolder_api
|
@@ -593,7 +621,7 @@ def delete_og_asset(asset_id):
|
|
593 |
|
594 |
return
|
595 |
|
596 |
-
def run_preprocess_ai(topical_map, client_name, section_type, progress=gr.Progress()):
|
597 |
section_id = section_key_dict[section_type]
|
598 |
headers = {
|
599 |
'Content-Type': 'application/json',
|
@@ -622,7 +650,7 @@ def run_preprocess_ai(topical_map, client_name, section_type, progress=gr.Progre
|
|
622 |
try:
|
623 |
time.sleep(2)
|
624 |
asset_dict = get_asset_info(asset_id)
|
625 |
-
new_img = create_ai_asset(asset_dict, topical_map, client_name, new_imgs)
|
626 |
new_imgs.append(new_img)
|
627 |
if new_img:
|
628 |
delete_og_asset(asset_id)
|
|
|
302 |
print("Exception during API call:", str(e))
|
303 |
return get_seo_tags(image_url, topical_map, new_imgs, attempts=attempts + 1)
|
304 |
|
305 |
+
def personalize_answer(answer, query_engine):
|
306 |
+
if query_engine:
|
307 |
+
prompt = f'''
|
308 |
+
% You are an expert construction contracter describing this image
|
309 |
+
|
310 |
+
% Goal: Add relevant company information to the Answer based on the context provided. Only output the Enhancement. Remove the triple quotes from the output
|
311 |
+
|
312 |
+
% Answer:
|
313 |
+
```{answer}```
|
314 |
+
|
315 |
+
% Instructions:
|
316 |
+
Step 1 - Identify what relevant company information from the context is relevant to the Answer
|
317 |
+
Step 2 - Enhance the Answer with the relevant company information. This will be known as the Enhancement
|
318 |
+
Step 3 - Make the Enhancement the same character length as the Answer. Use Python to check that they are the same character length.
|
319 |
+
Step 4 - Only output the Enhancement. Remove the triple quotes from the output
|
320 |
+
|
321 |
+
'''
|
322 |
+
|
323 |
+
response = query_engine.query(prompt)
|
324 |
+
|
325 |
+
return response.response.replace("`", "")
|
326 |
+
else:
|
327 |
+
return answer
|
328 |
+
|
329 |
# creates the asset in the client's brand folder
|
330 |
+
def create_ai_asset(asset_dict, topical_map, collection_name, new_imgs, query_engine, tags=True):
|
331 |
'''
|
332 |
Creates asset from image path. Also creates seo tags, topic, and alt tag for
|
333 |
image
|
|
|
370 |
alt_tag = json_dict['alt_tag']
|
371 |
image_name = json_dict['filename']
|
372 |
|
373 |
+
description = personalize_answer(description, query_engine)
|
374 |
+
caption = personalize_answer(caption, query_engine)
|
375 |
+
alt_tag = personalize_answer(alt_tag, query_engine)
|
376 |
+
|
377 |
headers = {
|
378 |
'Content-Type': 'application/json',
|
379 |
'Authorization': brandfolder_api
|
|
|
621 |
|
622 |
return
|
623 |
|
624 |
+
def run_preprocess_ai(topical_map, client_name, section_type, query_engine=query_engine, progress=gr.Progress()):
|
625 |
section_id = section_key_dict[section_type]
|
626 |
headers = {
|
627 |
'Content-Type': 'application/json',
|
|
|
650 |
try:
|
651 |
time.sleep(2)
|
652 |
asset_dict = get_asset_info(asset_id)
|
653 |
+
new_img = create_ai_asset(asset_dict, topical_map, client_name, new_imgs, query_engine=query_engine[-1])
|
654 |
new_imgs.append(new_img)
|
655 |
if new_img:
|
656 |
delete_og_asset(asset_id)
|