{ "cells": [ { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "from gpt3_function import *" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "import random\n", "import numpy as np\n", "\n", "def generate_weighted_list(weighted_list, length, verbose=False):\n", " if verbose : print(weighted_list)\n", " items = [*weighted_list.keys()]\n", " weights = [*weighted_list.values()]\n", " weights = np.array(weights)\n", " output = list(np.random.choice(items, length, p=weights/sum(weights)))\n", " return output\n", "\n", "#simple\n", "def kapuhala_list(weighted_list, length):\n", "\n", " def generate_weighted_list(weighted_list, length, verbose=False):\n", " if verbose : print(weighted_list)\n", " items = [*weighted_list.keys()]\n", " weights = [*weighted_list.values()]\n", " weights = np.array(weights)\n", " output = list(np.random.choice(items, length, p=weights/sum(weights)))\n", " return output\n", "\n", " list1 = list()\n", " for index in range(0, length):\n", " weighted_list_ = weighted_list.copy()\n", " if index == 1:\n", " #look 1 position back \n", " del weighted_list_[list1[index-1][0]]\n", " list1.append(generate_weighted_list(weighted_list_, 1))\n", " elif index >= 2:\n", " #look 2 positions back\n", " del weighted_list_[list1[index-2][0]]\n", " del weighted_list_[list1[index-1][0]]\n", " list1.append(generate_weighted_list(weighted_list_, 1))\n", " else:\n", " #we cannot look back otherwise throws error\n", " list1.append(generate_weighted_list(weighted_list_, 1))\n", "\n", " list1 = [x[0] for x in list1] \n", " return list1\n", "\n", "#includes weekdays\n", "def kapuhala_list(weighted_list, weekday_list, length):\n", "\n", " def generate_weighted_list(weighted_list, length, verbose=False):\n", " if verbose : print(weighted_list)\n", " items = [*weighted_list.keys()]\n", " weights = [*weighted_list.values()]\n", " weights = np.array(weights)\n", " output = list(np.random.choice(items, length, p=weights/sum(weights)))\n", " return output\n", "\n", " list1 = list()\n", " for index in range(0, length):\n", " weighted_list_ = weighted_list.copy()\n", " #weekday sequence\n", " current = weekday_list[index] \n", " if (current == 'Saturday') or (current == 'Sunday'):\n", " del weighted_list_['weekend']\n", " #avoid repetitions\n", " if index == 1:\n", " #look 1 position back \n", " try:\n", " del weighted_list_[list1[index-1][0]]\n", " except:\n", " pass\n", " list1.append(generate_weighted_list(weighted_list_, 1))\n", " elif index >= 2:\n", " #look 2 positions back\n", " try:\n", " del weighted_list_[list1[index-12][0]]\n", " except:\n", " pass\n", " try:\n", " del weighted_list_[list1[index-1][0]]\n", " except:\n", " pass\n", " list1.append(generate_weighted_list(weighted_list_, 1))\n", " else:\n", " #we cannot look back otherwise throws error\n", " list1.append(generate_weighted_list(weighted_list_, 1))\n", "\n", " list1 = [x[0] for x in list1] \n", " return list1" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "C:\\Users\\ardit\\AppData\\Local\\Temp\\ipykernel_21100\\3657193565.py:78: SettingWithCopyWarning: \n", "A value is trying to be set on a copy of a slice from a DataFrame.\n", "Try using .loc[row_indexer,col_indexer] = value instead\n", "\n", "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n", " df_['prompt'] = df_['vertical'].apply(lambda x : prompt+dict1[x])\n", "C:\\Users\\ardit\\AppData\\Local\\Temp\\ipykernel_21100\\3657193565.py:82: SettingWithCopyWarning: \n", "A value is trying to be set on a copy of a slice from a DataFrame.\n", "Try using .loc[row_indexer,col_indexer] = value instead\n", "\n", "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n", " df_['post'] = df_['prompt'].apply(lambda x : gpt3(x, model='gpt-3.5-turbo', service='azure'))\n" ] }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
dateweekdayverticalpost
02023-11-01WednesdayhappyHour🍹🍹 It's time to unwind and enjoy happy hour at...
12023-11-02ThursdayweddingπŸ‘°πŸ’πŸŒ΄ Get ready to say \"I do\" or fall even more ...
\n", "
" ], "text/plain": [ " date weekday vertical \\\n", "0 2023-11-01 Wednesday happyHour \n", "1 2023-11-02 Thursday wedding \n", "\n", " post \n", "0 🍹🍹 It's time to unwind and enjoy happy hour at... \n", "1 πŸ‘°πŸ’πŸŒ΄ Get ready to say \"I do\" or fall even more ... " ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import pandas as pd\n", "\n", "def generate_content(month, max_days):\n", "\n", " weighted_list = {\n", " 'yogaClasses' : 4,\n", " 'swim' : 4,\n", " 'mixology' : 4,\n", " 'happyHour' : 6,\n", " 'weekend' : 0,\n", " 'wedding' : 2,\n", " 'tentedVilla' : 2,\n", " 'farmhouse' : 2,\n", " 'retreats' : 2\n", " }\n", "\n", " dates = pd.date_range(start=f'2023-{month}-01', end=f'2023-{month}-30')\n", " df = pd.DataFrame({'date': dates, 'weekday': dates.strftime('%A')})\n", " df['vertical'] = kapuhala_list(weighted_list, df['weekday'].values.tolist(), len(df))\n", " #add weekend topic on fridays\n", " df.loc[df[df['weekday']=='Friday'].index.tolist(), 'vertical'] = 'weekend'\n", " df\n", "\n", " df_ = df[0:max_days]\n", " df_\n", "\n", " dict1 = {\n", " 'yogaClasses' : \"\"\"\n", " 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!\n", " \"\"\",\n", " 'swim' : \"\"\"\n", " At Halapua Restaurant we offer a Mediterranean-inspired menu using fresh seasonal ingredients and vegetables.\n", " 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.\n", " \"\"\",\n", " 'mixology' : \"\"\"\n", " 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!\n", " \"\"\",\n", " 'happyHour' : \"\"\"\n", " Come for the happy hour at Kapuhala Koh Samui from 3pm to 6pm.\n", " By getting 2 drinks you will receive a complimentary plate of snack from our kitchen! \n", " \"\"\",\n", " 'weekend' : \"\"\"\n", " Pass your Weekend with us at Kapuhala Koh Samui! \n", " Book a table on the best plant based restaurant on the island.\n", " Sicilian inspired cuisine made with local ingredients.\n", " \"\"\",\n", " 'wedding' : \"\"\"\n", " Wedding reception or honeymoon at Kapuhala.\n", " Our gorgeous, secluded spot offers everything you need for an unforgettable, intimate event.\n", " 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.\n", " Experience the paradise of Kapuhala! Plan your dream wedding or honeymoon here and let us make it all happen\n", " \"\"\",\n", " 'tentedVilla' : \"\"\"\n", " Book our TENTED VILLA at Kapuhala Koh Samui - Live Without Walls!\n", " Sleeps 2 adults (Max with 1-2 more kids)\n", " 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.\n", " 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.\n", " 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.\n", " \"\"\",\n", " 'farmhouse' : \"\"\"\n", " Kapuhala Koh Samui - Farmhouse\n", " 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.\n", " 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.\n", " Wake up daily to a serene sea view of the bay and enjoy the breath taking sunrises on your private balcony.\n", " \"\"\",\n", " 'retreats' : \"\"\"\n", " Are you ready to take your mental and physical capabilities to the next level?\n", " Yoga, Fitness and Nutrition!\n", " Come join us at Kapuhala for an exclusive Superhuman retreat and experience the power of true, natural Biohacking.\n", " 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.\n", " Through our 5 day protocol you'll be able to maximize your mental performance, increase creativity, and optimize physical performance.\n", " What are you waiting for? Join us at Kapuhala and unlock your superhuman capabilities!\n", " We can also help you organize a tailor made retreat on the dates that best suit your needs.\n", " \"\"\"\n", " }\n", "\n", " prompt = 'Write a social media post-caption about this: add emoji, add hashtags at the end :'\n", " df_['prompt'] = df_['vertical'].apply(lambda x : prompt+dict1[x])\n", " # df_ = df_[0:3]\n", "\n", " \n", " df_['post'] = df_['prompt'].apply(lambda x : gpt3(x, model='gpt-3.5-turbo', service='azure'))\n", " # df_['post'] = df_['prompt'].apply(lambda x : 'mmm')\n", " return df_.drop('prompt', axis=1)\n", "\n", "df_content = generate_content(11, 2)\n", "df_content" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "generate_content" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "c:\\Users\\ardit\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\gradio\\deprecation.py:43: UserWarning: You have unused kwarg parameters in Radio, please remove them: {'multiselect': False}\n", " warnings.warn(\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Running on local URL: http://127.0.0.1:7865\n", "\n", "To create a public link, set `share=True` in `launch()`.\n" ] }, { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" }, { "name": "stderr", "output_type": "stream", "text": [ "C:\\Users\\ardit\\AppData\\Local\\Temp\\ipykernel_21100\\3657193565.py:78: SettingWithCopyWarning: \n", "A value is trying to be set on a copy of a slice from a DataFrame.\n", "Try using .loc[row_indexer,col_indexer] = value instead\n", "\n", "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n", " df_['prompt'] = df_['vertical'].apply(lambda x : prompt+dict1[x])\n", "C:\\Users\\ardit\\AppData\\Local\\Temp\\ipykernel_21100\\3657193565.py:82: SettingWithCopyWarning: \n", "A value is trying to be set on a copy of a slice from a DataFrame.\n", "Try using .loc[row_indexer,col_indexer] = value instead\n", "\n", "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n", " df_['post'] = df_['prompt'].apply(lambda x : gpt3(x, model='gpt-3.5-turbo', service='azure'))\n" ] } ], "source": [ "import gradio as gr\n", "\n", "with gr.Blocks(theme=gr.themes.Soft(primary_hue='amber', secondary_hue='gray', neutral_hue='amber')) as demo:\n", " gr.Markdown(\n", " \"\"\"\n", " # Content Calendar Generator\n", " \"\"\"\n", " )\n", " # input1 = gr.Slider(1, 31, value=5, step_size=10, label=\"# Days\")\n", " input1 = gr.Slider(1, 12, step=1, value=5, label=\"Month\")\n", " input2 = gr.Radio([1, 3, 5, 10, 30], multiselect=False, label='# Days', value=3)\n", " # input3 = gr.Radio(['Manhattan', 'Brooklyn', 'Queens', 'Bronx'], multiselect=False, label='State', value='Brooklyn')\n", " # input4 = gr.Textbox(label='Query', value='I want to take a break from work 😴!!!')\n", "\n", " btn = gr.Button(value=\"Generate Content\")\n", " output1 = gr.Dataframe()\n", " # btn.click(greet, inputs='text', outputs=['dataframe'])\n", " btn.click(generate_content, [input1, input2], [output1])\n", "demo.launch(share=False)" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "c:\\Users\\ardit\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\gradio\\deprecation.py:43: UserWarning: You have unused kwarg parameters in Radio, please remove them: {'multiselect': False}\n", " warnings.warn(\n", "c:\\Users\\ardit\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\gradio\\utils.py:951: UserWarning: Expected 0 arguments for function , received 1.\n", " warnings.warn(\n", "c:\\Users\\ardit\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\gradio\\utils.py:959: UserWarning: Expected maximum 0 arguments for function , received 1.\n", " warnings.warn(\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Running on local URL: http://127.0.0.1:7861\n", "\n", "To create a public link, set `share=True` in `launch()`.\n" ] }, { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" }, { "name": "stderr", "output_type": "stream", "text": [ "C:\\Users\\ardit\\AppData\\Local\\Temp\\ipykernel_21100\\1929261880.py:58: SettingWithCopyWarning: \n", "A value is trying to be set on a copy of a slice from a DataFrame.\n", "Try using .loc[row_indexer,col_indexer] = value instead\n", "\n", "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n", " df_['prompt'] = df_['vertical'].apply(lambda x : prompt+dict1[x])\n", "C:\\Users\\ardit\\AppData\\Local\\Temp\\ipykernel_21100\\1929261880.py:62: SettingWithCopyWarning: \n", "A value is trying to be set on a copy of a slice from a DataFrame.\n", "Try using .loc[row_indexer,col_indexer] = value instead\n", "\n", "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n", " df_['post'] = df_['prompt'].apply(lambda x : gpt3(x, model='gpt-3.5-turbo', service='azure'))\n" ] } ], "source": [ "import gradio as gr\n", "\n", "def foo():\n", " return 0\n", "\n", "with gr.Blocks(theme=gr.themes.Soft(primary_hue='amber', secondary_hue='gray', neutral_hue='amber')) as demo:\n", " gr.Markdown(\n", " \"\"\"\n", " # Message generator\n", " \"\"\"\n", " )\n", " input1 = gr.Textbox(label='Input data', placeholder='Insert data from Linkedin here')\n", " input2 = gr.Radio(['Phishing', 'Sale', 'Feedback'], multiselect=False, label='Type of message')\n", " input3 = gr.Radio(['Linkedin', 'Instagram', 'Website'], multiselect=False, label='Source of information')\n", " # input3 = gr.Radio(['Manhattan', 'Brooklyn', 'Queens', 'Bronx'], multiselect=False, label='State', value='Brooklyn')\n", " # input4 = gr.Textbox(label='Query', value='I want to take a break from work 😴!!!')\n", "\n", " btn = gr.Button(value=\"Generate Message\")\n", " output1 = gr.Textbox()\n", " # btn.click(greet, inputs='text', outputs=['dataframe'])\n", " btn.click(foo, [input1], [output1])\n", "demo.launch(share=False)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.13" }, "orig_nbformat": 4 }, "nbformat": 4, "nbformat_minor": 2 }