abiabidali commited on
Commit
763746b
·
verified ·
1 Parent(s): ed8a9f9

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -0
app.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Install necessary packages
2
+ !pip install transformers pandas google-colab
3
+
4
+ import pandas as pd
5
+ from transformers import pipeline
6
+ from google.colab import files
7
+
8
+ # Function to enhance title using Hugging Face model
9
+ def generate_title_with_huggingface(description):
10
+ result = generator(description, max_length=100, num_return_sequences=1)
11
+ return result[0]['generated_text']
12
+
13
+ # Upload the CSV file
14
+ uploaded = files.upload()
15
+
16
+ # Assuming the file name is 'output.csv' after upload
17
+ file_name = list(uploaded.keys())[0]
18
+
19
+ # Load the CSV file
20
+ df = pd.read_csv(file_name)
21
+
22
+ # Initialize the text generation model (e.g., GPT-2)
23
+ generator = pipeline('text-generation', model='gpt-2')
24
+
25
+ # Apply the function to generate SEO-friendly titles
26
+ df['Title'] = df['Description'].apply(generate_title_with_huggingface)
27
+
28
+ # Function to generate keywords (basic example)
29
+ def generate_keywords(description):
30
+ words = set(description.replace(',', '').replace('.', '').split())
31
+ return ",".join(list(words)[:50])
32
+
33
+ # Generate basic keywords from the description (you can enhance this further)
34
+ df['Keywords'] = df['Description'].apply(generate_keywords)
35
+
36
+ # Save the SEO-optimized DataFrame to a new CSV file
37
+ seo_output_file_path = 'seo_huggingface_filename_title_keywords.csv'
38
+ df[['Filename', 'Title', 'Keywords']].to_csv(seo_output_file_path, index=False)
39
+
40
+ # Download the resulting CSV file
41
+ files.download(seo_output_file_path)