LP-Generator / app.py
hamza
initial commit
6a96373 verified
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)