Prompt Title: Improvment_product_generator

Created 1 year ago
Votes 0
Views 194 times
IT
0

Prompt Detail:

Here's an improved version of the code:

  1. It provides an English version for generating product descriptions by switching between languages.
  2. It reduces repeated user inputs by leveraging input from the Excel sheet.
  3. It allows the user to start a script by clicking a button in Excel.
python
import pandas as pd import openai def read_input(file_name, sheet_name): return pd.read_excel(file_name, sheet_name=sheet_name) def adjust_input(df): df['price'] = df['price'].apply(lambda x: str(x).replace('$', '').replace(',', '')) df['price_color'] = ', Price: ' + df['price'] + ' CZK, Color options: (' + df['color options'] + ')' df['key_attributes_adj'] = df['key attributes'] + df['price_color'] return df def generate_text(prompt_input, language): openai.api_key = "your-api-key" model_name = "text-davinci-003" if language == "en" else "text-davinci-multilingual-003" response = openai.Completion.create( model=model_name, prompt=prompt_input, temperature=0.7, max_tokens=985, top_p=1, frequency_penalty=0, presence_penalty=0 ) return response.choices[0].text def construct_prompt(df_row, language): product_name = df_row["Name"] target_audience = df_row["target audience"] key_attributes = df_row["key_attributes_adj"] goals = df_row["goals for product description"] if language == "en": prompt = f"Create an English product description for {product_name} targeting {target_audience}. Include the following key attributes: {key_attributes}. The description should fulfill these goals: {goals}." else: prompt = f"Vytvořte český popis produktu {product_name} pro cílovou skupinu {target_audience}. Zahrňte následující klíčové vlastnosti: {key_attributes}. Popis by měl splňovat tyto cíle: {goals}." return prompt def create_descriptions(df, language): descriptions = [] for _, row in df.iterrows(): prompt = construct_prompt(row, language) description = generate_text(prompt, language) descriptions.append(description) return descriptions def save_output(df, file_name, sheet_name): df.to_excel(file_name, sheet_name=sheet_name, index=False) def main(): input_file = "input.xlsx" output_file = "output.xlsx" language = "en" # Change this to "cs" for Czech language # Read input and adjust it df = read_input(input_file, "Data") df = adjust_input(df) # Create product descriptions descriptions = create_descriptions(df, language) df["description"] = descriptions # Save output to a new sheet in the same file save_output(df, output_file, "Output") if __name__ == "__main__": main()

For the VBA script to add a button in Excel, follow these steps:

  1. Open your Excel file and navigate to the "Developer" tab.
  2. Click "Insert" and choose "Button (Form Control)".
  3. Draw a button on the worksheet.
  4. Double-click the button, and the VBA editor will open.
  5. Copy and paste the following VBA code:
vba
Sub Button1_Click()
avatar
Matěj Konečný
Shared 1 prompt
Created 1 year ago

Leave a Comment

Related Tag Prompts

271
0
Python Pro
1 year ago 2023-01-19 05:16:28 AIPRM
0
0
MySQL Database Creation.
1 year ago 2023-03-08 12:23:48 Pub
0
0
Cool stuff
1 year ago 2023-03-08 15:49:26 Sivayogeith
0
0
Bajar version de python
1 year ago 2023-03-09 10:48:33 Juanma
0
0
Frappe
1 year ago 2023-03-11 01:40:59 KuuKuu
0
0
0
0
python remote control server
1 year ago 2023-03-11 23:05:25 V0rt
0
0
output
1 year ago 2023-03-14 07:09:17 yuvaraj
0
0
s-parameter processing in python
1 year ago 2023-03-14 14:46:13 jhdo
0
0
Python Landsat data handling.
1 year ago 2023-03-15 13:10:40 nathan
0
0
Python para Ciencia Datos
1 year ago 2023-03-16 08:24:10 pedro
0
0
Following Rotated Logfiles.
1 year ago 2023-03-17 09:05:24 hamid
0
0
Modelo de Negócio.
1 year ago 2023-03-18 01:35:57 reiu
0
0
Django API for Todo
1 year ago 2023-03-18 17:45:33 AbdAlmjed
0
0
python爬虫
1 year ago 2023-03-21 00:23:14 DDL
0
0
portable python environment
1 year ago 2023-03-22 12:34:38 Xing