forked from IncomeStreamSurfer/chatgptassistantautoblogger
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
41b82fd
commit 4a5115c
Showing
2 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
post_title,post_content,post_excerpt,post_date,post_name,post_author,post_status,featured_image,PRODUCTSKU,visibility,tax_status,product_type,product_attribute_name,product_attribute_value,product_attribute_visible,product_attribute_variation,product_attribute_position,product_attribute_taxonomy,tax_class,manage_stock,stock,stock_status,low_stock_threshold,stock_qty,downloadable,virtual,regular_price,sale_price,purchase_note,menu_order,comment_status,weight,length,width,height,upsell_ids,crosssell_ids,price,sold_individually,backorders,product_image_gallery,product_url,button_text,featured,downloadable_files,download_limit,download_expiry,product_category,product_tag | ||
WP Ultimate CSV Importer,Type your product content here,Type your product description here,2019-01-01,csv-importer,userloginname1,publish,https://upload.wikimedia.org/wikipedia/commons/thumb/9/98/WordPress_blue_logo.svg/1200px-WordPress_blue_logo.svg.png,ersdd23100,1,none,4,color|size,"red|green|blue,small|medium|large",1|1,1|1,0|1,1|1,zero-rate,yes,5,instock,3,5,no,no,,,Purchase note here,1,open,5,5,5,5,mention the ID of the product here,mention the ID of the product here,33,yes,yes,https://assets.smackcoders.com/wp-content/uploads/2018/03/CSV-Importer-Logo.png|https://www.techmakroti.com/wp-content/uploads/2019/05/Image-Optimization.jpg|https://s.w.org/images/backgrounds/wordpress-bg-medblue-square.png,,,1,,,,"WordPress,Importer,Import>Export","csv,importer,exporter" | ||
Email Customizer for WooCommerce,Type your content here,Type your product description here,2019-01-01,email-customizer-for-woocommerce-2,userloginname2,publish,https://upload.wikimedia.org/wikipedia/commons/thumb/9/98/WordPress_blue_logo.svg/1200px-WordPress_blue_logo.svg.png,ersdd23101,1,none,3,size,medium|large,1,0,0,1,zero-rate,no,,instock,,,no,no,100,99,,4,open,,,,,mention the ID of the product here,mention the ID of the product here,99,no,no,https://assets.smackcoders.com/wp-content/uploads/2018/03/Email-Customizer-Logo.png,https://www.smackcoders.com/email-customizer-woocommerce-pro.html,Email Customizer,0,,,,"wooCommerce,email,Template,Import>Export","email,customtemplates" | ||
WP Leads Builder for any CRM,Type your product content here,Type your product description here,2019-01-01,wp-leads-builder-for-any-crm,userloginname3,publish,https://upload.wikimedia.org/wikipedia/commons/thumb/9/98/WordPress_blue_logo.svg/1200px-WordPress_blue_logo.svg.png,ersdd23102,1,shipping,1,color|size,"green|blue,small|large",1|1,0|0,0|1,1|1,zero-rate,yes,5,instock,1,5,yes,yes,139,99,Purchase note,2,closed,,,,,mention the ID of the product here,mention the ID of the product here,99,yes,notify,https://assets.smackcoders.com/wp-content/uploads/2018/03/Lead-Builder-logo.png,,,0,"Product-link,https://trial.smackcoders.com/wpbpynnd/wp-content/uploads/2020/03/Marksmanship-hunter-Battleground-pvp-wow.3.3.5a-6.jpg",10,10,"Leads,Contacts,WordPress,CRM>Extensions","form,capture,leads, contacts" | ||
WP Advanced Importer,,Type your product description here,2019-01-01,wp-advanced-importer,userloginname4,publish,https://upload.wikimedia.org/wikipedia/commons/thumb/9/98/WordPress_blue_logo.svg/1200px-WordPress_blue_logo.svg.png,ersdd23103,1,taxable,2,color,green|blue,1,0,0,1,zero-rate,no,,instock,,,no,no,,,,3,open,,,,,mention the ID of the product here,mention the ID of the product here,,no,no,https://prologicwebdesign.com/blog/wp-content/uploads/2016/02/PLUGIN.jpg,,,1,,,,"WordPress,Importer,Import,Export","xml,importer,free" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import pandas as pd | ||
import openai | ||
from tqdm.auto import tqdm | ||
|
||
# Initialize tqdm for pandas | ||
tqdm.pandas() | ||
|
||
# Your OpenAI API key | ||
openai.api_key = 'your_api_key' | ||
|
||
# Define the translation function with custom prompts | ||
def translate(text, target_language, column_name): | ||
if pd.isna(text) or text.strip() == "": | ||
return "" | ||
|
||
prompts = { | ||
"post_title": f"Transcreate this meta title into {target_language} - You are writing for COMPANY_NAME_HERE - Do not translate Brand Names or Specific Names of products.", | ||
"post_content": f"Without translating directly, but transcreating, Write a simple, direct version of the content in {target_language}, at a grade 7 reading level. Do not translate Brand Names or Names or Products", | ||
"post_excerpt": f"Without translating directly, but transcreating, Write a simple, direct version of the content in {target_language}, at a grade 7 reading level. Do not translate Brand Names or Names or Products", | ||
} | ||
|
||
system_prompt = prompts.get(column_name, "Write anything such as do not translate this word or use this word instead of this word etc here.") | ||
|
||
print(f"Translating '{text[:50]}...' from column '{column_name}' to {target_language}.") # Print before translation | ||
|
||
try: | ||
response = openai.ChatCompletion.create( | ||
model="gpt-4-turbo-preview", | ||
messages=[{"role": "system", "content": system_prompt}, | ||
{"role": "user", "content": text}], | ||
temperature=0.2, | ||
max_tokens=2000, | ||
top_p=1.0, | ||
frequency_penalty=0.0, | ||
presence_penalty=0.0, | ||
) | ||
translated_text = response.choices[0].message['content'].strip() | ||
print(f"API Response: {translated_text[:200]}") # This prints the first 200 characters of the API response | ||
return translated_text | ||
except Exception as e: | ||
print(f"Error during translation of '{text[:50]}...' to {target_language}: {e}") | ||
return "Translation Error" | ||
|
||
# Load your CSV file | ||
print("Loading CSV file...") | ||
df = pd.read_csv("WooCommerce-Products-Import-csv-sample-file.csv") | ||
|
||
# Specify target languages | ||
languages = ["German", "French", "Dutch"] | ||
|
||
# Translate content | ||
for col in df.columns: | ||
for lang in languages: | ||
print(f"Starting translation of column '{col}' to {lang}.") # Print before starting column translation | ||
df[f"{col}_{lang}"] = df[col].progress_apply(lambda x: translate(x, lang, col)) | ||
print(f"Completed translations for column '{col}' to {lang}.") # Print after completing column translation | ||
|
||
# Save the processed DataFrame to a new CSV file | ||
output_file = "translated_content.csv" | ||
df.to_csv(output_file, index=False) | ||
print("Translation complete. Output saved to", output_file) |