from gpt3_function import * import random import numpy as np def generate_weighted_list(weighted_list, length, verbose=False): if verbose : print(weighted_list) items = [*weighted_list.keys()] weights = [*weighted_list.values()] weights = np.array(weights) output = list(np.random.choice(items, length, p=weights/sum(weights))) return output #simple def kapuhala_list(weighted_list, length): def generate_weighted_list(weighted_list, length, verbose=False): if verbose : print(weighted_list) items = [*weighted_list.keys()] weights = [*weighted_list.values()] weights = np.array(weights) output = list(np.random.choice(items, length, p=weights/sum(weights))) return output list1 = list() for index in range(0, length): weighted_list_ = weighted_list.copy() if index == 1: #look 1 position back del weighted_list_[list1[index-1][0]] list1.append(generate_weighted_list(weighted_list_, 1)) elif index >= 2: #look 2 positions back del weighted_list_[list1[index-2][0]] del weighted_list_[list1[index-1][0]] list1.append(generate_weighted_list(weighted_list_, 1)) else: #we cannot look back otherwise throws error list1.append(generate_weighted_list(weighted_list_, 1)) list1 = [x[0] for x in list1] return list1 #includes weekdays def kapuhala_list(weighted_list, weekday_list, length): def generate_weighted_list(weighted_list, length, verbose=False): if verbose : print(weighted_list) items = [*weighted_list.keys()] weights = [*weighted_list.values()] weights = np.array(weights) output = list(np.random.choice(items, length, p=weights/sum(weights))) return output list1 = list() for index in range(0, length): weighted_list_ = weighted_list.copy() #weekday sequence current = weekday_list[index] if (current == 'Saturday') or (current == 'Sunday'): del weighted_list_['weekend'] #avoid repetitions if index == 1: #look 1 position back try: del weighted_list_[list1[index-1][0]] except: pass list1.append(generate_weighted_list(weighted_list_, 1)) elif index >= 2: #look 2 positions back try: del weighted_list_[list1[index-12][0]] except: pass try: del weighted_list_[list1[index-1][0]] except: pass list1.append(generate_weighted_list(weighted_list_, 1)) else: #we cannot look back otherwise throws error list1.append(generate_weighted_list(weighted_list_, 1)) list1 = [x[0] for x in list1] return list1 import pandas as pd def generate_content(month, max_days): weighted_list = { 'yogaClasses' : 4, 'swim' : 4, 'mixology' : 4, 'happyHour' : 6, 'weekend' : 0, 'wedding' : 2, 'tentedVilla' : 2, 'farmhouse' : 2, 'retreats' : 2 } dates = pd.date_range(start=f'2023-{month}-01', end=f'2023-{month}-30') df = pd.DataFrame({'date': dates, 'weekday': dates.strftime('%A')}) df['vertical'] = kapuhala_list(weighted_list, df['weekday'].values.tolist(), len(df)) #add weekend topic on fridays df.loc[df[df['weekday']=='Friday'].index.tolist(), 'vertical'] = 'weekend' df df_ = df[0:max_days] df_ dict1 = { 'yogaClasses' : """ Find your inner zen and boost your fitness routine with our invigorating yoga and fitness classes at Kapuhala Koh Samui Surrounded by stunning nature, enjoy our incredible dishes and take advantage of our very instagrammable infinity pool. The ultimate wellness experience awaits you! """, 'swim' : """ At Halapua Restaurant we offer a Mediterranean-inspired menu using fresh seasonal ingredients and vegetables. With your lunch reservation you can enjoy our infinity pool with breath taking views, it’s the perfect way to spend a half day on this tropical island! Open everyday except Mondays. """, 'mixology' : """ Halapua restaurant and mixology lounge is the only unapologetically plant-based high-end dining experience on the island. We maintain strict standards and staff training to grant you the best experience! Book your table today! """, 'happyHour' : """ Come for the happy hour at Kapuhala Koh Samui from 3pm to 6pm. By getting 2 drinks you will receive a complimentary plate of snack from our kitchen! """, 'weekend' : """ Pass your Weekend with us at Kapuhala Koh Samui! Book a table on the best plant based restaurant on the island. Sicilian inspired cuisine made with local ingredients. """, 'wedding' : """ Wedding reception or honeymoon at Kapuhala. Our gorgeous, secluded spot offers everything you need for an unforgettable, intimate event. Our experienced team is here to help you create your dream event. Whether it’s a small gathering of friends or an extravagant celebration, we’ll make sure that your special day is just as perfect as you imagined. Experience the paradise of Kapuhala! Plan your dream wedding or honeymoon here and let us make it all happen """, 'tentedVilla' : """ Book our TENTED VILLA at Kapuhala Koh Samui - Live Without Walls! Sleeps 2 adults (Max with 1-2 more kids) At Kapuhala Koh Samui you have a unique opportunity to sleep surrounded by the ambient sounds of the jungle, yet still enjoy the comforts and amenities of a hotel room. We invite you to experience a different, more natural way of living. Become one with your surroundings, connect to the natural world around you and experience something as simple as waking up or taking a shower in an entirely new way. All our Tented Villas are fully detached en suite structures with a private terrace where you can greet the sunrise or enjoy your breakfast. The villas are modular and with removable panels enabling you to enjoy the spectacular nature around you. """, 'farmhouse' : """ Kapuhala Koh Samui - Farmhouse Nestled on the edge of a hill, these no ordinary, architecturally unique Farmhouses are fully detached rooms with separate entrances built on top of large rocks – a natural geological wonder of the area. Conveniently positioned close to the main building just across our tropical farm. Each house is 27 sq. m. and sleeps 2 people in a queen-size bed. Perfect for a single person or couple. Wake up daily to a serene sea view of the bay and enjoy the breath taking sunrises on your private balcony. """, 'retreats' : """ Are you ready to take your mental and physical capabilities to the next level? Yoga, Fitness and Nutrition! Come join us at Kapuhala for an exclusive Superhuman retreat and experience the power of true, natural Biohacking. At Kapuhala Koh Samui you will be sharing your day with Stefano Passarello, Crystal Lee and other entrepreneurial minds and forward thinkers just like you. Through our 5 day protocol you'll be able to maximize your mental performance, increase creativity, and optimize physical performance. What are you waiting for? Join us at Kapuhala and unlock your superhuman capabilities! We can also help you organize a tailor made retreat on the dates that best suit your needs. """ } prompt = 'Write a social media post-caption about this: add emoji, add hashtags at the end :' df_['prompt'] = df_['vertical'].apply(lambda x : prompt+dict1[x]) # df_ = df_[0:3] df_['post'] = df_['prompt'].apply(lambda x : gpt3(x, model='gpt-3.5-turbo', service='azure')) # df_['post'] = df_['prompt'].apply(lambda x : 'mmm') return df_.drop('prompt', axis=1) # df_content = generate_content(11, 2) # df_content import gradio as gr with gr.Blocks(theme=gr.themes.Soft(primary_hue='amber', secondary_hue='gray', neutral_hue='amber')) as demo: gr.Markdown( """ # Content Calendar Generator """ ) # input1 = gr.Slider(1, 31, value=5, step_size=10, label="# Days") input1 = gr.Slider(1, 12, step=1, value=5, label="Month") input2 = gr.Radio([1, 3, 5, 10, 30], multiselect=False, label='# Days', value=3) # input3 = gr.Radio(['Manhattan', 'Brooklyn', 'Queens', 'Bronx'], multiselect=False, label='State', value='Brooklyn') # input4 = gr.Textbox(label='Query', value='I want to take a break from work 😴!!!') btn = gr.Button(value="Generate Content") output1 = gr.Dataframe() # btn.click(greet, inputs='text', outputs=['dataframe']) btn.click(generate_content, [input1, input2], [output1]) demo.launch(share=False)