import csv from openai import OpenAI # API keys and clients setup hf2 = "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" model_key = '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' client = OpenAI(api_key=model_key) import csv def delete_first_element(csv_file_path): """ Deletes the first element (top-left cell) of a CSV file. Args: csv_file_path (str): Path to the CSV file. Returns: None """ # Read the CSV contents with open(csv_file_path, mode='r', newline='', encoding='utf-8') as file: reader = list(csv.reader(file)) # Modify the first row if it exists and has at least one element if reader and reader[0]: reader[0] = reader[0][1:] # Remove the first element of the first row # Write the modified contents back to the file with open(csv_file_path, mode='w', newline='', encoding='utf-8') as file: writer = csv.writer(file) writer.writerows(reader) def call_genai(prompt): model = "gpt-4.1" #model = "gpt-4.1-mini-2025-04-14" completion = client.chat.completions.create( model=model, messages=[ { "role": "user", "content": prompt } ] ) # print(completion.choices[0].message.content) return completion.choices[0].message.content def read_first_element(csv_file_path): """ Reads the first element (top-left cell) of a CSV file. Args: csv_file_path (str): Path to the CSV file. Returns: str: The first element of the CSV file, or None if file is empty. """ with open(csv_file_path, mode='r', newline='', encoding='utf-8') as file: reader = csv.reader(file) for row in reader: if row: # Make sure the row is not empty return row[0] # Return the first element of the first row return None # In case the file is empty or has no valid rows def get_article_obj(file_path): main_keyword = read_first_element(file_path) content = call_genai(f'I want to write an article on this topic: {main_keyword}. Can you cover everything about this topic in 1000 words. Output only the content.') keywords = call_genai(f'I want 5 to 10 keywords/keyphrases that are related to this content: {content}. Output only the keywords/keyphrases in a comma separated list. No other text.') content_obj = { 'body': content, 'keywords': keywords } print(content_obj) #delete_first_element(file_path) return content_obj # get_article_obj('final_queries_list_for_blogs.csv')