hamza commited on
initial commit
Browse files
app.py
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from mistralai import Mistral
|
| 4 |
+
|
| 5 |
+
# Set up the Mistral client with your API key
|
| 6 |
+
api_key = os.environ.get("MISTRAL_API_KEY", "0PzDuZAQnXhs5OkJb7Xg5PBYbweg9dWB")
|
| 7 |
+
client = Mistral(api_key=api_key)
|
| 8 |
+
|
| 9 |
+
# Define the function that interacts with your AI agent
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def generate_landing_page(product_name, product_description, audience, language, country_name):
|
| 13 |
+
message = (
|
| 14 |
+
f"Create a persuasive landing page for the following product with a warm, elegant feel:\n"
|
| 15 |
+
f"Product Name: {product_name}\n"
|
| 16 |
+
f"Product Description: {product_description}\n"
|
| 17 |
+
f"Audience: {audience}\n"
|
| 18 |
+
f"Language: {language}\n"
|
| 19 |
+
f"Country Name: {country_name}\n"
|
| 20 |
+
f"Instructions: Use a soft, welcoming tone with aspirational phrases (e.g., 'imagine,' 'savour'). "
|
| 21 |
+
f"Highlight gentle emotional hooks (e.g., calm, joy, pride) and clear benefits (e.g., ease, quality). "
|
| 22 |
+
f"For 'Before and After,' write vivid, relatable stories with names and cities from {country_name}. "
|
| 23 |
+
f"Format in Markdown: use # for main title (once), ### for section headings, minimal bolding (only key phrases), "
|
| 24 |
+
f"and subtle separators like '⋆ ⋆ ⋆' between sections. Keep it airy with line breaks, no dense text."
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
chat_response = client.agents.complete(
|
| 28 |
+
agent_id="ag:a858b0eb:20250223:expert-copywriter-for-landing-page-creation:d736839f",
|
| 29 |
+
messages=[{"role": "user", "content": message}]
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
return chat_response.choices[0].message.content
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
# Create the Gradio interface with a polished design
|
| 36 |
+
with gr.Blocks(
|
| 37 |
+
theme=gr.themes.Soft()
|
| 38 |
+
) as demo:
|
| 39 |
+
# Elegant header
|
| 40 |
+
gr.Markdown(
|
| 41 |
+
"# Powerful Landing Page Generator",
|
| 42 |
+
)
|
| 43 |
+
|
| 44 |
+
# Input section with balanced layout
|
| 45 |
+
with gr.Row(variant="panel"):
|
| 46 |
+
with gr.Column(scale=1):
|
| 47 |
+
product_name = gr.Textbox(
|
| 48 |
+
label="Product Name",
|
| 49 |
+
placeholder="Enter your product name",
|
| 50 |
+
lines=1,
|
| 51 |
+
interactive=True,
|
| 52 |
+
)
|
| 53 |
+
product_description = gr.Textbox(
|
| 54 |
+
label="Product Description",
|
| 55 |
+
placeholder="Describe your product carefully",
|
| 56 |
+
lines=4,
|
| 57 |
+
interactive=True,
|
| 58 |
+
)
|
| 59 |
+
audience = gr.Radio(
|
| 60 |
+
choices=["Men", "Women", "Both"],
|
| 61 |
+
label="Target Audience",
|
| 62 |
+
value="Both",
|
| 63 |
+
info="Who are you targeting?",
|
| 64 |
+
)
|
| 65 |
+
|
| 66 |
+
with gr.Column(scale=1):
|
| 67 |
+
language = gr.Dropdown(
|
| 68 |
+
choices=["French", "English", "Spanish", "Arabic"],
|
| 69 |
+
label="Language",
|
| 70 |
+
value="English",
|
| 71 |
+
info="Choose the language",
|
| 72 |
+
)
|
| 73 |
+
country_name = gr.Textbox(
|
| 74 |
+
label="Country",
|
| 75 |
+
placeholder="Enter the target country",
|
| 76 |
+
lines=1,
|
| 77 |
+
interactive=True,
|
| 78 |
+
)
|
| 79 |
+
|
| 80 |
+
# Button with native loading feedback via queue
|
| 81 |
+
generate_btn = gr.Button(
|
| 82 |
+
"Generate Landing Page",
|
| 83 |
+
variant="primary",
|
| 84 |
+
size="lg",
|
| 85 |
+
)
|
| 86 |
+
|
| 87 |
+
# Output in a card-like group
|
| 88 |
+
with gr.Group():
|
| 89 |
+
output = gr.Markdown(
|
| 90 |
+
value="Your page will appear here once generated...",
|
| 91 |
+
min_height=100,
|
| 92 |
+
label="Your Landing Page",
|
| 93 |
+
show_label=True,
|
| 94 |
+
show_copy_button=True,
|
| 95 |
+
container=True,
|
| 96 |
+
header_links=True
|
| 97 |
+
)
|
| 98 |
+
|
| 99 |
+
# Connect button to function with queue for spinner
|
| 100 |
+
generate_btn.click(
|
| 101 |
+
fn=generate_landing_page,
|
| 102 |
+
inputs=[product_name, product_description,
|
| 103 |
+
audience, language, country_name],
|
| 104 |
+
outputs=output
|
| 105 |
+
)
|
| 106 |
+
|
| 107 |
+
# Footer with instructions
|
| 108 |
+
with gr.Row():
|
| 109 |
+
gr.Markdown(
|
| 110 |
+
"### How to Use\n"
|
| 111 |
+
"1. Enter the product name and description.\n"
|
| 112 |
+
"2. Select the audience and language.\n"
|
| 113 |
+
"3. Specify the country for a local touch.\n"
|
| 114 |
+
"4. Click 'Generate' for a refined result.",
|
| 115 |
+
)
|
| 116 |
+
|
| 117 |
+
# Launch with queue for built-in loading feedback
|
| 118 |
+
demo.queue().launch(share=True, debug=True)
|