Update app.py
Browse files
app.py
CHANGED
|
@@ -197,12 +197,21 @@ class AllSessions():
|
|
| 197 |
def __init__(self):
|
| 198 |
self.sessions = {}
|
| 199 |
|
| 200 |
-
|
| 201 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 202 |
|
| 203 |
def submitPhoto(img, rooms, seshid):
|
| 204 |
print('submitPhoto reset rooms: ', rooms, seshid)
|
| 205 |
seshid = str(time.time()) if not seshid or seshid == 'SESHID' else seshid
|
|
|
|
| 206 |
#sesh.reset = True
|
| 207 |
sesh.current_img_signature = str(img.sum())
|
| 208 |
sesh.img_data[sesh.current_img_signature] = img
|
|
@@ -218,9 +227,11 @@ def submitPhoto(img, rooms, seshid):
|
|
| 218 |
rooms.append((img, sesh.current_img_signature))
|
| 219 |
print('submitPhoto reset: ', sesh.reset)
|
| 220 |
#return [(v,str(k)) for k,v in sesh.img_data.items()], gr.Image(label='Upload Room Photo
|
|
|
|
| 221 |
return rooms, gr.Image(label='Upload Room Photo'), seshid
|
| 222 |
|
| 223 |
def summarisePerStore(seshid):
|
|
|
|
| 224 |
sesh.summary_joined = {}
|
| 225 |
for imgid,product_dicts in sesh.summary.items():
|
| 226 |
for item_pd in product_dicts:
|
|
@@ -235,9 +246,11 @@ def summarisePerStore(seshid):
|
|
| 235 |
sesh.summary_joined[store]['descriptions'].append(pd['description'])
|
| 236 |
sesh.summary_joined[store]['sources'].append(pd['href'])
|
| 237 |
sesh.summary_joined[store]['num_items'] += 1
|
|
|
|
| 238 |
|
| 239 |
|
| 240 |
def summarisePerStore(seshid):
|
|
|
|
| 241 |
sesh.summary_joined = {}
|
| 242 |
for imgid,product_dicts in sesh.summary.items():
|
| 243 |
for item_pd in product_dicts:
|
|
@@ -249,9 +262,12 @@ def summarisePerStore(seshid):
|
|
| 249 |
sesh.summary_joined[store] = {}
|
| 250 |
|
| 251 |
sesh.summary_joined[store][item] = {'product_dict': pd, 'count':1}
|
|
|
|
| 252 |
|
| 253 |
|
| 254 |
def updateItemDisplay(seshid, budget=False):
|
|
|
|
|
|
|
| 255 |
if True:
|
| 256 |
keys = ['filtered_items_room', 'current_img_signature', 'items', 'filtered_items_style', 'room_style', 'room_type', 'bedsize', 'price', 'filtered_items_colors', 'Palette_ids', 'item_data', 'item_data_', 'display_items', 'item_data_keys', 'Palettes_displayed', 'room_img_loaded', 'Paletteid', 'img_id', 'seshid']
|
| 257 |
url = 'https://dreamdemo.pythonanywhere.com/sesh'
|
|
@@ -323,10 +339,11 @@ def updateItemDisplay(seshid, budget=False):
|
|
| 323 |
sesh.updated_display = realised_display
|
| 324 |
summarisePerStore(seshid)
|
| 325 |
|
| 326 |
-
|
| 327 |
|
| 328 |
return gr.Gallery(realised_display, label='Room Items', columns=5)
|
| 329 |
else: #except:
|
|
|
|
| 330 |
return sesh.updated_display
|
| 331 |
|
| 332 |
def getMostUsedColorsRGB(img_bytes):
|
|
@@ -366,6 +383,7 @@ def isJSONSerialiazable(obj):
|
|
| 366 |
return False
|
| 367 |
|
| 368 |
def updateItemDisplay(seshid, budget=False, pallete_change=False):
|
|
|
|
| 369 |
if True:
|
| 370 |
keys = ['filtered_items_room', 'current_img_signature', 'items', 'filtered_items_style', 'room_style', 'room_type', 'bedsize', 'price', 'filtered_items_colors', 'Palette_ids', 'item_data', 'item_data_', 'display_items', 'item_data_keys', 'Palettes_displayed', 'room_img_loaded', 'Paletteid', 'img_id', 'seshid']
|
| 371 |
url = 'https://dreamdemo.pythonanywhere.com/sesh'
|
|
@@ -494,13 +512,15 @@ def updateItemDisplay(seshid, budget=False, pallete_change=False):
|
|
| 494 |
sesh.updated_display = realised_display
|
| 495 |
summarisePerStore(seshid)
|
| 496 |
|
| 497 |
-
|
| 498 |
return gr.Gallery(realised_display, label='Room Items', columns=5)
|
| 499 |
else: #except:
|
|
|
|
| 500 |
return sesh.updated_display
|
| 501 |
|
| 502 |
|
| 503 |
def updateRoomType(evt: gr.SelectData, seshid):
|
|
|
|
| 504 |
label = evt.value['caption'].lower().split()[0] if evt.value['caption'] else sesh.room_type
|
| 505 |
sesh.room_type = label
|
| 506 |
images = [(v['bedroom'] if sesh.room_type == 'bedroom' else v['living room'], k) for k,v in styles_images.items()]
|
|
@@ -513,21 +533,26 @@ def updateRoomType(evt: gr.SelectData, seshid):
|
|
| 513 |
display = updateItemDisplay(seshid)
|
| 514 |
else:
|
| 515 |
display = sesh.updated_display
|
|
|
|
| 516 |
|
| 517 |
return images, gr.Radio(['Full', 'Queen', 'King'], value='Full', label='Bed Size', interactive=True, visible=True) if label == 'bedroom' else gr.Radio(visible=False), gr.Gallery(sesh.updated_display, label='Room Items', columns=5), display
|
| 518 |
|
| 519 |
|
| 520 |
def updateStyle(evt: gr.SelectData, seshid):
|
|
|
|
| 521 |
style = evt.value['caption'].lower().split()[0] if evt.value['caption'] else sesh.room_style
|
| 522 |
sesh.room_style = style
|
| 523 |
|
| 524 |
if hasattr(sesh, 'room_img_loaded') and sesh.room_img_loaded:
|
| 525 |
display = updateItemDisplay(seshid)
|
|
|
|
| 526 |
return display
|
| 527 |
else:
|
|
|
|
| 528 |
return sesh.updated_display
|
| 529 |
|
| 530 |
def updatePrice(evt: gr.SelectData, seshid):
|
|
|
|
| 531 |
print('updatePrice: ', type(evt.value), evt.value)
|
| 532 |
price = evt.value if evt.value else sesh.price
|
| 533 |
sesh.price = price
|
|
@@ -535,25 +560,31 @@ def updatePrice(evt: gr.SelectData, seshid):
|
|
| 535 |
|
| 536 |
if hasattr(sesh, 'room_img_loaded') and sesh.room_img_loaded:
|
| 537 |
display = updateItemDisplay(seshid)
|
|
|
|
| 538 |
return display
|
| 539 |
else:
|
|
|
|
| 540 |
return sesh.updated_display
|
| 541 |
|
| 542 |
|
| 543 |
def updateBedsize(evt: gr.SelectData, seshid):
|
|
|
|
| 544 |
bedsize = evt.value if evt.value else sesh.bedsize
|
| 545 |
sesh.bedsize = bedsize
|
| 546 |
|
| 547 |
|
| 548 |
if hasattr(sesh, 'room_img_loaded') and sesh.room_img_loaded:
|
| 549 |
display = updateItemDisplay(seshid)
|
|
|
|
| 550 |
return display
|
| 551 |
else:
|
|
|
|
| 552 |
return sesh.updated_display
|
| 553 |
|
| 554 |
|
| 555 |
#sesh.palettes_data
|
| 556 |
def updateColors(evt: gr.SelectData, seshid):
|
|
|
|
| 557 |
Paletteid = evt.value['caption'] if evt.value['caption'] else '0'
|
| 558 |
sesh.Paletteid = evt.value['caption']
|
| 559 |
sesh.Palette_ids[sesh.current_img_signature] = Paletteid
|
|
@@ -566,8 +597,10 @@ def updateColors(evt: gr.SelectData, seshid):
|
|
| 566 |
|
| 567 |
if hasattr(sesh, 'room_img_loaded') and sesh.room_img_loaded:
|
| 568 |
display = updateItemDisplay(seshid, pallete_change=True)
|
|
|
|
| 569 |
return display
|
| 570 |
else:
|
|
|
|
| 571 |
return sesh.updated_display
|
| 572 |
|
| 573 |
|
|
@@ -576,6 +609,7 @@ def updateColors(evt: gr.SelectData, seshid):
|
|
| 576 |
#Palettes_displayed, Palettes
|
| 577 |
|
| 578 |
def makePalettes(evt: gr.SelectData, seshid):
|
|
|
|
| 579 |
#print('makePalettes: ', type(evt.value), evt.value)
|
| 580 |
sesh.img_id = sesh.current_img_signature = evt.value['caption'] if evt.value['caption'] else sesh.current_img_signature
|
| 581 |
if sesh.current_img_signature in sesh.Palettes_displayed:
|
|
@@ -644,11 +678,13 @@ def makePalettes(evt: gr.SelectData, seshid):
|
|
| 644 |
sesh.Palettes_displayed[sesh.current_img_signature] = Palette_out
|
| 645 |
|
| 646 |
sesh.room_img_loaded = True
|
|
|
|
| 647 |
|
| 648 |
return Palette_out, sesh.img_data[sesh.img_id], display
|
| 649 |
|
| 650 |
#directory
|
| 651 |
def set_Palette(evt: gr.SelectData, seshid):
|
|
|
|
| 652 |
sesh.Paletteid = evt.value['caption']
|
| 653 |
sesh.Palette_img = np.zeros((200,200,3)).astype(np.uint8)
|
| 654 |
sesh.Palette_img[:50,:] = sesh.Palettes[sesh.img_id][sesh.Paletteid][0][0]
|
|
@@ -658,9 +694,11 @@ def set_Palette(evt: gr.SelectData, seshid):
|
|
| 658 |
|
| 659 |
sesh.Palette_imgs[sesh.img_id] = sesh.Palette_img
|
| 660 |
sesh.Palette_ids[sesh.img_id] = sesh.Paletteid
|
|
|
|
| 661 |
|
| 662 |
|
| 663 |
def set_style(evt: gr.SelectData, seshid):
|
|
|
|
| 664 |
label = evt.value['caption'].lower().split()[0]
|
| 665 |
sesh.room_type = label
|
| 666 |
images = [(v['bedroom'] if label == 'bedroom' else v['living room'], k) for k,v in styles_images.items()]
|
|
@@ -671,10 +709,12 @@ def set_style(evt: gr.SelectData, seshid):
|
|
| 671 |
|
| 672 |
room_items_imgs_tuples = [((sesh.Palette_img if item == 'Palette' else sesh.img_data[sesh.img_id]) if item in ['Palette', 'Living Room', 'Bedroom'] else room_item_placeholder_images_dict['BEDROOM FURNITURE' if label == 'bedroom' else 'LIVING ROOM FURNITURE'][item], item) for item in items]
|
| 673 |
|
|
|
|
| 674 |
return images, gr.Radio(['Full', 'Queen', 'King'], value='Full', label='Bed Size', interactive=True, visible=True) if label == 'bedroom' else gr.Radio(visible=False), gr.Gallery(room_items_imgs_tuples, label='Room Items', columns=5)
|
| 675 |
|
| 676 |
|
| 677 |
def applyStyle(evt: gr.SelectData, seshid):
|
|
|
|
| 678 |
design_style = evt.value['caption'].lower().split()[0]
|
| 679 |
|
| 680 |
sesh.filtered_files_style[sesh.img_id] = {color: [f for f in cfiles if any([(lambda substrs, f: substrs and substrs[0].lower() in f.lower() and (len(substrs)==1 or substrs[1] in f.lower()))(substr.replace('-', ' ').split(), f) for substr in design_style.split()])] for color,cfiles in sesh.filtered_files_room[sesh.img_id].items()}
|
|
@@ -693,15 +733,18 @@ def applyStyle(evt: gr.SelectData, seshid):
|
|
| 693 |
|
| 694 |
room_items_imgs_tuples = [((sesh.Palette_img if item == 'Palette' else sesh.img_data[sesh.img_id]) if item in ['Palette', 'Living Room', 'Bedroom'] else room_item_placeholder_images_dict['BEDROOM FURNITURE' if sesh.room_type == 'bedroom' else 'LIVING ROOM FURNITURE'][item], item) for item in sesh.items]
|
| 695 |
|
|
|
|
| 696 |
return gr.Gallery(room_items_imgs_tuples, label='Room Items', columns=5)
|
| 697 |
|
| 698 |
|
| 699 |
def roomItemClick(evt: gr.SelectData, seshid):
|
|
|
|
| 700 |
selection = evt.value['caption'].lower()
|
| 701 |
seshidtype = '...'+str(type(seshid))+ '...'
|
| 702 |
seshid_ = '...'+str(seshid)+ '...'
|
| 703 |
seshid = str(time.time()) if not seshid or seshid == 'SESHID' else seshid
|
| 704 |
sesh.clicked_displayed_product = evt.value['caption']
|
|
|
|
| 705 |
if selection == 'palette':
|
| 706 |
return gr.Column(scale=4), gr.update(visible=bool(0)), gr.update(visible=bool(0)), gr.update(visible=bool(1)), gr.Gallery(visible=False), gr.Label('Dream Home: As Quick As A Click. As Simple As Shopping.', label='Sponsors'), gr.update(visible=bool(0)), seshid
|
| 707 |
elif selection in ['living room', 'bedroom']:
|
|
@@ -716,20 +759,25 @@ def roomItemClick(evt: gr.SelectData, seshid):
|
|
| 716 |
|
| 717 |
|
| 718 |
def closeSidePanel(seshid):
|
|
|
|
|
|
|
| 719 |
return gr.Column(scale=5), gr.update(visible=bool(0)), gr.update(visible=bool(0)), gr.update(visible=bool(0)), gr.Label('No Item Selected', label='Merchant'), gr.Gallery(visible=False), gr.Label('Dream Home: As Quick As A Click. As Simple As Shopping.', label='Sponsors', visible=True), gr.update(visible=bool(0))
|
| 720 |
|
| 721 |
|
| 722 |
|
| 723 |
def productClick(evt: gr.SelectData, seshid):
|
|
|
|
| 724 |
if not sesh.clicked_displayed_product:
|
| 725 |
return gr.Label('No Item Selected', label='Merchant')
|
| 726 |
product_idx = evt.index
|
| 727 |
sesh.product_idx = evt.index
|
| 728 |
product = sesh.item_data[sesh.current_img_signature][sesh.room_type][sesh.room_style][sesh.price][sesh.Paletteid][sesh.clicked_displayed_product][product_idx]
|
| 729 |
sesh.product = product
|
|
|
|
| 730 |
return gr.Label(product['store'].split('-')[0], label='Merchant')
|
| 731 |
|
| 732 |
def replaceProduct(seshid):
|
|
|
|
| 733 |
item_idx = sesh.items.index(sesh.clicked_displayed_product)
|
| 734 |
sesh.updated_display[item_idx] = (sesh.product['img'], sesh.clicked_displayed_product)
|
| 735 |
#sesh.display_items[sesh.current_img_signature][sesh.room_type][sesh.room_style][sesh.price][sesh.Paletteid][item_idx] = (sesh.product_idx, sesh.clicked_displayed_product) if sesh.product_idx in sesh.inbudget[sesh.current_img_signature][sesh.clicked_displayed_product] else sesh.display_items[sesh.current_img_signature][sesh.room_type][sesh.room_style][sesh.price][sesh.Paletteid][item_idx]
|
|
@@ -746,10 +794,12 @@ def replaceProduct(seshid):
|
|
| 746 |
|
| 747 |
#print('replaceProduct: ', sesh.product_idx, sesh.clicked_displayed_product, sesh.product_idx in sesh.inbudget[sesh.current_img_signature][sesh.clicked_displayed_product], sesh.display_items_, sum([float(item_product[1]['price'].replace('$', '').replace(',', '')) for img in sesh.summary for item_product in sesh.summary[img] if item_product]))
|
| 748 |
|
|
|
|
| 749 |
return gr.Column(scale=5), gr.update(visible=bool(0)), gr.update(visible=bool(0)), gr.update(visible=bool(0)), gr.Label('No Item Selected', label='Merchant'), gr.Gallery(visible=False), gr.Label('Dream Home: As Quick As A Click. As Simple As Shopping.', label='Sponsors', visible=True), gr.Gallery(sesh.updated_display, label='Room Items', columns=5)
|
| 750 |
|
| 751 |
|
| 752 |
def selectMerchantItemCountAndTotal(store, seshid):
|
|
|
|
| 753 |
num_items = 0
|
| 754 |
total = 0
|
| 755 |
for item in sesh.summary_joined[store]:
|
|
@@ -757,17 +807,20 @@ def selectMerchantItemCountAndTotal(store, seshid):
|
|
| 757 |
price = sesh.summary_joined[store][item][description]['product_dict']['price']
|
| 758 |
count = sesh.summary_joined[store][item][description]['count']
|
| 759 |
total += float(price.replace('$', '').replace(',', '')) * count
|
| 760 |
-
num_items += count
|
|
|
|
| 761 |
return num_items, total
|
| 762 |
|
| 763 |
def selectMerchantItemCountAndTotal(store, seshid):
|
|
|
|
| 764 |
num_items = 0
|
| 765 |
total = 0
|
| 766 |
for item in sesh.summary_joined[store]:
|
| 767 |
price = sesh.summary_joined[store][item]['product_dict']['price']
|
| 768 |
count = sesh.summary_joined[store][item]['count']
|
| 769 |
total += float(price.replace('$', '').replace(',', '')) * count
|
| 770 |
-
num_items += count
|
|
|
|
| 771 |
return num_items, total
|
| 772 |
|
| 773 |
from huggingface_hub import InferenceClient
|
|
@@ -783,6 +836,7 @@ def retrieveProcessedStoreData(store, seshid):
|
|
| 783 |
return []
|
| 784 |
|
| 785 |
def summaryClick(seshid):
|
|
|
|
| 786 |
#from pathlib import Path
|
| 787 |
sesh.counts_totals = {store:selectMerchantItemCountAndTotal(store) for store in sesh.summary_joined}
|
| 788 |
all_counts = str(sum([ct[0] for store,ct in sesh.counts_totals.items()]))
|
|
@@ -794,19 +848,23 @@ def summaryClick(seshid):
|
|
| 794 |
#store_data = {store: (lambda data: '' if not data or 'zipcode' not in data[0] else '\n'.join([str(d) for d in data]))(retrieveProcessedStoreData(store)) for store in sesh.summary_joined}
|
| 795 |
item_summary_data = '\n\n'.join(['STORE: '+store+'\n'+('\tLOCATIONS: N/A' if not store_data[store] else '\tLOCATIONS: \n'+store_data[store])+''.join(['\n\tPRODUCT: '+ product +'\n\tPRICE: '+pd_count['product_dict']['price']+'\n\tSOURCE: '+pd_count['product_dict']['href'] for product,pd_count in sesh.summary_joined[store].items()]) for store in sesh.summary_joined])
|
| 796 |
print('store summary: ', {store: retrieveProcessedStoreData(store) for store in sesh.summary_joined})
|
|
|
|
| 797 |
return gr.Button('Suppress Summary'), gr.update(visible=bool(0)), gr.update(visible=bool(0)), gr.update(visible=bool(0)), gr.update(visible=bool(1)), gr.update(visible=bool(0)), gr.update(visible=bool(0)), gr.update(visible=bool(1)), gr.Dropdown(list(sesh.summary_joined), label='Merchants', interactive=True), gr.Label('All', label='Merchant'), gr.Label(all_counts, label='Number of Items'), gr.Label('$'+str(np.round(all_totals, 2)), label='Total'), item_summary_data
|
| 798 |
|
| 799 |
#'\n\n'.join(['Store: '+store+'\n\n'+'\n\n'.join(['\n\tProduct: '+ product +'\n\tPrice: '+pd_count['product_dict']['price']+'\n\tSource: '+pd_count['product_dict']['href'] for product,pd_count in sesh.summary_joined[store].items()]) for store in sesh.summary_joined])
|
| 800 |
else:
|
| 801 |
sesh.summary_closed = True
|
|
|
|
| 802 |
return gr.Button('Summarise'), gr.update(visible=bool(1)), gr.update(visible=bool(1)), gr.update(visible=bool(1)), gr.update(visible=bool(0)), gr.update(visible=bool(0)), gr.update(visible=bool(1)), gr.update(visible=bool(0)), gr.Dropdown(), gr.Label(), gr.Label(), gr.Label(), ''
|
| 803 |
|
| 804 |
|
| 805 |
def selectMerchantProduct(evt: gr.SelectData, seshid):
|
|
|
|
| 806 |
store = evt.value
|
| 807 |
sesh.summary_store = store
|
| 808 |
|
| 809 |
#print('selectMerchantProduct -- counts_totals: ', counts_totals)
|
|
|
|
| 810 |
return gr.Dropdown(list(sesh.summary_joined[store]), label='Items', interactive=True), gr.Label(sesh.summary_store if sesh.summary_store else 'All', label='Merchant'), gr.Label(str(sesh.counts_totals[store][0]), label='Number of Items'), gr.Label('$'+str(np.round(sesh.counts_totals[store][1], 2)), label='Total')
|
| 811 |
|
| 812 |
|
|
@@ -836,6 +894,7 @@ def findShoppingRelevantTerms(html):
|
|
| 836 |
return {}
|
| 837 |
|
| 838 |
def changeSummaryFilter(evt: gr.SelectData, seshid):
|
|
|
|
| 839 |
summary_radio = evt.value
|
| 840 |
print('changeSummaryFilter: ', summary_radio)
|
| 841 |
sesh.summary_radio = summary_radio
|
|
@@ -844,6 +903,7 @@ def changeSummaryFilter(evt: gr.SelectData, seshid):
|
|
| 844 |
#if summary_radio == 'Complete' or not hasattr(sesh, 'summary_store'):
|
| 845 |
if summary_radio == 'Complete':
|
| 846 |
print('changeSummaryFilter: in Complete')
|
|
|
|
| 847 |
return gr.Label('All', label='Merchant'), gr.Label(all_counts, label='Number of Items'), gr.Label('$'+str(np.round(all_totals, 2)), label='Total'), gr.update(visible=bool(0)), gr.update(visible=bool(1)), gr.update(visible=bool(1)), gr.update(visible=bool(0))
|
| 848 |
elif summary_radio == 'Script':
|
| 849 |
#textgen for general audience, things to look out for or be aware of
|
|
@@ -908,28 +968,35 @@ def changeSummaryFilter(evt: gr.SelectData, seshid):
|
|
| 908 |
#prompt = preprompt+"\n\nTask: Referencing the ITEMS provided -- each item DESCRIPTION, in particular -- create an audio script about shopping to decorate a room, writing to prompt the listener for their feedback as to whether the items chosen are choices they might have made; where applicable, incorporate the corresponding ITEM TOPICS to the item DESCRIPTION being written about, and do so in a way that is informing the listener of what they might expect during the ordering process. Reference the ITEM TOPICS in a fun way as if you are engaging in small talk, making remarks to the respective ITEM TOPIC in a 'just a heads up' tangent and then getting back on script. Write in the past tense, like we have already decorated and are now reviewing the items chosen to outfit the room, speculating as to the listener's stance on the items chosen, whether they would like the ITEM being spoken about and why (be creative, thinking of random reasons the listener would or would not like the ITEM chosen). Write in an informal style."
|
| 909 |
|
| 910 |
end = time.time()
|
|
|
|
| 911 |
return gr.Label('All', label='Merchant'), gr.Label(all_counts, label='Number of Items'), gr.Label('$'+str(np.round(all_totals, 2)), label='Total'), gr.update(visible=bool(0)), gr.update(visible=bool(1)), gr.update(visible=bool(1)), gr.update(visible=bool(0))
|
| 912 |
else:
|
|
|
|
| 913 |
return gr.Label(sesh.summary_store if hasattr(sesh, 'summary_store') and sesh.summary_store else 'All', label='Merchant'), gr.Label(str(sesh.counts_totals[sesh.summary_store][0]) if hasattr(sesh, 'summary_store') and sesh.summary_store else '--', label='Number of Items'), gr.Label('$'+str(np.round(sesh.counts_totals[sesh.summary_store][1], 2)) if hasattr(sesh, 'summary_store') and sesh.summary_store else '--', label='Total'), gr.update(visible=bool(1)), gr.update(visible=bool(0)), gr.update(visible=bool(0)), gr.update(visible=bool(1))
|
| 914 |
|
| 915 |
|
| 916 |
|
| 917 |
def displaySource(evt: gr.SelectData, seshid):
|
|
|
|
| 918 |
product = evt.value
|
| 919 |
sesh.summary_product = product
|
| 920 |
#sources = '\n\n'.join(['Price: '+pd_count['product_dict']['price']+'\n\nSource: '+pd_count['product_dict']['href'] for description_key,pd_count in sesh.summary_joined[sesh.summary_store][product].items()])
|
| 921 |
sources = 'Price: '+sesh.summary_joined[sesh.summary_store][product]['product_dict']['price']+'\n\nSource: '+sesh.summary_joined[sesh.summary_store][product]['product_dict']['href']
|
|
|
|
| 922 |
return gr.Markdown(sources), gr.Number(value=sesh.summary_joined[sesh.summary_store][product]['count'], label='Item Count', minimum=0)
|
| 923 |
|
| 924 |
def updateProductCount(count, seshid):
|
|
|
|
| 925 |
sesh.summary_joined[sesh.summary_store][sesh.summary_product]['count'] = count
|
| 926 |
sesh.counts_totals = {store:selectMerchantItemCountAndTotal(store) for store in sesh.summary_joined}
|
| 927 |
all_counts = str(sum([ct[0] for store,ct in sesh.counts_totals.items()]))
|
| 928 |
all_totals = sum([ct[1] for store,ct in sesh.counts_totals.items()])
|
| 929 |
|
|
|
|
| 930 |
return gr.Label(str(sesh.counts_totals[sesh.summary_store][0]) if sesh.summary_store and sesh.summary_radio != 'Complete' else all_counts, label='Number of Items'), gr.Label('$'+str(np.round(sesh.counts_totals[sesh.summary_store][1], 2)) if sesh.summary_store and sesh.summary_radio != 'Complete' else '$'+str(np.round(all_totals, 2)), label='Total')
|
| 931 |
|
| 932 |
def updateBudget(budget_number, seshid):
|
|
|
|
| 933 |
sesh.budget_number = float(budget_number)
|
| 934 |
#sesh.item_budgets = {img: {item: int(weight*sesh.budget_number) for item,weight in weights.items()} for img,weights in sesh.product_means_weights.items()}
|
| 935 |
#print('updateBudget: ', sesh.budget_number, sesh.item_budgets)
|
|
@@ -938,6 +1005,7 @@ def updateBudget(budget_number, seshid):
|
|
| 938 |
sesh.counts_totals = {store:selectMerchantItemCountAndTotal(store) for store in sesh.summary_joined}
|
| 939 |
all_counts = str(sum([ct[0] for store,ct in sesh.counts_totals.items()]))
|
| 940 |
all_totals = sum([ct[1] for store,ct in sesh.counts_totals.items()])
|
|
|
|
| 941 |
return display, gr.Label(all_counts, label='Number of Items'), gr.Label('$'+str(np.round(all_totals, 2)), label='Total')
|
| 942 |
|
| 943 |
|
|
@@ -954,6 +1022,7 @@ def showJourneys(seshid):
|
|
| 954 |
templates = {0:['For ITEM, we went with the ITEM DESCRIPTION. SPECULATED RESPONSE.', 'SPECULATED RESPONSE, so for ITEM we went with the ITEM DESCRIPTION.'], 1:['For ITEM, we went with the ITEM DESCRIPTION. ITEM TOPIC. SPECULATED RESPONSE.', 'SPECULATED RESPONSE, so for ITEM we went with the ITEM DESCRIPTION. ITEM TOPIC.'], 2:['For ITEM, we went with the ITEM DESCRIPTION. ITEM TOPICS. SPECULATED RESPONSE.', 'SPECULATED RESPONSE, so for ITEM we went with the ITEM DESCRIPTION. ITEM TOPICS.']}
|
| 955 |
|
| 956 |
def makeItemPrompt(idx,data, seshid):
|
|
|
|
| 957 |
template = templates[len(data[1]) if len(data[1])<2 else 2][np.random.choice([0,1])]
|
| 958 |
prompt = sesh.items_prepped[idx]+'\n\nTEMPLATE: '+template+"\n\nTASK: adapt TEMPLATE using the ITEM/DESCRIPTION/STORE info provided, where SPECULATED RESPONSE is your creative guess as to the reader's stance on the items chosen, whether they would like the ITEM being written about and why (be creative, thinking of random reasons the reader would or would not like the ITEM chosen). Write from the perspective of reporting to someone who is considering purchasing a home and you are presenting different decorative options that might persuade them to buy the home; so, make sure your wording reflects this -- 'if you go with...', 'now keep in mind...', 'were you to purchase this home...' and the like are examples of how you might word things. You don't have to use these examples exactly, just word things similarly. Be creative."
|
| 959 |
if data[1]:
|
|
@@ -966,16 +1035,20 @@ def makeItemPrompt(idx,data, seshid):
|
|
| 966 |
prompt += "Keep in mind this is the last of many items we are reviewing, so ensure your writing reflects the fact that this is the final item being reported on and do a review wrap-up/send off for this particular room's decor review. Maybe begin by writing something along the lines of 'Okay lastly we have the...' or 'Well, our final item is...' or what have you are examples of how you might word things. You don't have to use these examples exactly, just word things similarly. Be creative."
|
| 967 |
else:
|
| 968 |
prompt += "Keep in mind this is the one of many items we have already reviewed and one of other yet to be reviewed, so ensure your writing reflects the fact that this is just the next item being reported on. Maybe begin by writing something along the lines of 'Okay now we have...' or 'So next up is...' or what have you are examples of how you might word things. You don't have to use these examples exactly, just word things similarly. Be creative."
|
|
|
|
| 969 |
return prompt
|
| 970 |
|
| 971 |
def generateScriptForItem(idx,data, seshid):
|
|
|
|
| 972 |
prompt = makeItemPrompt(idx,data)
|
| 973 |
#tg_response = client.text_generation(prompt, model="mistralai/Mixtral-8x7B-Instruct-v0.1", max_new_tokens=2500)
|
| 974 |
tg_response = getTextGen(prompt)
|
| 975 |
tg_response = tg_response.replace("I know what you're thinking", np.random.choice(alarm3)).replace("I know what you're thinking", np.random.choice(alarm3))
|
| 976 |
sesh.tg_responses.append(tg_response)
|
|
|
|
| 977 |
|
| 978 |
def generateScriptForItem(seshid):
|
|
|
|
| 979 |
url = 'https://dreamdemo.pythonanywhere.com/script_gen'
|
| 980 |
valid_data = {'room_type': sesh.room_type, 'idx': sesh.found_terms_4_room_items_idx, 'gen_uid': sesh.gen_uid}
|
| 981 |
headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}
|
|
@@ -984,8 +1057,10 @@ def generateScriptForItem(seshid):
|
|
| 984 |
tg_response = jsondata['response']
|
| 985 |
print('generateScriptForItem from endpoint: ', tg_response)
|
| 986 |
sesh.tg_responses.append(tg_response)
|
|
|
|
| 987 |
|
| 988 |
def loadColorAndCharacter(text, seshid):
|
|
|
|
| 989 |
if text == 'load':
|
| 990 |
sesh.product_pd_counts = [(product,pd_count) for store in sesh.summary_joined for product,pd_count in sesh.summary_joined[store].items()]
|
| 991 |
sesh.tg_responses = []
|
|
@@ -1023,12 +1098,15 @@ def loadColorAndCharacter(text, seshid):
|
|
| 1023 |
responses = asyncio.run(main_post(urls, headers, json_data, timeout=1))
|
| 1024 |
except:
|
| 1025 |
pass
|
|
|
|
| 1026 |
return 'loaded'
|
| 1027 |
else:
|
|
|
|
| 1028 |
return 'not loaded'
|
| 1029 |
|
| 1030 |
|
| 1031 |
def searchColorAndCharacter(text, seshid):
|
|
|
|
| 1032 |
if text == 'search':
|
| 1033 |
"""url = 'https://dreamdemo.pythonanywhere.com/shopping'
|
| 1034 |
sesh.gen_uid = str(time.time())
|
|
@@ -1087,13 +1165,17 @@ def searchColorAndCharacter(text, seshid):
|
|
| 1087 |
#item_prompts = [makeItemPrompt(idx,idata) for idx,idata in enumerate(sesh.found_terms_4_room_items[sesh.found_terms_4_room_items_idx])]
|
| 1088 |
#item_scripts = multiprocessPrompts(item_prompts)
|
| 1089 |
#print('searchColorAndCharacter: ', item_scripts)
|
|
|
|
| 1090 |
return 'searched'
|
| 1091 |
else:
|
|
|
|
| 1092 |
return 'not searched'
|
| 1093 |
|
| 1094 |
|
| 1095 |
|
| 1096 |
def updateLinksLoadStatus(text, seshid):
|
|
|
|
|
|
|
| 1097 |
if text == 'loaded':
|
| 1098 |
print('LOADED color and character for script\nadding color and character to script\nstandby...')
|
| 1099 |
return 'LOADED color and character\nadding color and character to scripts\nstandby...', 'search'
|
|
@@ -1101,6 +1183,8 @@ def updateLinksLoadStatus(text, seshid):
|
|
| 1101 |
return 'searched color and character for script\npreparing script for item1\nstandby...update this', ''
|
| 1102 |
|
| 1103 |
def updateLinksSearchStatus(text, seshid):
|
|
|
|
|
|
|
| 1104 |
if text == 'searched':
|
| 1105 |
print('ADDED color and character for script\npreparing script for item1\nstandby...')
|
| 1106 |
#return f'ADDED color and character for script\npreparing script for {sesh.product_pd_counts[0][0]}\nWorking on step {sesh.found_terms_4_room_items_idx+1} of {len(sesh.product_pd_counts)+6}, standby......', 'prep1'
|
|
@@ -1109,6 +1193,8 @@ def updateLinksSearchStatus(text, seshid):
|
|
| 1109 |
return 'searched color and character for script\npreparing script for item1\nstandby...update this', ''
|
| 1110 |
|
| 1111 |
def prepAllScripts(text, seshid):
|
|
|
|
|
|
|
| 1112 |
if text == f'prep{sesh.found_terms_4_room_items_idx+1}':
|
| 1113 |
script_prompts = {'Youtube Long-Form': 'SCRIPT: \n\n'+'\n\n'.join(sesh.tg_responses)+f'\n\nTASK: rewrite the provided SCRIPT for a long-form Youtube video. Keep in mind the SCRIPT is about reviewing items to potentially have purchased, shipped and decorate a {sesh.room_type}; this is all for a prospective home buyer -- you are the item reviewer who is reviewing items on behalf of the potential home buyer.', 'Youtube Short-Form': 'SCRIPT: \n\n'+'\n\n'.join(sesh.tg_responses)+f'\n\nTASK: rewrite the provided SCRIPT for a Youtube Short. Keep in mind the SCRIPT is about reviewing items to potentially have purchased, shipped and decorate a {sesh.room_type}; this is all for a prospective home buyer -- you are the item reviewer who is reviewing items on behalf of the potential home buyer.', 'Facebook Long-Form': 'SCRIPT: \n\n'+'\n\n'.join(sesh.tg_responses)+f'\n\nTASK: rewrite the provided SCRIPT for a long-form Facebook video. Keep in mind the SCRIPT is about reviewing items to potentially have purchased, shipped and decorate a {sesh.room_type}; this is all for a prospective home buyer -- you are the item reviewer who is reviewing items on behalf of the potential home buyer.', 'Instagram Reel': 'SCRIPT: \n\n'+'\n\n'.join(sesh.tg_responses)+f'\n\nTASK: rewrite the provided SCRIPT for an Instagram Reel video. Keep in mind the SCRIPT is about reviewing items to potentially have purchased, shipped and decorate a {sesh.room_type}; this is all for a prospective home buyer -- you are the item reviewer who is reviewing items on behalf of the potential home buyer.', 'Tiktok': 'SCRIPT: \n\n'+'\n\n'.join(sesh.tg_responses)+f'\n\nTASK: rewrite the provided SCRIPT for a Tiktok video. Keep in mind the SCRIPT is about reviewing items to potentially have purchased, shipped and decorate a {sesh.room_type}; this is all for a prospective home buyer -- you are the item reviewer who is reviewing items on behalf of the potential home buyer.', 'LinkedIn': 'SCRIPT: \n\n'+'\n\n'.join(sesh.tg_responses)+f'\n\nTASK: rewrite the provided SCRIPT for a LinkedIn long-form video. Keep in mind the SCRIPT is about reviewing items to potentially have purchased, shipped and decorate a {sesh.room_type}; this is all for a prospective home buyer -- you are the item reviewer who is reviewing items on behalf of the potential home buyer.'}
|
| 1114 |
start = time.time()
|
|
@@ -1121,294 +1207,395 @@ def prepAllScripts(text, seshid):
|
|
| 1121 |
sesh.scripts = {k:json.loads(responses[i])['response'] if type(responses[i]) == type(b'') else 'Unable to complete this script.' for i,k in enumerate(script_types)}
|
| 1122 |
|
| 1123 |
#print('prepItem1ForScript script types: ', (end-start)/60, [(r[:250], script_types[i]) for i,r in enumerate(responses)])
|
|
|
|
| 1124 |
return 'good'
|
| 1125 |
|
| 1126 |
else:
|
|
|
|
| 1127 |
return 'bad'
|
| 1128 |
|
| 1129 |
def updateAllItemsStatus(text, seshid):
|
|
|
|
| 1130 |
completed = len([s for s in sesh.scripts if s != 'Unable to complete this script.'])
|
| 1131 |
if text == 'good' and completed > 0:
|
|
|
|
| 1132 |
return f"Color and character updated, {completed} {'scripts' if completed != 1 else 'script'} completed. ", gr.Dropdown(list(sesh.scripts), label='Scripts', interactive=True)
|
| 1133 |
|
| 1134 |
else:
|
|
|
|
| 1135 |
return f'Something went wrong, failed to complete scripts.', gr.Dropdown([], label='Scripts', interactive=True)
|
| 1136 |
|
| 1137 |
def prepItem1ForScript(text, seshid):
|
|
|
|
| 1138 |
if text == f'prep{sesh.found_terms_4_room_items_idx+1}':
|
| 1139 |
#generateScriptForItem(sesh.found_terms_4_room_items_idx,sesh.found_terms_4_room_items[sesh.found_terms_4_room_items_idx])
|
| 1140 |
generateScriptForItem()
|
| 1141 |
sesh.found_terms_4_room_items_idx += 1
|
|
|
|
| 1142 |
return f'prepped{sesh.found_terms_4_room_items_idx}'+'-changed for testing'
|
| 1143 |
|
| 1144 |
else:
|
|
|
|
| 1145 |
return f'prep{sesh.found_terms_4_room_items_idx} failed'
|
| 1146 |
|
| 1147 |
def updateItem1Status(text, seshid):
|
|
|
|
| 1148 |
if text == f'prepped{sesh.found_terms_4_room_items_idx}':
|
| 1149 |
#print('prepItem1forScript: ', sesh.tg_responses[0])
|
|
|
|
| 1150 |
return 'Color and character updated, scripts complete.', f'prep{sesh.found_terms_4_room_items_idx+1}'
|
| 1151 |
#return f'{sesh.product_pd_counts[sesh.found_terms_4_room_items_idx-1][0].upper()} script complete.\nPreparing script for {sesh.product_pd_counts[sesh.found_terms_4_room_items_idx][0]}.\nWorking on step {sesh.found_terms_4_room_items_idx+1} of {len(sesh.product_pd_counts)+6}, standby...', f'prep{sesh.found_terms_4_room_items_idx+1}'
|
| 1152 |
else:
|
|
|
|
| 1153 |
print(f'prepItem{sesh.found_terms_4_room_items_idx+1}ForScript: fail')
|
| 1154 |
return f'ITEM {sesh.found_terms_4_room_items_idx} prep failed', ''
|
| 1155 |
|
| 1156 |
|
| 1157 |
def prepItem2ForScript(text, seshid):
|
|
|
|
| 1158 |
if text == f'prep{sesh.found_terms_4_room_items_idx+1}':
|
| 1159 |
#generateScriptForItem(sesh.found_terms_4_room_items_idx,sesh.found_terms_4_room_items[sesh.found_terms_4_room_items_idx])
|
| 1160 |
generateScriptForItem()
|
| 1161 |
sesh.found_terms_4_room_items_idx += 1
|
|
|
|
| 1162 |
return f'prepped{sesh.found_terms_4_room_items_idx}'
|
| 1163 |
else:
|
|
|
|
| 1164 |
return f'prep{sesh.found_terms_4_room_items_idx} failed'
|
| 1165 |
|
| 1166 |
def updateItem2Status(text, seshid):
|
|
|
|
| 1167 |
if text == f'prepped{sesh.found_terms_4_room_items_idx}':
|
| 1168 |
#print('prepItem1forScript: ', sesh.tg_responses[0])
|
|
|
|
| 1169 |
return f'{sesh.product_pd_counts[sesh.found_terms_4_room_items_idx-1][0].upper()} script complete.\nPreparing script for {sesh.product_pd_counts[sesh.found_terms_4_room_items_idx][0]}.\nWorking on step {sesh.found_terms_4_room_items_idx+1} of {len(sesh.product_pd_counts)+6}, standby...', f'prep{sesh.found_terms_4_room_items_idx+1}'
|
| 1170 |
else:
|
| 1171 |
print(f'prepItem{sesh.found_terms_4_room_items_idx+1}ForScript: fail')
|
|
|
|
| 1172 |
return f'ITEM {sesh.found_terms_4_room_items_idx} prep failed', ''
|
| 1173 |
|
| 1174 |
|
| 1175 |
def prepItem3ForScript(text, seshid):
|
|
|
|
| 1176 |
if text == f'prep{sesh.found_terms_4_room_items_idx+1}':
|
| 1177 |
#generateScriptForItem(sesh.found_terms_4_room_items_idx,sesh.found_terms_4_room_items[sesh.found_terms_4_room_items_idx])
|
| 1178 |
generateScriptForItem()
|
| 1179 |
sesh.found_terms_4_room_items_idx += 1
|
|
|
|
| 1180 |
return f'prepped{sesh.found_terms_4_room_items_idx}'
|
| 1181 |
else:
|
|
|
|
| 1182 |
return f'prep{sesh.found_terms_4_room_items_idx} failed'
|
| 1183 |
|
| 1184 |
def updateItem3Status(text, seshid):
|
|
|
|
| 1185 |
if text == f'prepped{sesh.found_terms_4_room_items_idx}':
|
| 1186 |
#print('prepItem1forScript: ', sesh.tg_responses[0])
|
|
|
|
| 1187 |
return f'{sesh.product_pd_counts[sesh.found_terms_4_room_items_idx-1][0].upper()} script complete.\nPreparing script for {sesh.product_pd_counts[sesh.found_terms_4_room_items_idx][0]}.\nWorking on step {sesh.found_terms_4_room_items_idx+1} of {len(sesh.product_pd_counts)+6}, standby...', f'prep{sesh.found_terms_4_room_items_idx+1}'
|
| 1188 |
else:
|
| 1189 |
print(f'prepItem{sesh.found_terms_4_room_items_idx+1}ForScript: fail')
|
|
|
|
| 1190 |
return f'ITEM {sesh.found_terms_4_room_items_idx} prep failed', ''
|
| 1191 |
|
| 1192 |
def prepItem4ForScript(text, seshid):
|
|
|
|
| 1193 |
if text == f'prep{sesh.found_terms_4_room_items_idx+1}':
|
| 1194 |
#generateScriptForItem(sesh.found_terms_4_room_items_idx,sesh.found_terms_4_room_items[sesh.found_terms_4_room_items_idx])
|
| 1195 |
generateScriptForItem()
|
| 1196 |
sesh.found_terms_4_room_items_idx += 1
|
|
|
|
| 1197 |
return f'prepped{sesh.found_terms_4_room_items_idx}'
|
| 1198 |
else:
|
|
|
|
| 1199 |
return f'prep{sesh.found_terms_4_room_items_idx} failed'
|
| 1200 |
|
| 1201 |
def updateItem4Status(text, seshid):
|
|
|
|
| 1202 |
if text == f'prepped{sesh.found_terms_4_room_items_idx}':
|
| 1203 |
#print('prepItem1forScript: ', sesh.tg_responses[0])
|
|
|
|
| 1204 |
return f'{sesh.product_pd_counts[sesh.found_terms_4_room_items_idx-1][0].upper()} script complete.\nPreparing script for {sesh.product_pd_counts[sesh.found_terms_4_room_items_idx][0]}.\nWorking on step {sesh.found_terms_4_room_items_idx+1} of {len(sesh.product_pd_counts)+6}, standby...', f'prep{sesh.found_terms_4_room_items_idx+1}'
|
| 1205 |
else:
|
| 1206 |
print(f'prepItem{sesh.found_terms_4_room_items_idx+1}ForScript: fail')
|
|
|
|
| 1207 |
return f'ITEM {sesh.found_terms_4_room_items_idx} prep failed', ''
|
| 1208 |
|
| 1209 |
def prepItem5ForScript(text, seshid):
|
|
|
|
| 1210 |
if text == f'prep{sesh.found_terms_4_room_items_idx+1}':
|
| 1211 |
#generateScriptForItem(sesh.found_terms_4_room_items_idx,sesh.found_terms_4_room_items[sesh.found_terms_4_room_items_idx])
|
| 1212 |
generateScriptForItem()
|
| 1213 |
sesh.found_terms_4_room_items_idx += 1
|
|
|
|
| 1214 |
return f'prepped{sesh.found_terms_4_room_items_idx}'
|
| 1215 |
else:
|
|
|
|
| 1216 |
return f'prep{sesh.found_terms_4_room_items_idx} failed'
|
| 1217 |
|
| 1218 |
def updateItem5Status(text, seshid):
|
|
|
|
| 1219 |
if text == f'prepped{sesh.found_terms_4_room_items_idx}':
|
| 1220 |
#print('prepItem1forScript: ', sesh.tg_responses[0])
|
|
|
|
| 1221 |
return f'{sesh.product_pd_counts[sesh.found_terms_4_room_items_idx-1][0].upper()} script complete.\nPreparing script for {sesh.product_pd_counts[sesh.found_terms_4_room_items_idx][0]}.\nWorking on step {sesh.found_terms_4_room_items_idx+1} of {len(sesh.product_pd_counts)+6}, standby...', f'prep{sesh.found_terms_4_room_items_idx+1}'
|
| 1222 |
else:
|
| 1223 |
print(f'prepItem{sesh.found_terms_4_room_items_idx+1}ForScript: fail')
|
|
|
|
| 1224 |
return f'ITEM {sesh.found_terms_4_room_items_idx} prep failed', ''
|
| 1225 |
|
| 1226 |
def prepItem6ForScript(text, seshid):
|
|
|
|
| 1227 |
if text == f'prep{sesh.found_terms_4_room_items_idx+1}':
|
| 1228 |
#generateScriptForItem(sesh.found_terms_4_room_items_idx,sesh.found_terms_4_room_items[sesh.found_terms_4_room_items_idx])
|
| 1229 |
generateScriptForItem()
|
| 1230 |
sesh.found_terms_4_room_items_idx += 1
|
|
|
|
| 1231 |
return f'prepped{sesh.found_terms_4_room_items_idx}'
|
| 1232 |
else:
|
|
|
|
| 1233 |
return f'prep{sesh.found_terms_4_room_items_idx} failed'
|
| 1234 |
|
| 1235 |
def updateItem6Status(text, seshid):
|
|
|
|
| 1236 |
if text == f'prepped{sesh.found_terms_4_room_items_idx}':
|
| 1237 |
#print('prepItem1forScript: ', sesh.tg_responses[0])
|
|
|
|
| 1238 |
return f'{sesh.product_pd_counts[sesh.found_terms_4_room_items_idx-1][0].upper()} script complete.\nPreparing script for {sesh.product_pd_counts[sesh.found_terms_4_room_items_idx][0]}.\nWorking on step {sesh.found_terms_4_room_items_idx} of {len(sesh.product_pd_counts)+6}, standby...', f'prep{sesh.found_terms_4_room_items_idx+1}'
|
| 1239 |
else:
|
| 1240 |
print(f'prepItem{sesh.found_terms_4_room_items_idx+1}ForScript: fail')
|
|
|
|
| 1241 |
return f'ITEM {sesh.found_terms_4_room_items_idx} prep failed', ''
|
| 1242 |
|
| 1243 |
def prepItem7ForScript(text, seshid):
|
|
|
|
| 1244 |
if text == f'prep{sesh.found_terms_4_room_items_idx+1}':
|
| 1245 |
#generateScriptForItem(sesh.found_terms_4_room_items_idx,sesh.found_terms_4_room_items[sesh.found_terms_4_room_items_idx])
|
| 1246 |
generateScriptForItem()
|
| 1247 |
sesh.found_terms_4_room_items_idx += 1
|
|
|
|
| 1248 |
return f'prepped{sesh.found_terms_4_room_items_idx}'
|
| 1249 |
else:
|
|
|
|
| 1250 |
return f'prep{sesh.found_terms_4_room_items_idx} failed'
|
| 1251 |
|
| 1252 |
def updateItem7Status(text, seshid):
|
|
|
|
| 1253 |
if text == f'prepped{sesh.found_terms_4_room_items_idx}':
|
| 1254 |
#print('prepItem1forScript: ', sesh.tg_responses[0])
|
|
|
|
| 1255 |
return f'{sesh.product_pd_counts[sesh.found_terms_4_room_items_idx-1][0].upper()} script complete.\nPreparing script for {sesh.product_pd_counts[sesh.found_terms_4_room_items_idx][0]}.\nWorking on step {sesh.found_terms_4_room_items_idx+1} of {len(sesh.product_pd_counts)+6}, standby...', f'prep{sesh.found_terms_4_room_items_idx+1}'
|
| 1256 |
else:
|
| 1257 |
|
| 1258 |
print(f'prepItem{sesh.found_terms_4_room_items_idx+1}ForScript: fail')
|
|
|
|
| 1259 |
return f'ITEM {sesh.found_terms_4_room_items_idx} prep failed', ''
|
| 1260 |
|
| 1261 |
def prepItem8ForScript(text, seshid):
|
|
|
|
| 1262 |
if text == f'prep{sesh.found_terms_4_room_items_idx+1}':
|
| 1263 |
#generateScriptForItem(sesh.found_terms_4_room_items_idx,sesh.found_terms_4_room_items[sesh.found_terms_4_room_items_idx])
|
| 1264 |
generateScriptForItem()
|
| 1265 |
sesh.found_terms_4_room_items_idx += 1
|
|
|
|
| 1266 |
return f'prepped{sesh.found_terms_4_room_items_idx}'
|
| 1267 |
else:
|
|
|
|
| 1268 |
return f'prep{sesh.found_terms_4_room_items_idx} failed'
|
| 1269 |
|
| 1270 |
def updateItem8Status(text, seshid):
|
|
|
|
| 1271 |
if text == f'prepped{sesh.found_terms_4_room_items_idx}':
|
| 1272 |
#print('updateItem8Status: ', sesh.found_terms_4_room_items_idx, len(sesh.found_terms_4_room_items))
|
| 1273 |
sesh.script_status_text = f'{sesh.product_pd_counts[sesh.found_terms_4_room_items_idx-1][0].upper()} script complete.\nPreparing script for {sesh.product_pd_counts[sesh.found_terms_4_room_items_idx][0]}.\nWorking on step {sesh.found_terms_4_room_items_idx+1} of {len(sesh.product_pd_counts)+6}, standby...' if sesh.found_terms_4_room_items_idx < len(sesh.product_pd_counts) else f'{sesh.product_pd_counts[sesh.found_terms_4_room_items_idx-1][0].upper()} script complete.\nPreparing script for Youtube long-form video.\nWorking on step {sesh.found_terms_4_room_items_idx} of {len(sesh.product_pd_counts)+6}, standby...'
|
|
|
|
| 1274 |
return sesh.script_status_text, f'prep{sesh.found_terms_4_room_items_idx+1}'
|
| 1275 |
else:
|
| 1276 |
print(f'prepItem{sesh.found_terms_4_room_items_idx+1}ForScript: fail')
|
|
|
|
| 1277 |
return f'ITEM {sesh.found_terms_4_room_items_idx} prep failed', ''
|
| 1278 |
|
| 1279 |
def prepItem9ForScript(text, seshid):
|
|
|
|
| 1280 |
if text == f'prep{sesh.found_terms_4_room_items_idx+1}':
|
| 1281 |
if sesh.found_terms_4_room_items_idx < len(sesh.product_pd_counts): generateScriptForItem() #generateScriptForItem(sesh.found_terms_4_room_items_idx,sesh.found_terms_4_room_items[sesh.found_terms_4_room_items_idx])
|
| 1282 |
if sesh.found_terms_4_room_items_idx < len(sesh.product_pd_counts): sesh.found_terms_4_room_items_idx += 1
|
|
|
|
| 1283 |
return f'prepped{sesh.found_terms_4_room_items_idx}'
|
| 1284 |
else:
|
|
|
|
| 1285 |
return f'prep{sesh.found_terms_4_room_items_idx} failed'
|
| 1286 |
|
| 1287 |
def updateItem9Status(text, seshid):
|
|
|
|
| 1288 |
if text == f'prepped{sesh.found_terms_4_room_items_idx}':
|
| 1289 |
#print('updateItem9Status: ', sesh.found_terms_4_room_items_idx, len(sesh.found_terms_4_room_items))
|
| 1290 |
sesh.script_status_text = f'{sesh.product_pd_counts[sesh.found_terms_4_room_items_idx-1][0].upper()} script complete.\nPreparing script for {sesh.product_pd_counts[sesh.found_terms_4_room_items_idx][0]}.\nWorking on step {sesh.found_terms_4_room_items_idx+1} of {len(sesh.product_pd_counts)+6}, standby...' if sesh.found_terms_4_room_items_idx < len(sesh.product_pd_counts)-1 else sesh.script_status_text
|
|
|
|
| 1291 |
return sesh.script_status_text, f'prep{sesh.found_terms_4_room_items_idx+1}'
|
| 1292 |
else:
|
| 1293 |
print(f'prepItem{sesh.found_terms_4_room_items_idx+1}ForScript: fail')
|
|
|
|
| 1294 |
return f'ITEM {sesh.found_terms_4_room_items_idx} prep failed', ''
|
| 1295 |
|
| 1296 |
def prepItem10ForScript(text, seshid):
|
|
|
|
| 1297 |
if text == f'prep{sesh.found_terms_4_room_items_idx+1}':
|
| 1298 |
if sesh.found_terms_4_room_items_idx < len(sesh.product_pd_counts): generateScriptForItem() #generateScriptForItem(sesh.found_terms_4_room_items_idx,sesh.found_terms_4_room_items[sesh.found_terms_4_room_items_idx])
|
| 1299 |
if sesh.found_terms_4_room_items_idx < len(sesh.product_pd_counts): sesh.found_terms_4_room_items_idx += 1
|
|
|
|
| 1300 |
return f'prepped{sesh.found_terms_4_room_items_idx}'
|
| 1301 |
else:
|
|
|
|
| 1302 |
return f'prep{sesh.found_terms_4_room_items_idx} failed'
|
| 1303 |
|
| 1304 |
def updateItem10Status(text, seshid):
|
|
|
|
| 1305 |
if text == f'prepped{sesh.found_terms_4_room_items_idx}':
|
| 1306 |
#print('updateItem10Status: ', sesh.found_terms_4_room_items_idx, len(sesh.found_terms_4_room_items))
|
| 1307 |
sesh.script_status_text = f'{sesh.product_pd_counts[sesh.found_terms_4_room_items_idx-1][0].upper()} script complete.\nPreparing script for {sesh.product_pd_counts[sesh.found_terms_4_room_items_idx][0]}.\nWorking on step {sesh.found_terms_4_room_items_idx+1} of {len(sesh.product_pd_counts)+6}, standby...' if sesh.found_terms_4_room_items_idx < len(sesh.product_pd_counts)-1 else sesh.script_status_text
|
|
|
|
| 1308 |
return sesh.script_status_text, f'prep{sesh.found_terms_4_room_items_idx+1}'
|
| 1309 |
else:
|
| 1310 |
print(f'prepItem{sesh.found_terms_4_room_items_idx+1}ForScript: fail')
|
|
|
|
| 1311 |
return f'ITEM {sesh.found_terms_4_room_items_idx} prep failed', ''
|
| 1312 |
|
| 1313 |
def prepItem11ForScript(text, seshid):
|
|
|
|
| 1314 |
if text == f'prep{sesh.found_terms_4_room_items_idx+1}':
|
| 1315 |
if sesh.found_terms_4_room_items_idx < len(sesh.product_pd_counts): generateScriptForItem() #generateScriptForItem(sesh.found_terms_4_room_items_idx,sesh.found_terms_4_room_items[sesh.found_terms_4_room_items_idx])
|
| 1316 |
if sesh.found_terms_4_room_items_idx < len(sesh.product_pd_counts): sesh.found_terms_4_room_items_idx += 1
|
|
|
|
| 1317 |
return f'prepped{sesh.found_terms_4_room_items_idx}'
|
| 1318 |
else:
|
|
|
|
| 1319 |
return f'prep{sesh.found_terms_4_room_items_idx} failed'
|
| 1320 |
|
| 1321 |
def updateItem11Status(text, seshid):
|
|
|
|
| 1322 |
if text == f'prepped{sesh.found_terms_4_room_items_idx}':
|
| 1323 |
#print('updateItem11Status: ', sesh.found_terms_4_room_items_idx, len(sesh.found_terms_4_room_items))
|
| 1324 |
sesh.script_status_text = f'{sesh.product_pd_counts[sesh.found_terms_4_room_items_idx-1][0].upper()} script complete.\nPreparing script for {sesh.product_pd_counts[sesh.found_terms_4_room_items_idx][0]}.\nWorking on step {sesh.found_terms_4_room_items_idx+1} of {len(sesh.product_pd_counts)+6}, standby...' if sesh.found_terms_4_room_items_idx < len(sesh.product_pd_counts)-1 else sesh.script_status_text
|
|
|
|
| 1325 |
return sesh.script_status_text, f'prep{sesh.found_terms_4_room_items_idx+1}'
|
| 1326 |
else:
|
| 1327 |
print(f'prepItem{sesh.found_terms_4_room_items_idx+1}ForScript: fail')
|
|
|
|
| 1328 |
return f'ITEM {sesh.found_terms_4_room_items_idx} prep failed', ''
|
| 1329 |
|
| 1330 |
def prepItem12ForScript(text, seshid):
|
|
|
|
| 1331 |
if text == f'prep{sesh.found_terms_4_room_items_idx+1}':
|
| 1332 |
if sesh.found_terms_4_room_items_idx < len(sesh.product_pd_counts): generateScriptForItem() #generateScriptForItem(sesh.found_terms_4_room_items_idx,sesh.found_terms_4_room_items[sesh.found_terms_4_room_items_idx])
|
| 1333 |
if sesh.found_terms_4_room_items_idx < len(sesh.product_pd_counts): sesh.found_terms_4_room_items_idx += 1
|
|
|
|
| 1334 |
return f'prepped{sesh.found_terms_4_room_items_idx}'
|
| 1335 |
else:
|
|
|
|
| 1336 |
return f'prep{sesh.found_terms_4_room_items_idx} failed'
|
| 1337 |
|
| 1338 |
def updateItem12Status(text, seshid):
|
|
|
|
| 1339 |
if text == f'prepped{sesh.found_terms_4_room_items_idx}':
|
| 1340 |
#print('updateItem12Status: ', sesh.found_terms_4_room_items_idx, len(sesh.found_terms_4_room_items))
|
| 1341 |
sesh.script_status_text = f'{sesh.product_pd_counts[sesh.found_terms_4_room_items_idx-1][0].upper()} script complete.\nPreparing script for {sesh.product_pd_counts[sesh.found_terms_4_room_items_idx][0]}.\nWorking on step {sesh.found_terms_4_room_items_idx+1} of {len(sesh.product_pd_counts)+6}, standby...' if sesh.found_terms_4_room_items_idx < len(sesh.product_pd_counts)-1 else sesh.script_status_text
|
|
|
|
| 1342 |
return sesh.script_status_text, f'prep{sesh.found_terms_4_room_items_idx+1}'
|
| 1343 |
else:
|
| 1344 |
print(f'prepItem{sesh.found_terms_4_room_items_idx+1}ForScript: fail')
|
|
|
|
| 1345 |
return f'ITEM {sesh.found_terms_4_room_items_idx} prep failed', ''
|
| 1346 |
|
| 1347 |
def prepItem13ForScript(text, seshid):
|
|
|
|
| 1348 |
if text == f'prep{sesh.found_terms_4_room_items_idx+1}':
|
| 1349 |
if sesh.found_terms_4_room_items_idx < len(sesh.product_pd_counts): generateScriptForItem() #generateScriptForItem(sesh.found_terms_4_room_items_idx,sesh.found_terms_4_room_items[sesh.found_terms_4_room_items_idx])
|
| 1350 |
if sesh.found_terms_4_room_items_idx < len(sesh.product_pd_counts): sesh.found_terms_4_room_items_idx += 1
|
|
|
|
| 1351 |
return f'prepped{sesh.found_terms_4_room_items_idx}'
|
| 1352 |
else:
|
|
|
|
| 1353 |
return f'prep{sesh.found_terms_4_room_items_idx} failed'
|
| 1354 |
|
| 1355 |
def updateItem13Status(text, seshid):
|
|
|
|
| 1356 |
if text == f'prepped{sesh.found_terms_4_room_items_idx}':
|
| 1357 |
#print('updateItem13Status: ', sesh.found_terms_4_room_items_idx, len(sesh.found_terms_4_room_items))
|
| 1358 |
#print('prepItem13forScript: ', sesh.tg_responses)
|
| 1359 |
sesh.scripts['Base'] = '\n\n'.join(sesh.tg_responses)
|
| 1360 |
sesh.script_status_text = f'{sesh.product_pd_counts[sesh.found_terms_4_room_items_idx-1][0].upper()} script complete.\nPreparing script for {sesh.product_pd_counts[sesh.found_terms_4_room_items_idx][0]}.\nWorking on step {sesh.found_terms_4_room_items_idx+1} of {len(sesh.product_pd_counts)+6}, standby...' if sesh.found_terms_4_room_items_idx < len(sesh.product_pd_counts)-1 else sesh.script_status_text
|
|
|
|
| 1361 |
return sesh.script_status_text, 'prep_ytlong'
|
| 1362 |
else:
|
| 1363 |
print(f'prepItem{sesh.found_terms_4_room_items_idx+1}ForScript: fail')
|
|
|
|
| 1364 |
return f'ITEM {sesh.found_terms_4_room_items_idx} prep failed', ''
|
| 1365 |
|
| 1366 |
|
| 1367 |
def prepYTLongFormScript(text, seshid):
|
|
|
|
| 1368 |
if text == 'prep_ytlong':
|
| 1369 |
prompt = 'SCRIPT: \n\n'+'\n\n'.join(sesh.tg_responses)+f'\n\nTASK: rewrite the provided SCRIPT for a long-form Youtube video. Keep in mind the SCRIPT is about reviewing items to potentially have purchased, shipped and decorate a {sesh.room_type}; this is all for a prospective home buyer -- you are the item reviewer who is reviewing items on behalf of the potential home buyer.'
|
| 1370 |
sesh.scripts['Youtube Long-Form'] = getTextGen(prompt) #client.text_generation(prompt, model="mistralai/Mixtral-8x7B-Instruct-v0.1", max_new_tokens=2500)
|
|
|
|
| 1371 |
return 'ytlong_prepped'
|
| 1372 |
else:
|
|
|
|
| 1373 |
return 'prep_ytlong failed'
|
| 1374 |
|
| 1375 |
def updateYTLongFormStatus(text, seshid):
|
|
|
|
| 1376 |
if text == 'ytlong_prepped':
|
| 1377 |
print('updateYTLongFormStatus: ', list(sesh.scripts))
|
|
|
|
| 1378 |
return f'YOUTUBE LONG-FORM script complete.\nPreparing script for Youtube short-form.\nWorking on step {sesh.found_terms_4_room_items_idx+2} of {len(sesh.product_pd_counts)+6}, standby...', 'prep_ytshort', gr.Dropdown(list(sesh.scripts), label='Scripts', interactive=True)
|
| 1379 |
else:
|
|
|
|
| 1380 |
return 'YT long-form script failed', '', gr.Dropdown(list(sesh.scripts), label='Scripts', interactive=True)
|
| 1381 |
|
| 1382 |
|
| 1383 |
def prepYTShortFormScript(text, seshid):
|
|
|
|
| 1384 |
if text == 'prep_ytshort':
|
| 1385 |
prompt = 'SCRIPT: \n\n'+'\n\n'.join(sesh.tg_responses)+f'\n\nTASK: rewrite the provided SCRIPT for a Youtube Short. Keep in mind the SCRIPT is about reviewing items to potentially have purchased, shipped and decorate a {sesh.room_type}; this is all for a prospective home buyer -- you are the item reviewer who is reviewing items on behalf of the potential home buyer.'
|
| 1386 |
sesh.scripts['Youtube Short-Form'] = getTextGen(prompt) #client.text_generation(prompt, model="mistralai/Mixtral-8x7B-Instruct-v0.1", max_new_tokens=2500)
|
|
|
|
| 1387 |
return 'ytshort_prepped'
|
| 1388 |
else:
|
|
|
|
| 1389 |
return 'prep_ytshort failed'
|
| 1390 |
|
| 1391 |
def updateYTShortFormStatus(text, seshid):
|
|
|
|
| 1392 |
print('updateYTShortFormStatus: ', text, list(sesh.scripts))
|
| 1393 |
if text == 'ytshort_prepped':
|
|
|
|
| 1394 |
return f'YOUTUBE SHORT script complete.\nPreparing script for Facebook.\nWorking on step {sesh.found_terms_4_room_items_idx+3} of {len(sesh.product_pd_counts)+6}, standby...', 'prepfb', gr.Dropdown(list(sesh.scripts), label='Scripts', interactive=True)
|
| 1395 |
else:
|
|
|
|
| 1396 |
return 'YT short-form script failed', '', gr.Dropdown(list(sesh.scripts), label='Scripts', interactive=True)
|
| 1397 |
|
| 1398 |
|
| 1399 |
def prepFBScript(text,seshid):
|
|
|
|
| 1400 |
if text == 'prepfb':
|
| 1401 |
prompt = 'SCRIPT: \n\n'+'\n\n'.join(sesh.tg_responses)+f'\n\nTASK: rewrite the provided SCRIPT for a long-form Facebook video. Keep in mind the SCRIPT is about reviewing items to potentially have purchased, shipped and decorate a {sesh.room_type}; this is all for a prospective home buyer -- you are the item reviewer who is reviewing items on behalf of the potential home buyer.'
|
| 1402 |
sesh.scripts['Facebook Long-Form'] = getTextGen(prompt) #client.text_generation(prompt, model="mistralai/Mixtral-8x7B-Instruct-v0.1", max_new_tokens=2500)
|
|
|
|
| 1403 |
return 'fb_prepped'
|
| 1404 |
else:
|
|
|
|
| 1405 |
return 'prepfb failed'
|
| 1406 |
|
| 1407 |
def updateFBStatus(text, seshid):
|
|
|
|
| 1408 |
print('updateFBStatus: ', text, list(sesh.scripts))
|
| 1409 |
if text == 'fb_prepped':
|
|
|
|
| 1410 |
return f'FACEBOOK script complete.\nPreparing script for Instagram Reel.\nWorking on step {sesh.found_terms_4_room_items_idx+4} of {len(sesh.product_pd_counts)+6}, standby...', 'prepig', gr.Dropdown(list(sesh.scripts), label='Scripts', interactive=True)
|
| 1411 |
else:
|
|
|
|
| 1412 |
return 'Facebook script failed', '', gr.Dropdown(list(sesh.scripts), label='Scripts', interactive=True)
|
| 1413 |
|
| 1414 |
|
|
@@ -1461,8 +1648,9 @@ def updateLinkedInStatus(text, seshid):
|
|
| 1461 |
|
| 1462 |
|
| 1463 |
def selectScript(evt: gr.SelectData, seshid):
|
|
|
|
| 1464 |
script = evt.value
|
| 1465 |
-
return sesh.scripts[script
|
| 1466 |
|
| 1467 |
|
| 1468 |
|
|
|
|
| 197 |
def __init__(self):
|
| 198 |
self.sessions = {}
|
| 199 |
|
| 200 |
+
all_sesh = AllSessions()
|
| 201 |
|
| 202 |
+
def getSesh(seshid):
|
| 203 |
+
if seshid not in all_sesh:
|
| 204 |
+
all_sesh[seshid] = Session()
|
| 205 |
+
sesh = all_sesh[seshid]
|
| 206 |
+
return sesh
|
| 207 |
+
|
| 208 |
+
def setSesh(seshid, sesh):
|
| 209 |
+
all_sesh[seshid] = sesh
|
| 210 |
|
| 211 |
def submitPhoto(img, rooms, seshid):
|
| 212 |
print('submitPhoto reset rooms: ', rooms, seshid)
|
| 213 |
seshid = str(time.time()) if not seshid or seshid == 'SESHID' else seshid
|
| 214 |
+
sesh = getSesh(seshid)
|
| 215 |
#sesh.reset = True
|
| 216 |
sesh.current_img_signature = str(img.sum())
|
| 217 |
sesh.img_data[sesh.current_img_signature] = img
|
|
|
|
| 227 |
rooms.append((img, sesh.current_img_signature))
|
| 228 |
print('submitPhoto reset: ', sesh.reset)
|
| 229 |
#return [(v,str(k)) for k,v in sesh.img_data.items()], gr.Image(label='Upload Room Photo
|
| 230 |
+
setSesh(seshid, sesh)
|
| 231 |
return rooms, gr.Image(label='Upload Room Photo'), seshid
|
| 232 |
|
| 233 |
def summarisePerStore(seshid):
|
| 234 |
+
sesh = getSesh(seshid)
|
| 235 |
sesh.summary_joined = {}
|
| 236 |
for imgid,product_dicts in sesh.summary.items():
|
| 237 |
for item_pd in product_dicts:
|
|
|
|
| 246 |
sesh.summary_joined[store]['descriptions'].append(pd['description'])
|
| 247 |
sesh.summary_joined[store]['sources'].append(pd['href'])
|
| 248 |
sesh.summary_joined[store]['num_items'] += 1
|
| 249 |
+
setSesh(seshid, sesh)
|
| 250 |
|
| 251 |
|
| 252 |
def summarisePerStore(seshid):
|
| 253 |
+
sesh = getSesh(seshid)
|
| 254 |
sesh.summary_joined = {}
|
| 255 |
for imgid,product_dicts in sesh.summary.items():
|
| 256 |
for item_pd in product_dicts:
|
|
|
|
| 262 |
sesh.summary_joined[store] = {}
|
| 263 |
|
| 264 |
sesh.summary_joined[store][item] = {'product_dict': pd, 'count':1}
|
| 265 |
+
setSesh(seshid, sesh)
|
| 266 |
|
| 267 |
|
| 268 |
def updateItemDisplay(seshid, budget=False):
|
| 269 |
+
sesh = getSesh(seshid)
|
| 270 |
+
|
| 271 |
if True:
|
| 272 |
keys = ['filtered_items_room', 'current_img_signature', 'items', 'filtered_items_style', 'room_style', 'room_type', 'bedsize', 'price', 'filtered_items_colors', 'Palette_ids', 'item_data', 'item_data_', 'display_items', 'item_data_keys', 'Palettes_displayed', 'room_img_loaded', 'Paletteid', 'img_id', 'seshid']
|
| 273 |
url = 'https://dreamdemo.pythonanywhere.com/sesh'
|
|
|
|
| 339 |
sesh.updated_display = realised_display
|
| 340 |
summarisePerStore(seshid)
|
| 341 |
|
| 342 |
+
setSesh(seshid, sesh)
|
| 343 |
|
| 344 |
return gr.Gallery(realised_display, label='Room Items', columns=5)
|
| 345 |
else: #except:
|
| 346 |
+
setSesh(seshid, sesh)
|
| 347 |
return sesh.updated_display
|
| 348 |
|
| 349 |
def getMostUsedColorsRGB(img_bytes):
|
|
|
|
| 383 |
return False
|
| 384 |
|
| 385 |
def updateItemDisplay(seshid, budget=False, pallete_change=False):
|
| 386 |
+
sesh = getSesh(seshid)
|
| 387 |
if True:
|
| 388 |
keys = ['filtered_items_room', 'current_img_signature', 'items', 'filtered_items_style', 'room_style', 'room_type', 'bedsize', 'price', 'filtered_items_colors', 'Palette_ids', 'item_data', 'item_data_', 'display_items', 'item_data_keys', 'Palettes_displayed', 'room_img_loaded', 'Paletteid', 'img_id', 'seshid']
|
| 389 |
url = 'https://dreamdemo.pythonanywhere.com/sesh'
|
|
|
|
| 512 |
sesh.updated_display = realised_display
|
| 513 |
summarisePerStore(seshid)
|
| 514 |
|
| 515 |
+
setSesh(seshid, sesh)
|
| 516 |
return gr.Gallery(realised_display, label='Room Items', columns=5)
|
| 517 |
else: #except:
|
| 518 |
+
setSesh(seshid, sesh)
|
| 519 |
return sesh.updated_display
|
| 520 |
|
| 521 |
|
| 522 |
def updateRoomType(evt: gr.SelectData, seshid):
|
| 523 |
+
sesh = getSesh(seshid)
|
| 524 |
label = evt.value['caption'].lower().split()[0] if evt.value['caption'] else sesh.room_type
|
| 525 |
sesh.room_type = label
|
| 526 |
images = [(v['bedroom'] if sesh.room_type == 'bedroom' else v['living room'], k) for k,v in styles_images.items()]
|
|
|
|
| 533 |
display = updateItemDisplay(seshid)
|
| 534 |
else:
|
| 535 |
display = sesh.updated_display
|
| 536 |
+
setSesh(seshid, sesh)
|
| 537 |
|
| 538 |
return images, gr.Radio(['Full', 'Queen', 'King'], value='Full', label='Bed Size', interactive=True, visible=True) if label == 'bedroom' else gr.Radio(visible=False), gr.Gallery(sesh.updated_display, label='Room Items', columns=5), display
|
| 539 |
|
| 540 |
|
| 541 |
def updateStyle(evt: gr.SelectData, seshid):
|
| 542 |
+
sesh = getSesh(seshid)
|
| 543 |
style = evt.value['caption'].lower().split()[0] if evt.value['caption'] else sesh.room_style
|
| 544 |
sesh.room_style = style
|
| 545 |
|
| 546 |
if hasattr(sesh, 'room_img_loaded') and sesh.room_img_loaded:
|
| 547 |
display = updateItemDisplay(seshid)
|
| 548 |
+
setSesh(seshid, sesh)
|
| 549 |
return display
|
| 550 |
else:
|
| 551 |
+
setSesh(seshid, sesh)
|
| 552 |
return sesh.updated_display
|
| 553 |
|
| 554 |
def updatePrice(evt: gr.SelectData, seshid):
|
| 555 |
+
sesh = getSesh(seshid)
|
| 556 |
print('updatePrice: ', type(evt.value), evt.value)
|
| 557 |
price = evt.value if evt.value else sesh.price
|
| 558 |
sesh.price = price
|
|
|
|
| 560 |
|
| 561 |
if hasattr(sesh, 'room_img_loaded') and sesh.room_img_loaded:
|
| 562 |
display = updateItemDisplay(seshid)
|
| 563 |
+
setSesh(seshid, sesh)
|
| 564 |
return display
|
| 565 |
else:
|
| 566 |
+
setSesh(seshid, sesh)
|
| 567 |
return sesh.updated_display
|
| 568 |
|
| 569 |
|
| 570 |
def updateBedsize(evt: gr.SelectData, seshid):
|
| 571 |
+
sesh = getSesh(seshid)
|
| 572 |
bedsize = evt.value if evt.value else sesh.bedsize
|
| 573 |
sesh.bedsize = bedsize
|
| 574 |
|
| 575 |
|
| 576 |
if hasattr(sesh, 'room_img_loaded') and sesh.room_img_loaded:
|
| 577 |
display = updateItemDisplay(seshid)
|
| 578 |
+
setSesh(seshid, sesh)
|
| 579 |
return display
|
| 580 |
else:
|
| 581 |
+
setSesh(seshid, sesh)
|
| 582 |
return sesh.updated_display
|
| 583 |
|
| 584 |
|
| 585 |
#sesh.palettes_data
|
| 586 |
def updateColors(evt: gr.SelectData, seshid):
|
| 587 |
+
sesh = getSesh(seshid)
|
| 588 |
Paletteid = evt.value['caption'] if evt.value['caption'] else '0'
|
| 589 |
sesh.Paletteid = evt.value['caption']
|
| 590 |
sesh.Palette_ids[sesh.current_img_signature] = Paletteid
|
|
|
|
| 597 |
|
| 598 |
if hasattr(sesh, 'room_img_loaded') and sesh.room_img_loaded:
|
| 599 |
display = updateItemDisplay(seshid, pallete_change=True)
|
| 600 |
+
setSesh(seshid, sesh)
|
| 601 |
return display
|
| 602 |
else:
|
| 603 |
+
setSesh(seshid, sesh)
|
| 604 |
return sesh.updated_display
|
| 605 |
|
| 606 |
|
|
|
|
| 609 |
#Palettes_displayed, Palettes
|
| 610 |
|
| 611 |
def makePalettes(evt: gr.SelectData, seshid):
|
| 612 |
+
sesh = getSesh(seshid)
|
| 613 |
#print('makePalettes: ', type(evt.value), evt.value)
|
| 614 |
sesh.img_id = sesh.current_img_signature = evt.value['caption'] if evt.value['caption'] else sesh.current_img_signature
|
| 615 |
if sesh.current_img_signature in sesh.Palettes_displayed:
|
|
|
|
| 678 |
sesh.Palettes_displayed[sesh.current_img_signature] = Palette_out
|
| 679 |
|
| 680 |
sesh.room_img_loaded = True
|
| 681 |
+
setSesh(seshid, sesh)
|
| 682 |
|
| 683 |
return Palette_out, sesh.img_data[sesh.img_id], display
|
| 684 |
|
| 685 |
#directory
|
| 686 |
def set_Palette(evt: gr.SelectData, seshid):
|
| 687 |
+
sesh = getSesh(seshid)
|
| 688 |
sesh.Paletteid = evt.value['caption']
|
| 689 |
sesh.Palette_img = np.zeros((200,200,3)).astype(np.uint8)
|
| 690 |
sesh.Palette_img[:50,:] = sesh.Palettes[sesh.img_id][sesh.Paletteid][0][0]
|
|
|
|
| 694 |
|
| 695 |
sesh.Palette_imgs[sesh.img_id] = sesh.Palette_img
|
| 696 |
sesh.Palette_ids[sesh.img_id] = sesh.Paletteid
|
| 697 |
+
setSesh(seshid, sesh)
|
| 698 |
|
| 699 |
|
| 700 |
def set_style(evt: gr.SelectData, seshid):
|
| 701 |
+
sesh = getSesh(seshid)
|
| 702 |
label = evt.value['caption'].lower().split()[0]
|
| 703 |
sesh.room_type = label
|
| 704 |
images = [(v['bedroom'] if label == 'bedroom' else v['living room'], k) for k,v in styles_images.items()]
|
|
|
|
| 709 |
|
| 710 |
room_items_imgs_tuples = [((sesh.Palette_img if item == 'Palette' else sesh.img_data[sesh.img_id]) if item in ['Palette', 'Living Room', 'Bedroom'] else room_item_placeholder_images_dict['BEDROOM FURNITURE' if label == 'bedroom' else 'LIVING ROOM FURNITURE'][item], item) for item in items]
|
| 711 |
|
| 712 |
+
setSesh(seshid, sesh)
|
| 713 |
return images, gr.Radio(['Full', 'Queen', 'King'], value='Full', label='Bed Size', interactive=True, visible=True) if label == 'bedroom' else gr.Radio(visible=False), gr.Gallery(room_items_imgs_tuples, label='Room Items', columns=5)
|
| 714 |
|
| 715 |
|
| 716 |
def applyStyle(evt: gr.SelectData, seshid):
|
| 717 |
+
sesh = getSesh(seshid)
|
| 718 |
design_style = evt.value['caption'].lower().split()[0]
|
| 719 |
|
| 720 |
sesh.filtered_files_style[sesh.img_id] = {color: [f for f in cfiles if any([(lambda substrs, f: substrs and substrs[0].lower() in f.lower() and (len(substrs)==1 or substrs[1] in f.lower()))(substr.replace('-', ' ').split(), f) for substr in design_style.split()])] for color,cfiles in sesh.filtered_files_room[sesh.img_id].items()}
|
|
|
|
| 733 |
|
| 734 |
room_items_imgs_tuples = [((sesh.Palette_img if item == 'Palette' else sesh.img_data[sesh.img_id]) if item in ['Palette', 'Living Room', 'Bedroom'] else room_item_placeholder_images_dict['BEDROOM FURNITURE' if sesh.room_type == 'bedroom' else 'LIVING ROOM FURNITURE'][item], item) for item in sesh.items]
|
| 735 |
|
| 736 |
+
setSesh(seshid, sesh)
|
| 737 |
return gr.Gallery(room_items_imgs_tuples, label='Room Items', columns=5)
|
| 738 |
|
| 739 |
|
| 740 |
def roomItemClick(evt: gr.SelectData, seshid):
|
| 741 |
+
sesh = getSesh(seshid)
|
| 742 |
selection = evt.value['caption'].lower()
|
| 743 |
seshidtype = '...'+str(type(seshid))+ '...'
|
| 744 |
seshid_ = '...'+str(seshid)+ '...'
|
| 745 |
seshid = str(time.time()) if not seshid or seshid == 'SESHID' else seshid
|
| 746 |
sesh.clicked_displayed_product = evt.value['caption']
|
| 747 |
+
setSesh(seshid, sesh)
|
| 748 |
if selection == 'palette':
|
| 749 |
return gr.Column(scale=4), gr.update(visible=bool(0)), gr.update(visible=bool(0)), gr.update(visible=bool(1)), gr.Gallery(visible=False), gr.Label('Dream Home: As Quick As A Click. As Simple As Shopping.', label='Sponsors'), gr.update(visible=bool(0)), seshid
|
| 750 |
elif selection in ['living room', 'bedroom']:
|
|
|
|
| 759 |
|
| 760 |
|
| 761 |
def closeSidePanel(seshid):
|
| 762 |
+
sesh = getSesh(seshid)
|
| 763 |
+
setSesh(seshid, sesh)
|
| 764 |
return gr.Column(scale=5), gr.update(visible=bool(0)), gr.update(visible=bool(0)), gr.update(visible=bool(0)), gr.Label('No Item Selected', label='Merchant'), gr.Gallery(visible=False), gr.Label('Dream Home: As Quick As A Click. As Simple As Shopping.', label='Sponsors', visible=True), gr.update(visible=bool(0))
|
| 765 |
|
| 766 |
|
| 767 |
|
| 768 |
def productClick(evt: gr.SelectData, seshid):
|
| 769 |
+
sesh = getSesh(seshid)
|
| 770 |
if not sesh.clicked_displayed_product:
|
| 771 |
return gr.Label('No Item Selected', label='Merchant')
|
| 772 |
product_idx = evt.index
|
| 773 |
sesh.product_idx = evt.index
|
| 774 |
product = sesh.item_data[sesh.current_img_signature][sesh.room_type][sesh.room_style][sesh.price][sesh.Paletteid][sesh.clicked_displayed_product][product_idx]
|
| 775 |
sesh.product = product
|
| 776 |
+
setSesh(seshid, sesh)
|
| 777 |
return gr.Label(product['store'].split('-')[0], label='Merchant')
|
| 778 |
|
| 779 |
def replaceProduct(seshid):
|
| 780 |
+
sesh = getSesh(seshid)
|
| 781 |
item_idx = sesh.items.index(sesh.clicked_displayed_product)
|
| 782 |
sesh.updated_display[item_idx] = (sesh.product['img'], sesh.clicked_displayed_product)
|
| 783 |
#sesh.display_items[sesh.current_img_signature][sesh.room_type][sesh.room_style][sesh.price][sesh.Paletteid][item_idx] = (sesh.product_idx, sesh.clicked_displayed_product) if sesh.product_idx in sesh.inbudget[sesh.current_img_signature][sesh.clicked_displayed_product] else sesh.display_items[sesh.current_img_signature][sesh.room_type][sesh.room_style][sesh.price][sesh.Paletteid][item_idx]
|
|
|
|
| 794 |
|
| 795 |
#print('replaceProduct: ', sesh.product_idx, sesh.clicked_displayed_product, sesh.product_idx in sesh.inbudget[sesh.current_img_signature][sesh.clicked_displayed_product], sesh.display_items_, sum([float(item_product[1]['price'].replace('$', '').replace(',', '')) for img in sesh.summary for item_product in sesh.summary[img] if item_product]))
|
| 796 |
|
| 797 |
+
setSesh(seshid, sesh)
|
| 798 |
return gr.Column(scale=5), gr.update(visible=bool(0)), gr.update(visible=bool(0)), gr.update(visible=bool(0)), gr.Label('No Item Selected', label='Merchant'), gr.Gallery(visible=False), gr.Label('Dream Home: As Quick As A Click. As Simple As Shopping.', label='Sponsors', visible=True), gr.Gallery(sesh.updated_display, label='Room Items', columns=5)
|
| 799 |
|
| 800 |
|
| 801 |
def selectMerchantItemCountAndTotal(store, seshid):
|
| 802 |
+
sesh = getSesh(seshid)
|
| 803 |
num_items = 0
|
| 804 |
total = 0
|
| 805 |
for item in sesh.summary_joined[store]:
|
|
|
|
| 807 |
price = sesh.summary_joined[store][item][description]['product_dict']['price']
|
| 808 |
count = sesh.summary_joined[store][item][description]['count']
|
| 809 |
total += float(price.replace('$', '').replace(',', '')) * count
|
| 810 |
+
num_items += count
|
| 811 |
+
setSesh(seshid, sesh)
|
| 812 |
return num_items, total
|
| 813 |
|
| 814 |
def selectMerchantItemCountAndTotal(store, seshid):
|
| 815 |
+
sesh = getSesh(seshid)
|
| 816 |
num_items = 0
|
| 817 |
total = 0
|
| 818 |
for item in sesh.summary_joined[store]:
|
| 819 |
price = sesh.summary_joined[store][item]['product_dict']['price']
|
| 820 |
count = sesh.summary_joined[store][item]['count']
|
| 821 |
total += float(price.replace('$', '').replace(',', '')) * count
|
| 822 |
+
num_items += count
|
| 823 |
+
setSesh(seshid, sesh)
|
| 824 |
return num_items, total
|
| 825 |
|
| 826 |
from huggingface_hub import InferenceClient
|
|
|
|
| 836 |
return []
|
| 837 |
|
| 838 |
def summaryClick(seshid):
|
| 839 |
+
sesh = getSesh(seshid)
|
| 840 |
#from pathlib import Path
|
| 841 |
sesh.counts_totals = {store:selectMerchantItemCountAndTotal(store) for store in sesh.summary_joined}
|
| 842 |
all_counts = str(sum([ct[0] for store,ct in sesh.counts_totals.items()]))
|
|
|
|
| 848 |
#store_data = {store: (lambda data: '' if not data or 'zipcode' not in data[0] else '\n'.join([str(d) for d in data]))(retrieveProcessedStoreData(store)) for store in sesh.summary_joined}
|
| 849 |
item_summary_data = '\n\n'.join(['STORE: '+store+'\n'+('\tLOCATIONS: N/A' if not store_data[store] else '\tLOCATIONS: \n'+store_data[store])+''.join(['\n\tPRODUCT: '+ product +'\n\tPRICE: '+pd_count['product_dict']['price']+'\n\tSOURCE: '+pd_count['product_dict']['href'] for product,pd_count in sesh.summary_joined[store].items()]) for store in sesh.summary_joined])
|
| 850 |
print('store summary: ', {store: retrieveProcessedStoreData(store) for store in sesh.summary_joined})
|
| 851 |
+
setSesh(seshid, sesh)
|
| 852 |
return gr.Button('Suppress Summary'), gr.update(visible=bool(0)), gr.update(visible=bool(0)), gr.update(visible=bool(0)), gr.update(visible=bool(1)), gr.update(visible=bool(0)), gr.update(visible=bool(0)), gr.update(visible=bool(1)), gr.Dropdown(list(sesh.summary_joined), label='Merchants', interactive=True), gr.Label('All', label='Merchant'), gr.Label(all_counts, label='Number of Items'), gr.Label('$'+str(np.round(all_totals, 2)), label='Total'), item_summary_data
|
| 853 |
|
| 854 |
#'\n\n'.join(['Store: '+store+'\n\n'+'\n\n'.join(['\n\tProduct: '+ product +'\n\tPrice: '+pd_count['product_dict']['price']+'\n\tSource: '+pd_count['product_dict']['href'] for product,pd_count in sesh.summary_joined[store].items()]) for store in sesh.summary_joined])
|
| 855 |
else:
|
| 856 |
sesh.summary_closed = True
|
| 857 |
+
setSesh(seshid, sesh)
|
| 858 |
return gr.Button('Summarise'), gr.update(visible=bool(1)), gr.update(visible=bool(1)), gr.update(visible=bool(1)), gr.update(visible=bool(0)), gr.update(visible=bool(0)), gr.update(visible=bool(1)), gr.update(visible=bool(0)), gr.Dropdown(), gr.Label(), gr.Label(), gr.Label(), ''
|
| 859 |
|
| 860 |
|
| 861 |
def selectMerchantProduct(evt: gr.SelectData, seshid):
|
| 862 |
+
sesh = getSesh(seshid)
|
| 863 |
store = evt.value
|
| 864 |
sesh.summary_store = store
|
| 865 |
|
| 866 |
#print('selectMerchantProduct -- counts_totals: ', counts_totals)
|
| 867 |
+
setSesh(seshid, sesh)
|
| 868 |
return gr.Dropdown(list(sesh.summary_joined[store]), label='Items', interactive=True), gr.Label(sesh.summary_store if sesh.summary_store else 'All', label='Merchant'), gr.Label(str(sesh.counts_totals[store][0]), label='Number of Items'), gr.Label('$'+str(np.round(sesh.counts_totals[store][1], 2)), label='Total')
|
| 869 |
|
| 870 |
|
|
|
|
| 894 |
return {}
|
| 895 |
|
| 896 |
def changeSummaryFilter(evt: gr.SelectData, seshid):
|
| 897 |
+
sesh = getSesh(seshid)
|
| 898 |
summary_radio = evt.value
|
| 899 |
print('changeSummaryFilter: ', summary_radio)
|
| 900 |
sesh.summary_radio = summary_radio
|
|
|
|
| 903 |
#if summary_radio == 'Complete' or not hasattr(sesh, 'summary_store'):
|
| 904 |
if summary_radio == 'Complete':
|
| 905 |
print('changeSummaryFilter: in Complete')
|
| 906 |
+
setSesh(seshid, sesh)
|
| 907 |
return gr.Label('All', label='Merchant'), gr.Label(all_counts, label='Number of Items'), gr.Label('$'+str(np.round(all_totals, 2)), label='Total'), gr.update(visible=bool(0)), gr.update(visible=bool(1)), gr.update(visible=bool(1)), gr.update(visible=bool(0))
|
| 908 |
elif summary_radio == 'Script':
|
| 909 |
#textgen for general audience, things to look out for or be aware of
|
|
|
|
| 968 |
#prompt = preprompt+"\n\nTask: Referencing the ITEMS provided -- each item DESCRIPTION, in particular -- create an audio script about shopping to decorate a room, writing to prompt the listener for their feedback as to whether the items chosen are choices they might have made; where applicable, incorporate the corresponding ITEM TOPICS to the item DESCRIPTION being written about, and do so in a way that is informing the listener of what they might expect during the ordering process. Reference the ITEM TOPICS in a fun way as if you are engaging in small talk, making remarks to the respective ITEM TOPIC in a 'just a heads up' tangent and then getting back on script. Write in the past tense, like we have already decorated and are now reviewing the items chosen to outfit the room, speculating as to the listener's stance on the items chosen, whether they would like the ITEM being spoken about and why (be creative, thinking of random reasons the listener would or would not like the ITEM chosen). Write in an informal style."
|
| 969 |
|
| 970 |
end = time.time()
|
| 971 |
+
setSesh(seshid, sesh)
|
| 972 |
return gr.Label('All', label='Merchant'), gr.Label(all_counts, label='Number of Items'), gr.Label('$'+str(np.round(all_totals, 2)), label='Total'), gr.update(visible=bool(0)), gr.update(visible=bool(1)), gr.update(visible=bool(1)), gr.update(visible=bool(0))
|
| 973 |
else:
|
| 974 |
+
setSesh(seshid, sesh)
|
| 975 |
return gr.Label(sesh.summary_store if hasattr(sesh, 'summary_store') and sesh.summary_store else 'All', label='Merchant'), gr.Label(str(sesh.counts_totals[sesh.summary_store][0]) if hasattr(sesh, 'summary_store') and sesh.summary_store else '--', label='Number of Items'), gr.Label('$'+str(np.round(sesh.counts_totals[sesh.summary_store][1], 2)) if hasattr(sesh, 'summary_store') and sesh.summary_store else '--', label='Total'), gr.update(visible=bool(1)), gr.update(visible=bool(0)), gr.update(visible=bool(0)), gr.update(visible=bool(1))
|
| 976 |
|
| 977 |
|
| 978 |
|
| 979 |
def displaySource(evt: gr.SelectData, seshid):
|
| 980 |
+
sesh = getSesh(seshid)
|
| 981 |
product = evt.value
|
| 982 |
sesh.summary_product = product
|
| 983 |
#sources = '\n\n'.join(['Price: '+pd_count['product_dict']['price']+'\n\nSource: '+pd_count['product_dict']['href'] for description_key,pd_count in sesh.summary_joined[sesh.summary_store][product].items()])
|
| 984 |
sources = 'Price: '+sesh.summary_joined[sesh.summary_store][product]['product_dict']['price']+'\n\nSource: '+sesh.summary_joined[sesh.summary_store][product]['product_dict']['href']
|
| 985 |
+
setSesh(seshid, sesh)
|
| 986 |
return gr.Markdown(sources), gr.Number(value=sesh.summary_joined[sesh.summary_store][product]['count'], label='Item Count', minimum=0)
|
| 987 |
|
| 988 |
def updateProductCount(count, seshid):
|
| 989 |
+
sesh = getSesh(seshid)
|
| 990 |
sesh.summary_joined[sesh.summary_store][sesh.summary_product]['count'] = count
|
| 991 |
sesh.counts_totals = {store:selectMerchantItemCountAndTotal(store) for store in sesh.summary_joined}
|
| 992 |
all_counts = str(sum([ct[0] for store,ct in sesh.counts_totals.items()]))
|
| 993 |
all_totals = sum([ct[1] for store,ct in sesh.counts_totals.items()])
|
| 994 |
|
| 995 |
+
setSesh(seshid, sesh)
|
| 996 |
return gr.Label(str(sesh.counts_totals[sesh.summary_store][0]) if sesh.summary_store and sesh.summary_radio != 'Complete' else all_counts, label='Number of Items'), gr.Label('$'+str(np.round(sesh.counts_totals[sesh.summary_store][1], 2)) if sesh.summary_store and sesh.summary_radio != 'Complete' else '$'+str(np.round(all_totals, 2)), label='Total')
|
| 997 |
|
| 998 |
def updateBudget(budget_number, seshid):
|
| 999 |
+
sesh = getSesh(seshid)
|
| 1000 |
sesh.budget_number = float(budget_number)
|
| 1001 |
#sesh.item_budgets = {img: {item: int(weight*sesh.budget_number) for item,weight in weights.items()} for img,weights in sesh.product_means_weights.items()}
|
| 1002 |
#print('updateBudget: ', sesh.budget_number, sesh.item_budgets)
|
|
|
|
| 1005 |
sesh.counts_totals = {store:selectMerchantItemCountAndTotal(store) for store in sesh.summary_joined}
|
| 1006 |
all_counts = str(sum([ct[0] for store,ct in sesh.counts_totals.items()]))
|
| 1007 |
all_totals = sum([ct[1] for store,ct in sesh.counts_totals.items()])
|
| 1008 |
+
setSesh(seshid, sesh)
|
| 1009 |
return display, gr.Label(all_counts, label='Number of Items'), gr.Label('$'+str(np.round(all_totals, 2)), label='Total')
|
| 1010 |
|
| 1011 |
|
|
|
|
| 1022 |
templates = {0:['For ITEM, we went with the ITEM DESCRIPTION. SPECULATED RESPONSE.', 'SPECULATED RESPONSE, so for ITEM we went with the ITEM DESCRIPTION.'], 1:['For ITEM, we went with the ITEM DESCRIPTION. ITEM TOPIC. SPECULATED RESPONSE.', 'SPECULATED RESPONSE, so for ITEM we went with the ITEM DESCRIPTION. ITEM TOPIC.'], 2:['For ITEM, we went with the ITEM DESCRIPTION. ITEM TOPICS. SPECULATED RESPONSE.', 'SPECULATED RESPONSE, so for ITEM we went with the ITEM DESCRIPTION. ITEM TOPICS.']}
|
| 1023 |
|
| 1024 |
def makeItemPrompt(idx,data, seshid):
|
| 1025 |
+
sesh = getSesh(seshid)
|
| 1026 |
template = templates[len(data[1]) if len(data[1])<2 else 2][np.random.choice([0,1])]
|
| 1027 |
prompt = sesh.items_prepped[idx]+'\n\nTEMPLATE: '+template+"\n\nTASK: adapt TEMPLATE using the ITEM/DESCRIPTION/STORE info provided, where SPECULATED RESPONSE is your creative guess as to the reader's stance on the items chosen, whether they would like the ITEM being written about and why (be creative, thinking of random reasons the reader would or would not like the ITEM chosen). Write from the perspective of reporting to someone who is considering purchasing a home and you are presenting different decorative options that might persuade them to buy the home; so, make sure your wording reflects this -- 'if you go with...', 'now keep in mind...', 'were you to purchase this home...' and the like are examples of how you might word things. You don't have to use these examples exactly, just word things similarly. Be creative."
|
| 1028 |
if data[1]:
|
|
|
|
| 1035 |
prompt += "Keep in mind this is the last of many items we are reviewing, so ensure your writing reflects the fact that this is the final item being reported on and do a review wrap-up/send off for this particular room's decor review. Maybe begin by writing something along the lines of 'Okay lastly we have the...' or 'Well, our final item is...' or what have you are examples of how you might word things. You don't have to use these examples exactly, just word things similarly. Be creative."
|
| 1036 |
else:
|
| 1037 |
prompt += "Keep in mind this is the one of many items we have already reviewed and one of other yet to be reviewed, so ensure your writing reflects the fact that this is just the next item being reported on. Maybe begin by writing something along the lines of 'Okay now we have...' or 'So next up is...' or what have you are examples of how you might word things. You don't have to use these examples exactly, just word things similarly. Be creative."
|
| 1038 |
+
setSesh(seshid, sesh)
|
| 1039 |
return prompt
|
| 1040 |
|
| 1041 |
def generateScriptForItem(idx,data, seshid):
|
| 1042 |
+
sesh = getSesh(seshid)
|
| 1043 |
prompt = makeItemPrompt(idx,data)
|
| 1044 |
#tg_response = client.text_generation(prompt, model="mistralai/Mixtral-8x7B-Instruct-v0.1", max_new_tokens=2500)
|
| 1045 |
tg_response = getTextGen(prompt)
|
| 1046 |
tg_response = tg_response.replace("I know what you're thinking", np.random.choice(alarm3)).replace("I know what you're thinking", np.random.choice(alarm3))
|
| 1047 |
sesh.tg_responses.append(tg_response)
|
| 1048 |
+
setSesh(seshid, sesh)
|
| 1049 |
|
| 1050 |
def generateScriptForItem(seshid):
|
| 1051 |
+
sesh = getSesh(seshid)
|
| 1052 |
url = 'https://dreamdemo.pythonanywhere.com/script_gen'
|
| 1053 |
valid_data = {'room_type': sesh.room_type, 'idx': sesh.found_terms_4_room_items_idx, 'gen_uid': sesh.gen_uid}
|
| 1054 |
headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}
|
|
|
|
| 1057 |
tg_response = jsondata['response']
|
| 1058 |
print('generateScriptForItem from endpoint: ', tg_response)
|
| 1059 |
sesh.tg_responses.append(tg_response)
|
| 1060 |
+
setSesh(seshid, sesh)
|
| 1061 |
|
| 1062 |
def loadColorAndCharacter(text, seshid):
|
| 1063 |
+
sesh = getSesh(seshid)
|
| 1064 |
if text == 'load':
|
| 1065 |
sesh.product_pd_counts = [(product,pd_count) for store in sesh.summary_joined for product,pd_count in sesh.summary_joined[store].items()]
|
| 1066 |
sesh.tg_responses = []
|
|
|
|
| 1098 |
responses = asyncio.run(main_post(urls, headers, json_data, timeout=1))
|
| 1099 |
except:
|
| 1100 |
pass
|
| 1101 |
+
setSesh(seshid, sesh)
|
| 1102 |
return 'loaded'
|
| 1103 |
else:
|
| 1104 |
+
setSesh(seshid, sesh)
|
| 1105 |
return 'not loaded'
|
| 1106 |
|
| 1107 |
|
| 1108 |
def searchColorAndCharacter(text, seshid):
|
| 1109 |
+
sesh = getSesh(seshid)
|
| 1110 |
if text == 'search':
|
| 1111 |
"""url = 'https://dreamdemo.pythonanywhere.com/shopping'
|
| 1112 |
sesh.gen_uid = str(time.time())
|
|
|
|
| 1165 |
#item_prompts = [makeItemPrompt(idx,idata) for idx,idata in enumerate(sesh.found_terms_4_room_items[sesh.found_terms_4_room_items_idx])]
|
| 1166 |
#item_scripts = multiprocessPrompts(item_prompts)
|
| 1167 |
#print('searchColorAndCharacter: ', item_scripts)
|
| 1168 |
+
setSesh(seshid, sesh)
|
| 1169 |
return 'searched'
|
| 1170 |
else:
|
| 1171 |
+
setSesh(seshid, sesh)
|
| 1172 |
return 'not searched'
|
| 1173 |
|
| 1174 |
|
| 1175 |
|
| 1176 |
def updateLinksLoadStatus(text, seshid):
|
| 1177 |
+
sesh = getSesh(seshid)
|
| 1178 |
+
setSesh(seshid, sesh)
|
| 1179 |
if text == 'loaded':
|
| 1180 |
print('LOADED color and character for script\nadding color and character to script\nstandby...')
|
| 1181 |
return 'LOADED color and character\nadding color and character to scripts\nstandby...', 'search'
|
|
|
|
| 1183 |
return 'searched color and character for script\npreparing script for item1\nstandby...update this', ''
|
| 1184 |
|
| 1185 |
def updateLinksSearchStatus(text, seshid):
|
| 1186 |
+
sesh = getSesh(seshid)
|
| 1187 |
+
setSesh(seshid, sesh)
|
| 1188 |
if text == 'searched':
|
| 1189 |
print('ADDED color and character for script\npreparing script for item1\nstandby...')
|
| 1190 |
#return f'ADDED color and character for script\npreparing script for {sesh.product_pd_counts[0][0]}\nWorking on step {sesh.found_terms_4_room_items_idx+1} of {len(sesh.product_pd_counts)+6}, standby......', 'prep1'
|
|
|
|
| 1193 |
return 'searched color and character for script\npreparing script for item1\nstandby...update this', ''
|
| 1194 |
|
| 1195 |
def prepAllScripts(text, seshid):
|
| 1196 |
+
sesh = getSesh(seshid)
|
| 1197 |
+
|
| 1198 |
if text == f'prep{sesh.found_terms_4_room_items_idx+1}':
|
| 1199 |
script_prompts = {'Youtube Long-Form': 'SCRIPT: \n\n'+'\n\n'.join(sesh.tg_responses)+f'\n\nTASK: rewrite the provided SCRIPT for a long-form Youtube video. Keep in mind the SCRIPT is about reviewing items to potentially have purchased, shipped and decorate a {sesh.room_type}; this is all for a prospective home buyer -- you are the item reviewer who is reviewing items on behalf of the potential home buyer.', 'Youtube Short-Form': 'SCRIPT: \n\n'+'\n\n'.join(sesh.tg_responses)+f'\n\nTASK: rewrite the provided SCRIPT for a Youtube Short. Keep in mind the SCRIPT is about reviewing items to potentially have purchased, shipped and decorate a {sesh.room_type}; this is all for a prospective home buyer -- you are the item reviewer who is reviewing items on behalf of the potential home buyer.', 'Facebook Long-Form': 'SCRIPT: \n\n'+'\n\n'.join(sesh.tg_responses)+f'\n\nTASK: rewrite the provided SCRIPT for a long-form Facebook video. Keep in mind the SCRIPT is about reviewing items to potentially have purchased, shipped and decorate a {sesh.room_type}; this is all for a prospective home buyer -- you are the item reviewer who is reviewing items on behalf of the potential home buyer.', 'Instagram Reel': 'SCRIPT: \n\n'+'\n\n'.join(sesh.tg_responses)+f'\n\nTASK: rewrite the provided SCRIPT for an Instagram Reel video. Keep in mind the SCRIPT is about reviewing items to potentially have purchased, shipped and decorate a {sesh.room_type}; this is all for a prospective home buyer -- you are the item reviewer who is reviewing items on behalf of the potential home buyer.', 'Tiktok': 'SCRIPT: \n\n'+'\n\n'.join(sesh.tg_responses)+f'\n\nTASK: rewrite the provided SCRIPT for a Tiktok video. Keep in mind the SCRIPT is about reviewing items to potentially have purchased, shipped and decorate a {sesh.room_type}; this is all for a prospective home buyer -- you are the item reviewer who is reviewing items on behalf of the potential home buyer.', 'LinkedIn': 'SCRIPT: \n\n'+'\n\n'.join(sesh.tg_responses)+f'\n\nTASK: rewrite the provided SCRIPT for a LinkedIn long-form video. Keep in mind the SCRIPT is about reviewing items to potentially have purchased, shipped and decorate a {sesh.room_type}; this is all for a prospective home buyer -- you are the item reviewer who is reviewing items on behalf of the potential home buyer.'}
|
| 1200 |
start = time.time()
|
|
|
|
| 1207 |
sesh.scripts = {k:json.loads(responses[i])['response'] if type(responses[i]) == type(b'') else 'Unable to complete this script.' for i,k in enumerate(script_types)}
|
| 1208 |
|
| 1209 |
#print('prepItem1ForScript script types: ', (end-start)/60, [(r[:250], script_types[i]) for i,r in enumerate(responses)])
|
| 1210 |
+
setSesh(seshid, sesh)
|
| 1211 |
return 'good'
|
| 1212 |
|
| 1213 |
else:
|
| 1214 |
+
setSesh(seshid, sesh)
|
| 1215 |
return 'bad'
|
| 1216 |
|
| 1217 |
def updateAllItemsStatus(text, seshid):
|
| 1218 |
+
sesh = getSesh(seshid)
|
| 1219 |
completed = len([s for s in sesh.scripts if s != 'Unable to complete this script.'])
|
| 1220 |
if text == 'good' and completed > 0:
|
| 1221 |
+
setSesh(seshid, sesh)
|
| 1222 |
return f"Color and character updated, {completed} {'scripts' if completed != 1 else 'script'} completed. ", gr.Dropdown(list(sesh.scripts), label='Scripts', interactive=True)
|
| 1223 |
|
| 1224 |
else:
|
| 1225 |
+
setSesh(seshid, sesh)
|
| 1226 |
return f'Something went wrong, failed to complete scripts.', gr.Dropdown([], label='Scripts', interactive=True)
|
| 1227 |
|
| 1228 |
def prepItem1ForScript(text, seshid):
|
| 1229 |
+
sesh = getSesh(seshid)
|
| 1230 |
if text == f'prep{sesh.found_terms_4_room_items_idx+1}':
|
| 1231 |
#generateScriptForItem(sesh.found_terms_4_room_items_idx,sesh.found_terms_4_room_items[sesh.found_terms_4_room_items_idx])
|
| 1232 |
generateScriptForItem()
|
| 1233 |
sesh.found_terms_4_room_items_idx += 1
|
| 1234 |
+
setSesh(seshid, sesh)
|
| 1235 |
return f'prepped{sesh.found_terms_4_room_items_idx}'+'-changed for testing'
|
| 1236 |
|
| 1237 |
else:
|
| 1238 |
+
setSesh(seshid, sesh)
|
| 1239 |
return f'prep{sesh.found_terms_4_room_items_idx} failed'
|
| 1240 |
|
| 1241 |
def updateItem1Status(text, seshid):
|
| 1242 |
+
sesh = getSesh(seshid)
|
| 1243 |
if text == f'prepped{sesh.found_terms_4_room_items_idx}':
|
| 1244 |
#print('prepItem1forScript: ', sesh.tg_responses[0])
|
| 1245 |
+
setSesh(seshid, sesh)
|
| 1246 |
return 'Color and character updated, scripts complete.', f'prep{sesh.found_terms_4_room_items_idx+1}'
|
| 1247 |
#return f'{sesh.product_pd_counts[sesh.found_terms_4_room_items_idx-1][0].upper()} script complete.\nPreparing script for {sesh.product_pd_counts[sesh.found_terms_4_room_items_idx][0]}.\nWorking on step {sesh.found_terms_4_room_items_idx+1} of {len(sesh.product_pd_counts)+6}, standby...', f'prep{sesh.found_terms_4_room_items_idx+1}'
|
| 1248 |
else:
|
| 1249 |
+
setSesh(seshid, sesh)
|
| 1250 |
print(f'prepItem{sesh.found_terms_4_room_items_idx+1}ForScript: fail')
|
| 1251 |
return f'ITEM {sesh.found_terms_4_room_items_idx} prep failed', ''
|
| 1252 |
|
| 1253 |
|
| 1254 |
def prepItem2ForScript(text, seshid):
|
| 1255 |
+
sesh = getSesh(seshid)
|
| 1256 |
if text == f'prep{sesh.found_terms_4_room_items_idx+1}':
|
| 1257 |
#generateScriptForItem(sesh.found_terms_4_room_items_idx,sesh.found_terms_4_room_items[sesh.found_terms_4_room_items_idx])
|
| 1258 |
generateScriptForItem()
|
| 1259 |
sesh.found_terms_4_room_items_idx += 1
|
| 1260 |
+
setSesh(seshid, sesh)
|
| 1261 |
return f'prepped{sesh.found_terms_4_room_items_idx}'
|
| 1262 |
else:
|
| 1263 |
+
setSesh(seshid, sesh)
|
| 1264 |
return f'prep{sesh.found_terms_4_room_items_idx} failed'
|
| 1265 |
|
| 1266 |
def updateItem2Status(text, seshid):
|
| 1267 |
+
sesh = getSesh(seshid)
|
| 1268 |
if text == f'prepped{sesh.found_terms_4_room_items_idx}':
|
| 1269 |
#print('prepItem1forScript: ', sesh.tg_responses[0])
|
| 1270 |
+
setSesh(seshid, sesh)
|
| 1271 |
return f'{sesh.product_pd_counts[sesh.found_terms_4_room_items_idx-1][0].upper()} script complete.\nPreparing script for {sesh.product_pd_counts[sesh.found_terms_4_room_items_idx][0]}.\nWorking on step {sesh.found_terms_4_room_items_idx+1} of {len(sesh.product_pd_counts)+6}, standby...', f'prep{sesh.found_terms_4_room_items_idx+1}'
|
| 1272 |
else:
|
| 1273 |
print(f'prepItem{sesh.found_terms_4_room_items_idx+1}ForScript: fail')
|
| 1274 |
+
setSesh(seshid, sesh)
|
| 1275 |
return f'ITEM {sesh.found_terms_4_room_items_idx} prep failed', ''
|
| 1276 |
|
| 1277 |
|
| 1278 |
def prepItem3ForScript(text, seshid):
|
| 1279 |
+
sesh = getSesh(seshid)
|
| 1280 |
if text == f'prep{sesh.found_terms_4_room_items_idx+1}':
|
| 1281 |
#generateScriptForItem(sesh.found_terms_4_room_items_idx,sesh.found_terms_4_room_items[sesh.found_terms_4_room_items_idx])
|
| 1282 |
generateScriptForItem()
|
| 1283 |
sesh.found_terms_4_room_items_idx += 1
|
| 1284 |
+
setSesh(seshid, sesh)
|
| 1285 |
return f'prepped{sesh.found_terms_4_room_items_idx}'
|
| 1286 |
else:
|
| 1287 |
+
setSesh(seshid, sesh)
|
| 1288 |
return f'prep{sesh.found_terms_4_room_items_idx} failed'
|
| 1289 |
|
| 1290 |
def updateItem3Status(text, seshid):
|
| 1291 |
+
sesh = getSesh(seshid)
|
| 1292 |
if text == f'prepped{sesh.found_terms_4_room_items_idx}':
|
| 1293 |
#print('prepItem1forScript: ', sesh.tg_responses[0])
|
| 1294 |
+
setSesh(seshid, sesh)
|
| 1295 |
return f'{sesh.product_pd_counts[sesh.found_terms_4_room_items_idx-1][0].upper()} script complete.\nPreparing script for {sesh.product_pd_counts[sesh.found_terms_4_room_items_idx][0]}.\nWorking on step {sesh.found_terms_4_room_items_idx+1} of {len(sesh.product_pd_counts)+6}, standby...', f'prep{sesh.found_terms_4_room_items_idx+1}'
|
| 1296 |
else:
|
| 1297 |
print(f'prepItem{sesh.found_terms_4_room_items_idx+1}ForScript: fail')
|
| 1298 |
+
setSesh(seshid, sesh)
|
| 1299 |
return f'ITEM {sesh.found_terms_4_room_items_idx} prep failed', ''
|
| 1300 |
|
| 1301 |
def prepItem4ForScript(text, seshid):
|
| 1302 |
+
sesh = getSesh(seshid)
|
| 1303 |
if text == f'prep{sesh.found_terms_4_room_items_idx+1}':
|
| 1304 |
#generateScriptForItem(sesh.found_terms_4_room_items_idx,sesh.found_terms_4_room_items[sesh.found_terms_4_room_items_idx])
|
| 1305 |
generateScriptForItem()
|
| 1306 |
sesh.found_terms_4_room_items_idx += 1
|
| 1307 |
+
setSesh(seshid, sesh)
|
| 1308 |
return f'prepped{sesh.found_terms_4_room_items_idx}'
|
| 1309 |
else:
|
| 1310 |
+
setSesh(seshid, sesh)
|
| 1311 |
return f'prep{sesh.found_terms_4_room_items_idx} failed'
|
| 1312 |
|
| 1313 |
def updateItem4Status(text, seshid):
|
| 1314 |
+
sesh = getSesh(seshid)
|
| 1315 |
if text == f'prepped{sesh.found_terms_4_room_items_idx}':
|
| 1316 |
#print('prepItem1forScript: ', sesh.tg_responses[0])
|
| 1317 |
+
setSesh(seshid, sesh)
|
| 1318 |
return f'{sesh.product_pd_counts[sesh.found_terms_4_room_items_idx-1][0].upper()} script complete.\nPreparing script for {sesh.product_pd_counts[sesh.found_terms_4_room_items_idx][0]}.\nWorking on step {sesh.found_terms_4_room_items_idx+1} of {len(sesh.product_pd_counts)+6}, standby...', f'prep{sesh.found_terms_4_room_items_idx+1}'
|
| 1319 |
else:
|
| 1320 |
print(f'prepItem{sesh.found_terms_4_room_items_idx+1}ForScript: fail')
|
| 1321 |
+
setSesh(seshid, sesh)
|
| 1322 |
return f'ITEM {sesh.found_terms_4_room_items_idx} prep failed', ''
|
| 1323 |
|
| 1324 |
def prepItem5ForScript(text, seshid):
|
| 1325 |
+
sesh = getSesh(seshid)
|
| 1326 |
if text == f'prep{sesh.found_terms_4_room_items_idx+1}':
|
| 1327 |
#generateScriptForItem(sesh.found_terms_4_room_items_idx,sesh.found_terms_4_room_items[sesh.found_terms_4_room_items_idx])
|
| 1328 |
generateScriptForItem()
|
| 1329 |
sesh.found_terms_4_room_items_idx += 1
|
| 1330 |
+
setSesh(seshid, sesh)
|
| 1331 |
return f'prepped{sesh.found_terms_4_room_items_idx}'
|
| 1332 |
else:
|
| 1333 |
+
setSesh(seshid, sesh)
|
| 1334 |
return f'prep{sesh.found_terms_4_room_items_idx} failed'
|
| 1335 |
|
| 1336 |
def updateItem5Status(text, seshid):
|
| 1337 |
+
sesh = getSesh(seshid)
|
| 1338 |
if text == f'prepped{sesh.found_terms_4_room_items_idx}':
|
| 1339 |
#print('prepItem1forScript: ', sesh.tg_responses[0])
|
| 1340 |
+
setSesh(seshid, sesh)
|
| 1341 |
return f'{sesh.product_pd_counts[sesh.found_terms_4_room_items_idx-1][0].upper()} script complete.\nPreparing script for {sesh.product_pd_counts[sesh.found_terms_4_room_items_idx][0]}.\nWorking on step {sesh.found_terms_4_room_items_idx+1} of {len(sesh.product_pd_counts)+6}, standby...', f'prep{sesh.found_terms_4_room_items_idx+1}'
|
| 1342 |
else:
|
| 1343 |
print(f'prepItem{sesh.found_terms_4_room_items_idx+1}ForScript: fail')
|
| 1344 |
+
setSesh(seshid, sesh)
|
| 1345 |
return f'ITEM {sesh.found_terms_4_room_items_idx} prep failed', ''
|
| 1346 |
|
| 1347 |
def prepItem6ForScript(text, seshid):
|
| 1348 |
+
sesh = getSesh(seshid)
|
| 1349 |
if text == f'prep{sesh.found_terms_4_room_items_idx+1}':
|
| 1350 |
#generateScriptForItem(sesh.found_terms_4_room_items_idx,sesh.found_terms_4_room_items[sesh.found_terms_4_room_items_idx])
|
| 1351 |
generateScriptForItem()
|
| 1352 |
sesh.found_terms_4_room_items_idx += 1
|
| 1353 |
+
setSesh(seshid, sesh)
|
| 1354 |
return f'prepped{sesh.found_terms_4_room_items_idx}'
|
| 1355 |
else:
|
| 1356 |
+
setSesh(seshid, sesh)
|
| 1357 |
return f'prep{sesh.found_terms_4_room_items_idx} failed'
|
| 1358 |
|
| 1359 |
def updateItem6Status(text, seshid):
|
| 1360 |
+
sesh = getSesh(seshid)
|
| 1361 |
if text == f'prepped{sesh.found_terms_4_room_items_idx}':
|
| 1362 |
#print('prepItem1forScript: ', sesh.tg_responses[0])
|
| 1363 |
+
setSesh(seshid, sesh)
|
| 1364 |
return f'{sesh.product_pd_counts[sesh.found_terms_4_room_items_idx-1][0].upper()} script complete.\nPreparing script for {sesh.product_pd_counts[sesh.found_terms_4_room_items_idx][0]}.\nWorking on step {sesh.found_terms_4_room_items_idx} of {len(sesh.product_pd_counts)+6}, standby...', f'prep{sesh.found_terms_4_room_items_idx+1}'
|
| 1365 |
else:
|
| 1366 |
print(f'prepItem{sesh.found_terms_4_room_items_idx+1}ForScript: fail')
|
| 1367 |
+
setSesh(seshid, sesh)
|
| 1368 |
return f'ITEM {sesh.found_terms_4_room_items_idx} prep failed', ''
|
| 1369 |
|
| 1370 |
def prepItem7ForScript(text, seshid):
|
| 1371 |
+
sesh = getSesh(seshid)
|
| 1372 |
if text == f'prep{sesh.found_terms_4_room_items_idx+1}':
|
| 1373 |
#generateScriptForItem(sesh.found_terms_4_room_items_idx,sesh.found_terms_4_room_items[sesh.found_terms_4_room_items_idx])
|
| 1374 |
generateScriptForItem()
|
| 1375 |
sesh.found_terms_4_room_items_idx += 1
|
| 1376 |
+
setSesh(seshid, sesh)
|
| 1377 |
return f'prepped{sesh.found_terms_4_room_items_idx}'
|
| 1378 |
else:
|
| 1379 |
+
setSesh(seshid, sesh)
|
| 1380 |
return f'prep{sesh.found_terms_4_room_items_idx} failed'
|
| 1381 |
|
| 1382 |
def updateItem7Status(text, seshid):
|
| 1383 |
+
sesh = getSesh(seshid)
|
| 1384 |
if text == f'prepped{sesh.found_terms_4_room_items_idx}':
|
| 1385 |
#print('prepItem1forScript: ', sesh.tg_responses[0])
|
| 1386 |
+
setSesh(seshid, sesh)
|
| 1387 |
return f'{sesh.product_pd_counts[sesh.found_terms_4_room_items_idx-1][0].upper()} script complete.\nPreparing script for {sesh.product_pd_counts[sesh.found_terms_4_room_items_idx][0]}.\nWorking on step {sesh.found_terms_4_room_items_idx+1} of {len(sesh.product_pd_counts)+6}, standby...', f'prep{sesh.found_terms_4_room_items_idx+1}'
|
| 1388 |
else:
|
| 1389 |
|
| 1390 |
print(f'prepItem{sesh.found_terms_4_room_items_idx+1}ForScript: fail')
|
| 1391 |
+
setSesh(seshid, sesh)
|
| 1392 |
return f'ITEM {sesh.found_terms_4_room_items_idx} prep failed', ''
|
| 1393 |
|
| 1394 |
def prepItem8ForScript(text, seshid):
|
| 1395 |
+
sesh = getSesh(seshid)
|
| 1396 |
if text == f'prep{sesh.found_terms_4_room_items_idx+1}':
|
| 1397 |
#generateScriptForItem(sesh.found_terms_4_room_items_idx,sesh.found_terms_4_room_items[sesh.found_terms_4_room_items_idx])
|
| 1398 |
generateScriptForItem()
|
| 1399 |
sesh.found_terms_4_room_items_idx += 1
|
| 1400 |
+
setSesh(seshid, sesh)
|
| 1401 |
return f'prepped{sesh.found_terms_4_room_items_idx}'
|
| 1402 |
else:
|
| 1403 |
+
setSesh(seshid, sesh)
|
| 1404 |
return f'prep{sesh.found_terms_4_room_items_idx} failed'
|
| 1405 |
|
| 1406 |
def updateItem8Status(text, seshid):
|
| 1407 |
+
sesh = getSesh(seshid)
|
| 1408 |
if text == f'prepped{sesh.found_terms_4_room_items_idx}':
|
| 1409 |
#print('updateItem8Status: ', sesh.found_terms_4_room_items_idx, len(sesh.found_terms_4_room_items))
|
| 1410 |
sesh.script_status_text = f'{sesh.product_pd_counts[sesh.found_terms_4_room_items_idx-1][0].upper()} script complete.\nPreparing script for {sesh.product_pd_counts[sesh.found_terms_4_room_items_idx][0]}.\nWorking on step {sesh.found_terms_4_room_items_idx+1} of {len(sesh.product_pd_counts)+6}, standby...' if sesh.found_terms_4_room_items_idx < len(sesh.product_pd_counts) else f'{sesh.product_pd_counts[sesh.found_terms_4_room_items_idx-1][0].upper()} script complete.\nPreparing script for Youtube long-form video.\nWorking on step {sesh.found_terms_4_room_items_idx} of {len(sesh.product_pd_counts)+6}, standby...'
|
| 1411 |
+
setSesh(seshid, sesh)
|
| 1412 |
return sesh.script_status_text, f'prep{sesh.found_terms_4_room_items_idx+1}'
|
| 1413 |
else:
|
| 1414 |
print(f'prepItem{sesh.found_terms_4_room_items_idx+1}ForScript: fail')
|
| 1415 |
+
setSesh(seshid, sesh)
|
| 1416 |
return f'ITEM {sesh.found_terms_4_room_items_idx} prep failed', ''
|
| 1417 |
|
| 1418 |
def prepItem9ForScript(text, seshid):
|
| 1419 |
+
sesh = getSesh(seshid)
|
| 1420 |
if text == f'prep{sesh.found_terms_4_room_items_idx+1}':
|
| 1421 |
if sesh.found_terms_4_room_items_idx < len(sesh.product_pd_counts): generateScriptForItem() #generateScriptForItem(sesh.found_terms_4_room_items_idx,sesh.found_terms_4_room_items[sesh.found_terms_4_room_items_idx])
|
| 1422 |
if sesh.found_terms_4_room_items_idx < len(sesh.product_pd_counts): sesh.found_terms_4_room_items_idx += 1
|
| 1423 |
+
setSesh(seshid, sesh)
|
| 1424 |
return f'prepped{sesh.found_terms_4_room_items_idx}'
|
| 1425 |
else:
|
| 1426 |
+
setSesh(seshid, sesh)
|
| 1427 |
return f'prep{sesh.found_terms_4_room_items_idx} failed'
|
| 1428 |
|
| 1429 |
def updateItem9Status(text, seshid):
|
| 1430 |
+
sesh = getSesh(seshid)
|
| 1431 |
if text == f'prepped{sesh.found_terms_4_room_items_idx}':
|
| 1432 |
#print('updateItem9Status: ', sesh.found_terms_4_room_items_idx, len(sesh.found_terms_4_room_items))
|
| 1433 |
sesh.script_status_text = f'{sesh.product_pd_counts[sesh.found_terms_4_room_items_idx-1][0].upper()} script complete.\nPreparing script for {sesh.product_pd_counts[sesh.found_terms_4_room_items_idx][0]}.\nWorking on step {sesh.found_terms_4_room_items_idx+1} of {len(sesh.product_pd_counts)+6}, standby...' if sesh.found_terms_4_room_items_idx < len(sesh.product_pd_counts)-1 else sesh.script_status_text
|
| 1434 |
+
setSesh(seshid, sesh)
|
| 1435 |
return sesh.script_status_text, f'prep{sesh.found_terms_4_room_items_idx+1}'
|
| 1436 |
else:
|
| 1437 |
print(f'prepItem{sesh.found_terms_4_room_items_idx+1}ForScript: fail')
|
| 1438 |
+
setSesh(seshid, sesh)
|
| 1439 |
return f'ITEM {sesh.found_terms_4_room_items_idx} prep failed', ''
|
| 1440 |
|
| 1441 |
def prepItem10ForScript(text, seshid):
|
| 1442 |
+
sesh = getSesh(seshid)
|
| 1443 |
if text == f'prep{sesh.found_terms_4_room_items_idx+1}':
|
| 1444 |
if sesh.found_terms_4_room_items_idx < len(sesh.product_pd_counts): generateScriptForItem() #generateScriptForItem(sesh.found_terms_4_room_items_idx,sesh.found_terms_4_room_items[sesh.found_terms_4_room_items_idx])
|
| 1445 |
if sesh.found_terms_4_room_items_idx < len(sesh.product_pd_counts): sesh.found_terms_4_room_items_idx += 1
|
| 1446 |
+
setSesh(seshid, sesh)
|
| 1447 |
return f'prepped{sesh.found_terms_4_room_items_idx}'
|
| 1448 |
else:
|
| 1449 |
+
setSesh(seshid, sesh)
|
| 1450 |
return f'prep{sesh.found_terms_4_room_items_idx} failed'
|
| 1451 |
|
| 1452 |
def updateItem10Status(text, seshid):
|
| 1453 |
+
sesh = getSesh(seshid)
|
| 1454 |
if text == f'prepped{sesh.found_terms_4_room_items_idx}':
|
| 1455 |
#print('updateItem10Status: ', sesh.found_terms_4_room_items_idx, len(sesh.found_terms_4_room_items))
|
| 1456 |
sesh.script_status_text = f'{sesh.product_pd_counts[sesh.found_terms_4_room_items_idx-1][0].upper()} script complete.\nPreparing script for {sesh.product_pd_counts[sesh.found_terms_4_room_items_idx][0]}.\nWorking on step {sesh.found_terms_4_room_items_idx+1} of {len(sesh.product_pd_counts)+6}, standby...' if sesh.found_terms_4_room_items_idx < len(sesh.product_pd_counts)-1 else sesh.script_status_text
|
| 1457 |
+
setSesh(seshid, sesh)
|
| 1458 |
return sesh.script_status_text, f'prep{sesh.found_terms_4_room_items_idx+1}'
|
| 1459 |
else:
|
| 1460 |
print(f'prepItem{sesh.found_terms_4_room_items_idx+1}ForScript: fail')
|
| 1461 |
+
setSesh(seshid, sesh)
|
| 1462 |
return f'ITEM {sesh.found_terms_4_room_items_idx} prep failed', ''
|
| 1463 |
|
| 1464 |
def prepItem11ForScript(text, seshid):
|
| 1465 |
+
sesh = getSesh(seshid)
|
| 1466 |
if text == f'prep{sesh.found_terms_4_room_items_idx+1}':
|
| 1467 |
if sesh.found_terms_4_room_items_idx < len(sesh.product_pd_counts): generateScriptForItem() #generateScriptForItem(sesh.found_terms_4_room_items_idx,sesh.found_terms_4_room_items[sesh.found_terms_4_room_items_idx])
|
| 1468 |
if sesh.found_terms_4_room_items_idx < len(sesh.product_pd_counts): sesh.found_terms_4_room_items_idx += 1
|
| 1469 |
+
setSesh(seshid, sesh)
|
| 1470 |
return f'prepped{sesh.found_terms_4_room_items_idx}'
|
| 1471 |
else:
|
| 1472 |
+
setSesh(seshid, sesh)
|
| 1473 |
return f'prep{sesh.found_terms_4_room_items_idx} failed'
|
| 1474 |
|
| 1475 |
def updateItem11Status(text, seshid):
|
| 1476 |
+
sesh = getSesh(seshid)
|
| 1477 |
if text == f'prepped{sesh.found_terms_4_room_items_idx}':
|
| 1478 |
#print('updateItem11Status: ', sesh.found_terms_4_room_items_idx, len(sesh.found_terms_4_room_items))
|
| 1479 |
sesh.script_status_text = f'{sesh.product_pd_counts[sesh.found_terms_4_room_items_idx-1][0].upper()} script complete.\nPreparing script for {sesh.product_pd_counts[sesh.found_terms_4_room_items_idx][0]}.\nWorking on step {sesh.found_terms_4_room_items_idx+1} of {len(sesh.product_pd_counts)+6}, standby...' if sesh.found_terms_4_room_items_idx < len(sesh.product_pd_counts)-1 else sesh.script_status_text
|
| 1480 |
+
setSesh(seshid, sesh)
|
| 1481 |
return sesh.script_status_text, f'prep{sesh.found_terms_4_room_items_idx+1}'
|
| 1482 |
else:
|
| 1483 |
print(f'prepItem{sesh.found_terms_4_room_items_idx+1}ForScript: fail')
|
| 1484 |
+
setSesh(seshid, sesh)
|
| 1485 |
return f'ITEM {sesh.found_terms_4_room_items_idx} prep failed', ''
|
| 1486 |
|
| 1487 |
def prepItem12ForScript(text, seshid):
|
| 1488 |
+
sesh = getSesh(seshid)
|
| 1489 |
if text == f'prep{sesh.found_terms_4_room_items_idx+1}':
|
| 1490 |
if sesh.found_terms_4_room_items_idx < len(sesh.product_pd_counts): generateScriptForItem() #generateScriptForItem(sesh.found_terms_4_room_items_idx,sesh.found_terms_4_room_items[sesh.found_terms_4_room_items_idx])
|
| 1491 |
if sesh.found_terms_4_room_items_idx < len(sesh.product_pd_counts): sesh.found_terms_4_room_items_idx += 1
|
| 1492 |
+
setSesh(seshid, sesh)
|
| 1493 |
return f'prepped{sesh.found_terms_4_room_items_idx}'
|
| 1494 |
else:
|
| 1495 |
+
setSesh(seshid, sesh)
|
| 1496 |
return f'prep{sesh.found_terms_4_room_items_idx} failed'
|
| 1497 |
|
| 1498 |
def updateItem12Status(text, seshid):
|
| 1499 |
+
sesh = getSesh(seshid)
|
| 1500 |
if text == f'prepped{sesh.found_terms_4_room_items_idx}':
|
| 1501 |
#print('updateItem12Status: ', sesh.found_terms_4_room_items_idx, len(sesh.found_terms_4_room_items))
|
| 1502 |
sesh.script_status_text = f'{sesh.product_pd_counts[sesh.found_terms_4_room_items_idx-1][0].upper()} script complete.\nPreparing script for {sesh.product_pd_counts[sesh.found_terms_4_room_items_idx][0]}.\nWorking on step {sesh.found_terms_4_room_items_idx+1} of {len(sesh.product_pd_counts)+6}, standby...' if sesh.found_terms_4_room_items_idx < len(sesh.product_pd_counts)-1 else sesh.script_status_text
|
| 1503 |
+
setSesh(seshid, sesh)
|
| 1504 |
return sesh.script_status_text, f'prep{sesh.found_terms_4_room_items_idx+1}'
|
| 1505 |
else:
|
| 1506 |
print(f'prepItem{sesh.found_terms_4_room_items_idx+1}ForScript: fail')
|
| 1507 |
+
setSesh(seshid, sesh)
|
| 1508 |
return f'ITEM {sesh.found_terms_4_room_items_idx} prep failed', ''
|
| 1509 |
|
| 1510 |
def prepItem13ForScript(text, seshid):
|
| 1511 |
+
sesh = getSesh(seshid)
|
| 1512 |
if text == f'prep{sesh.found_terms_4_room_items_idx+1}':
|
| 1513 |
if sesh.found_terms_4_room_items_idx < len(sesh.product_pd_counts): generateScriptForItem() #generateScriptForItem(sesh.found_terms_4_room_items_idx,sesh.found_terms_4_room_items[sesh.found_terms_4_room_items_idx])
|
| 1514 |
if sesh.found_terms_4_room_items_idx < len(sesh.product_pd_counts): sesh.found_terms_4_room_items_idx += 1
|
| 1515 |
+
setSesh(seshid, sesh)
|
| 1516 |
return f'prepped{sesh.found_terms_4_room_items_idx}'
|
| 1517 |
else:
|
| 1518 |
+
setSesh(seshid, sesh)
|
| 1519 |
return f'prep{sesh.found_terms_4_room_items_idx} failed'
|
| 1520 |
|
| 1521 |
def updateItem13Status(text, seshid):
|
| 1522 |
+
sesh = getSesh(seshid)
|
| 1523 |
if text == f'prepped{sesh.found_terms_4_room_items_idx}':
|
| 1524 |
#print('updateItem13Status: ', sesh.found_terms_4_room_items_idx, len(sesh.found_terms_4_room_items))
|
| 1525 |
#print('prepItem13forScript: ', sesh.tg_responses)
|
| 1526 |
sesh.scripts['Base'] = '\n\n'.join(sesh.tg_responses)
|
| 1527 |
sesh.script_status_text = f'{sesh.product_pd_counts[sesh.found_terms_4_room_items_idx-1][0].upper()} script complete.\nPreparing script for {sesh.product_pd_counts[sesh.found_terms_4_room_items_idx][0]}.\nWorking on step {sesh.found_terms_4_room_items_idx+1} of {len(sesh.product_pd_counts)+6}, standby...' if sesh.found_terms_4_room_items_idx < len(sesh.product_pd_counts)-1 else sesh.script_status_text
|
| 1528 |
+
setSesh(seshid, sesh)
|
| 1529 |
return sesh.script_status_text, 'prep_ytlong'
|
| 1530 |
else:
|
| 1531 |
print(f'prepItem{sesh.found_terms_4_room_items_idx+1}ForScript: fail')
|
| 1532 |
+
setSesh(seshid, sesh)
|
| 1533 |
return f'ITEM {sesh.found_terms_4_room_items_idx} prep failed', ''
|
| 1534 |
|
| 1535 |
|
| 1536 |
def prepYTLongFormScript(text, seshid):
|
| 1537 |
+
sesh = getSesh(seshid)
|
| 1538 |
if text == 'prep_ytlong':
|
| 1539 |
prompt = 'SCRIPT: \n\n'+'\n\n'.join(sesh.tg_responses)+f'\n\nTASK: rewrite the provided SCRIPT for a long-form Youtube video. Keep in mind the SCRIPT is about reviewing items to potentially have purchased, shipped and decorate a {sesh.room_type}; this is all for a prospective home buyer -- you are the item reviewer who is reviewing items on behalf of the potential home buyer.'
|
| 1540 |
sesh.scripts['Youtube Long-Form'] = getTextGen(prompt) #client.text_generation(prompt, model="mistralai/Mixtral-8x7B-Instruct-v0.1", max_new_tokens=2500)
|
| 1541 |
+
setSesh(seshid, sesh)
|
| 1542 |
return 'ytlong_prepped'
|
| 1543 |
else:
|
| 1544 |
+
setSesh(seshid, sesh)
|
| 1545 |
return 'prep_ytlong failed'
|
| 1546 |
|
| 1547 |
def updateYTLongFormStatus(text, seshid):
|
| 1548 |
+
sesh = getSesh(seshid)
|
| 1549 |
if text == 'ytlong_prepped':
|
| 1550 |
print('updateYTLongFormStatus: ', list(sesh.scripts))
|
| 1551 |
+
setSesh(seshid, sesh)
|
| 1552 |
return f'YOUTUBE LONG-FORM script complete.\nPreparing script for Youtube short-form.\nWorking on step {sesh.found_terms_4_room_items_idx+2} of {len(sesh.product_pd_counts)+6}, standby...', 'prep_ytshort', gr.Dropdown(list(sesh.scripts), label='Scripts', interactive=True)
|
| 1553 |
else:
|
| 1554 |
+
setSesh(seshid, sesh)
|
| 1555 |
return 'YT long-form script failed', '', gr.Dropdown(list(sesh.scripts), label='Scripts', interactive=True)
|
| 1556 |
|
| 1557 |
|
| 1558 |
def prepYTShortFormScript(text, seshid):
|
| 1559 |
+
sesh = getSesh(seshid)
|
| 1560 |
if text == 'prep_ytshort':
|
| 1561 |
prompt = 'SCRIPT: \n\n'+'\n\n'.join(sesh.tg_responses)+f'\n\nTASK: rewrite the provided SCRIPT for a Youtube Short. Keep in mind the SCRIPT is about reviewing items to potentially have purchased, shipped and decorate a {sesh.room_type}; this is all for a prospective home buyer -- you are the item reviewer who is reviewing items on behalf of the potential home buyer.'
|
| 1562 |
sesh.scripts['Youtube Short-Form'] = getTextGen(prompt) #client.text_generation(prompt, model="mistralai/Mixtral-8x7B-Instruct-v0.1", max_new_tokens=2500)
|
| 1563 |
+
setSesh(seshid, sesh)
|
| 1564 |
return 'ytshort_prepped'
|
| 1565 |
else:
|
| 1566 |
+
setSesh(seshid, sesh)
|
| 1567 |
return 'prep_ytshort failed'
|
| 1568 |
|
| 1569 |
def updateYTShortFormStatus(text, seshid):
|
| 1570 |
+
sesh = getSesh(seshid)
|
| 1571 |
print('updateYTShortFormStatus: ', text, list(sesh.scripts))
|
| 1572 |
if text == 'ytshort_prepped':
|
| 1573 |
+
setSesh(seshid, sesh)
|
| 1574 |
return f'YOUTUBE SHORT script complete.\nPreparing script for Facebook.\nWorking on step {sesh.found_terms_4_room_items_idx+3} of {len(sesh.product_pd_counts)+6}, standby...', 'prepfb', gr.Dropdown(list(sesh.scripts), label='Scripts', interactive=True)
|
| 1575 |
else:
|
| 1576 |
+
setSesh(seshid, sesh)
|
| 1577 |
return 'YT short-form script failed', '', gr.Dropdown(list(sesh.scripts), label='Scripts', interactive=True)
|
| 1578 |
|
| 1579 |
|
| 1580 |
def prepFBScript(text,seshid):
|
| 1581 |
+
sesh = getSesh(seshid)
|
| 1582 |
if text == 'prepfb':
|
| 1583 |
prompt = 'SCRIPT: \n\n'+'\n\n'.join(sesh.tg_responses)+f'\n\nTASK: rewrite the provided SCRIPT for a long-form Facebook video. Keep in mind the SCRIPT is about reviewing items to potentially have purchased, shipped and decorate a {sesh.room_type}; this is all for a prospective home buyer -- you are the item reviewer who is reviewing items on behalf of the potential home buyer.'
|
| 1584 |
sesh.scripts['Facebook Long-Form'] = getTextGen(prompt) #client.text_generation(prompt, model="mistralai/Mixtral-8x7B-Instruct-v0.1", max_new_tokens=2500)
|
| 1585 |
+
setSesh(seshid, sesh)
|
| 1586 |
return 'fb_prepped'
|
| 1587 |
else:
|
| 1588 |
+
setSesh(seshid, sesh)
|
| 1589 |
return 'prepfb failed'
|
| 1590 |
|
| 1591 |
def updateFBStatus(text, seshid):
|
| 1592 |
+
sesh = getSesh(seshid)
|
| 1593 |
print('updateFBStatus: ', text, list(sesh.scripts))
|
| 1594 |
if text == 'fb_prepped':
|
| 1595 |
+
setSesh(seshid, sesh)
|
| 1596 |
return f'FACEBOOK script complete.\nPreparing script for Instagram Reel.\nWorking on step {sesh.found_terms_4_room_items_idx+4} of {len(sesh.product_pd_counts)+6}, standby...', 'prepig', gr.Dropdown(list(sesh.scripts), label='Scripts', interactive=True)
|
| 1597 |
else:
|
| 1598 |
+
setSesh(seshid, sesh)
|
| 1599 |
return 'Facebook script failed', '', gr.Dropdown(list(sesh.scripts), label='Scripts', interactive=True)
|
| 1600 |
|
| 1601 |
|
|
|
|
| 1648 |
|
| 1649 |
|
| 1650 |
def selectScript(evt: gr.SelectData, seshid):
|
| 1651 |
+
sesh = getSesh(seshid)
|
| 1652 |
script = evt.value
|
| 1653 |
+
return sesh.scripts[script]
|
| 1654 |
|
| 1655 |
|
| 1656 |
|