|
import pandas as pd |
|
from transformers import pipeline |
|
|
|
|
|
def generate_title_with_huggingface(description): |
|
result = generator(description, max_length=100, num_return_sequences=1) |
|
return result[0]['generated_text'] |
|
|
|
|
|
file_name = 'input.csv' |
|
df = pd.read_csv(file_name) |
|
|
|
|
|
generator = pipeline('text-generation', model='gpt-2') |
|
|
|
|
|
df['Title'] = df['Description'].apply(generate_title_with_huggingface) |
|
|
|
|
|
def generate_keywords(description): |
|
words = set(description.replace(',', '').replace('.', '').split()) |
|
return ",".join(list(words)[:50]) |
|
|
|
|
|
df['Keywords'] = df['Description'].apply(generate_keywords) |
|
|
|
|
|
seo_output_file_path = 'seo_huggingface_filename_title_keywords.csv' |
|
df[['Filename', 'Title', 'Keywords']].to_csv(seo_output_file_path, index=False) |
|
|
|
|
|
print(f"File saved as {seo_output_file_path}") |
|
|