File size: 6,076 Bytes
7a05cac
80b662f
62a9d97
 
7a05cac
62a9d97
80b662f
62a9d97
80b662f
5d7a0c8
62a9d97
 
5d7a0c8
 
80b662f
62a9d97
5d7a0c8
 
 
62a9d97
5d7a0c8
62a9d97
 
 
5d7a0c8
 
62a9d97
 
 
 
 
 
 
 
 
5d7a0c8
62a9d97
 
5d7a0c8
62a9d97
80b662f
5d7a0c8
62a9d97
 
 
 
 
 
 
 
 
 
 
 
5d7a0c8
62a9d97
5d7a0c8
 
 
 
 
 
 
 
 
 
62a9d97
5d7a0c8
 
 
 
 
 
 
 
 
80b662f
5d7a0c8
62a9d97
 
 
 
 
5d7a0c8
62a9d97
 
 
 
 
 
 
 
 
 
 
 
 
5d7a0c8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62a9d97
 
 
 
 
 
 
 
 
 
 
5d7a0c8
62a9d97
 
 
5d7a0c8
62a9d97
5d7a0c8
62a9d97
 
 
 
 
 
 
5d7a0c8
62a9d97
 
 
 
 
 
 
 
 
80b662f
62a9d97
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import gradio as gr
import google.generativeai as genai
import os
import json

def generate_pinterest_content(api_key, blog_title):
    try:
        # Configure the Gemini API
        genai.configure(api_key=api_key)

        # Set up the model
        model = genai.GenerativeModel('gemini-1.5-pro')

        # Create the prompt
        prompt = f"""
        You are a Pinterest SEO expert specializing in fermentation content (kombucha, kefir, kimchi, sauerkraut, etc.).

        Transform this blog title: \"{blog_title}\" 

        Into a complete Pinterest marketing package. For each of the 5 variations, provide:

        1. Pinterest Title: Highly engaging, under 60 characters when possible
        2. Pinterest Description: 150-300 characters with targeted keywords
        3. Benefit or Hook: A specific, compelling benefit statement
        4. CTA Button Text: Action-focused text for the button (e.g., \"Learn More\", \"Try This Recipe\")
        5. Social Proof Statement: A line that builds credibility (e.g., \"Loved by 5,000+ home fermenters\")
        6. Pinterest Tags/Keywords: 5-7 relevant keywords (comma-separated)

        Format each variation as a JSON object with these fields:
        - title
        - description
        - benefit_hook
        - cta_button
        - social_proof
        - tags

        Return an array with 5 of these JSON objects.
        """

        # Generate response
        response = model.generate_content(prompt)

        # Parse the response as JSON
        try:
            result = json.loads(response.text)
        except json.JSONDecodeError:
            response_text = response.text
            start_idx = response_text.find('[')
            end_idx = response_text.rfind(']') + 1
            if start_idx >= 0 and end_idx > start_idx:
                json_str = response_text[start_idx:end_idx]
                try:
                    result = json.loads(json_str)
                except json.JSONDecodeError:
                    return "", "", "", "", "", "", f"Error parsing JSON from response: {response_text}"
            else:
                return "", "", "", "", "", "", f"Could not find JSON array in response: {response_text}"

        # Separate outputs into categories
        titles = []
        descriptions = []
        hooks = []
        ctas = []
        proofs = []
        tags = []

        for i, variation in enumerate(result, 1):
            titles.append(f"{i}. {variation.get('title', 'N/A')}")
            descriptions.append(f"{i}. {variation.get('description', 'N/A')}")
            hooks.append(f"{i}. {variation.get('benefit_hook', 'N/A')}")
            ctas.append(f"{i}. {variation.get('cta_button', 'N/A')}")
            proofs.append(f"{i}. {variation.get('social_proof', 'N/A')}")
            tags.append(f"{i}. {variation.get('tags', 'N/A')}")

        return "\n\n".join(titles), "\n\n".join(descriptions), "\n\n".join(hooks), "\n\n".join(ctas), "\n\n".join(proofs), "\n\n".join(tags), "βœ… Pinterest content generated successfully."

    except Exception as e:
        return "", "", "", "", "", "", f"Error generating Pinterest content: {str(e)}"

# Create the Gradio interface
with gr.Blocks(theme=gr.themes.Soft(primary_hue="green")) as app:
    gr.Markdown("# 🌱 Pinterest Content Generator for Fermentation Blog")
    gr.Markdown("Transform your blog titles into complete Pinterest marketing packages to drive traffic to your fermentation website.")

    with gr.Row():
        with gr.Column():
            api_key = gr.Textbox(
                label="Gemini API Key", 
                placeholder="Enter your Gemini API key...",
                type="password"
            )
            blog_title = gr.Textbox(
                label="Blog Post Title",
                placeholder="Enter your original blog post title here...",
                lines=2
            )
            submit_btn = gr.Button("Generate Pinterest Content", variant="primary")

    with gr.Row():
        title_output = gr.Textbox(label="πŸ“Œ Pinterest Titles", lines=10)
        description_output = gr.Textbox(label="πŸ“ Descriptions", lines=10)

    with gr.Row():
        hook_output = gr.Textbox(label="🎯 Benefits or Hooks", lines=10)
        cta_output = gr.Textbox(label="πŸ‘† CTA Buttons", lines=10)

    with gr.Row():
        proof_output = gr.Textbox(label="πŸ‘₯ Social Proof Statements", lines=10)
        tag_output = gr.Textbox(label="πŸ”‘ Pinterest Tags", lines=10)

    status_output = gr.Markdown("πŸ‘† Click the button above to generate Pinterest content.")

    gr.Examples(
        [
            ["How to Make Milk Kefir at Home"],
            ["Kombucha Brewing Guide for Beginners"],
            ["10 Health Benefits of Fermented Foods"],
            ["Troubleshooting Common Sauerkraut Problems"],
            ["Easy Kimchi Recipe for First-time Fermenters"]
        ],
        inputs=blog_title,
        label="Example Blog Titles"
    )

    submit_btn.click(
        fn=generate_pinterest_content,
        inputs=[api_key, blog_title],
        outputs=[title_output, description_output, hook_output, cta_output, proof_output, tag_output, status_output]
    )

    gr.Markdown("""
    ### πŸ“Š Pinterest Stats for Fermentation Content
    - 89% of Pinterest users are actively looking for inspiration for projects
    - Food & Recipe pins have 5x higher engagement than average pins
    - "How-to" pins get 30% more engagement than other types
    - Pins with testimonials have 35% higher click-through rates
    - Most active fermentation enthusiasts use Pinterest daily

    ### πŸ“Œ Tips for Pinterest Success
    - Pin at optimal times: 8-11pm and 2-4am EST
    - Use vertical images with 2:3 ratio (1000px by 1500px is ideal)
    - Include your keyword in the first 60 characters
    - Create multiple pins for the same content with different visuals
    - Join group boards focused on natural food, gut health, and fermentation
    - Use Rich Pins to automatically include metadata from your website
    """)

if __name__ == "__main__":
    app.launch()