File size: 4,264 Bytes
6a96373
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
import gradio as gr
from mistralai import Mistral

# Set up the Mistral client with your API key
api_key = os.environ.get("MISTRAL_API_KEY", "0PzDuZAQnXhs5OkJb7Xg5PBYbweg9dWB")
client = Mistral(api_key=api_key)

# Define the function that interacts with your AI agent


def generate_landing_page(product_name, product_description, audience, language, country_name):
    message = (
        f"Create a persuasive landing page for the following product with a warm, elegant feel:\n"
        f"Product Name: {product_name}\n"
        f"Product Description: {product_description}\n"
        f"Audience: {audience}\n"
        f"Language: {language}\n"
        f"Country Name: {country_name}\n"
        f"Instructions: Use a soft, welcoming tone with aspirational phrases (e.g., 'imagine,' 'savour'). "
        f"Highlight gentle emotional hooks (e.g., calm, joy, pride) and clear benefits (e.g., ease, quality). "
        f"For 'Before and After,' write vivid, relatable stories with names and cities from {country_name}. "
        f"Format in Markdown: use # for main title (once), ### for section headings, minimal bolding (only key phrases), "
        f"and subtle separators like '⋆ ⋆ ⋆' between sections. Keep it airy with line breaks, no dense text."
    )

    chat_response = client.agents.complete(
        agent_id="ag:a858b0eb:20250223:expert-copywriter-for-landing-page-creation:d736839f",
        messages=[{"role": "user", "content": message}]
    )

    return chat_response.choices[0].message.content


# Create the Gradio interface with a polished design
with gr.Blocks(
    theme=gr.themes.Soft()
) as demo:
    # Elegant header
    gr.Markdown(
        "# Powerful Landing Page Generator",
    )

    # Input section with balanced layout
    with gr.Row(variant="panel"):
        with gr.Column(scale=1):
            product_name = gr.Textbox(
                label="Product Name",
                placeholder="Enter your product name",
                lines=1,
                interactive=True,
            )
            product_description = gr.Textbox(
                label="Product Description",
                placeholder="Describe your product carefully",
                lines=4,
                interactive=True,
            )
            audience = gr.Radio(
                choices=["Men", "Women", "Both"],
                label="Target Audience",
                value="Both",
                info="Who are you targeting?",
            )

        with gr.Column(scale=1):
            language = gr.Dropdown(
                choices=["French", "English", "Spanish", "Arabic"],
                label="Language",
                value="English",
                info="Choose the language",
            )
            country_name = gr.Textbox(
                label="Country",
                placeholder="Enter the target country",
                lines=1,
                interactive=True,
            )

    # Button with native loading feedback via queue
    generate_btn = gr.Button(
        "Generate Landing Page",
        variant="primary",
        size="lg",
    )

    # Output in a card-like group
    with gr.Group():
        output = gr.Markdown(
            value="Your page will appear here once generated...",
            min_height=100,
            label="Your Landing Page",
            show_label=True,
            show_copy_button=True,
            container=True,
            header_links=True
        )

    # Connect button to function with queue for spinner
    generate_btn.click(
        fn=generate_landing_page,
        inputs=[product_name, product_description,
                audience, language, country_name],
        outputs=output
    )

    # Footer with instructions
    with gr.Row():
        gr.Markdown(
            "### How to Use\n"
            "1. Enter the product name and description.\n"
            "2. Select the audience and language.\n"
            "3. Specify the country for a local touch.\n"
            "4. Click 'Generate' for a refined result.",
        )

# Launch with queue for built-in loading feedback
demo.queue().launch(share=True, debug=True)