abiabidali's picture
Update app.py
45b71d5 verified
raw
history blame
1.34 kB
import pandas as pd
from transformers import pipeline
# 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']
# Load the CSV file directly (replace 'input.csv' with your actual file path)
file_name = 'input.csv' # Update this with the correct path to your 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)
# The output file will be saved in the current working directory
print(f"File saved as {seo_output_file_path}")