import pandas as pd import swifter def get_website_layout_prompt(page, instructions, pov, element, csv_prompt=None): if csv_prompt: return csv_prompt else: prompt = f''' % You are a website designer creating text for the {page} of the website % Goal: Create content for the Element according to the Writing Guidelines and Point of View. Only output the edited content. % Writing Guidelines: ```{instructions}``` % Point of View: ```{pov}``` % Element: ```{element}``` % Instructions: Step 1 - First write content for the element according to the Writing Guidelines and Point of View. Step 2 - Add relevant company information from the context to the content to make it more personalized and detailed Step 3 - If the Writing Guidelines mention a specific word/character count, use Python to calculate word count of your response to Step 1. If the Step 1 word count exceeds the Writing Guidelines word count, edit the content so that it adheres to the Writing Guidelines. Step 4 - Edit the content so that it adheres to the Point of View if applicable. Step 5 - Only output the edited content. ''' return prompt def get_website_content(row, query_engine): # gets website content based on spreadsheet try: if pd.notna(row['Suggested Word/Character Count']): if row['Suggested Word/Character Count'] != 'Not applicable for SEO': page = row['Page Type'] instructions = row['Suggested Word/Character Count'] pov = row['Point of View'] element = row['Section Piece (Element)'] if pd.notna(row['Prompt']): prompt = row['Prompt'] response = query_engine.query(get_website_layout_prompt(page, instructions, pov, element, csv_prompt=prompt)) else: response = query_engine.query(get_website_layout_prompt(page, instructions, pov, element)) print(response) return response.response else: return row['Content'] else: return row['Content'] except: return 'Could not Process this row' def get_content_csv(csv_file, query_engine): df = pd.read_csv(csv_file.name) df['Content'] = df.swifter.apply(lambda row: get_website_content(row, query_engine), axis=1) return df