File size: 1,517 Bytes
763746b f2f4bb0 763746b f2f4bb0 763746b f2f4bb0 763746b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
import pandas as pd
from transformers import pipeline
from google.colab import files # Only needed if running in Google Colab
# Function to enhance title using Hugging Face model
def generate_title_with_huggingface(description):
result = generator(description, max_length=100, num_return_sequences=1)
return result[0]['generated_text']
# If running in Google Colab, use files.upload() to upload the CSV
# For local environment, you can replace this with a file path directly
uploaded = files.upload()
# Assuming the file name is 'output.csv' after upload
file_name = list(uploaded.keys())[0]
# Load the CSV file
df = pd.read_csv(file_name)
# Initialize the text generation model (e.g., GPT-2)
generator = pipeline('text-generation', model='gpt-2')
# Apply the function to generate SEO-friendly titles
df['Title'] = df['Description'].apply(generate_title_with_huggingface)
# Function to generate keywords (basic example)
def generate_keywords(description):
words = set(description.replace(',', '').replace('.', '').split())
return ",".join(list(words)[:50])
# Generate basic keywords from the description (you can enhance this further)
df['Keywords'] = df['Description'].apply(generate_keywords)
# Save the SEO-optimized DataFrame to a new CSV file
seo_output_file_path = 'seo_huggingface_filename_title_keywords.csv'
df[['Filename', 'Title', 'Keywords']].to_csv(seo_output_file_path, index=False)
# Download the resulting CSV file (if running in Colab)
files.download(seo_output_file_path)
|