|
|
import gradio as gr |
|
|
import requests |
|
|
|
|
|
|
|
|
GEMINI_API_URL = "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-pro:generateContent" |
|
|
API_KEY = "YOUR_API_KEY" |
|
|
|
|
|
|
|
|
main_prompt = """ |
|
|
You are an expert Amazon Merch on Demand (Print on Demand) listing optimizer. |
|
|
|
|
|
You will be given a raw product listing, including a title, brand name, bullet point 1, bullet point 2, and a set of keywords. |
|
|
|
|
|
Your task is to carefully analyze and professionally improve the entire listing while following strict Amazon Merch on Demand best practices. |
|
|
|
|
|
Make the following improvements in your response: |
|
|
|
|
|
--- |
|
|
|
|
|
β
**Title (β€ 60 characters):** |
|
|
- Prioritize relevant high-volume keywords (e.g. "T-Shirt" instead of "Tee"). |
|
|
- Include niche, audience, occasion/holiday if relevant. |
|
|
- Maintain clarity, appeal, and Amazon compliance. |
|
|
- No emojis, no pipes (|), no all-caps words. |
|
|
|
|
|
β
**Brand Name (β€ 50 characters):** |
|
|
- Keep it niche-relevant, creative, and Amazon-appropriate. |
|
|
- You may improve the brand name only if it's generic or lacks niche alignment. |
|
|
|
|
|
β
**Bullet Point 1 (200β256 characters):** |
|
|
- Start with an ALL-CAPS benefit-driven hook (like "FUEL YOUR DAY!" or "COFFEE LOVER MUST-HAVE!") |
|
|
- Describe who the product is for and when to wear it (lifestyle, event, occasion). |
|
|
- Mention the core emotional/functional benefit (e.g., soft, comfy, relatable). |
|
|
- Avoid generic filler. Be natural but clear. |
|
|
|
|
|
β
**Bullet Point 2 (200β256 characters):** |
|
|
- Start with another ALL-CAPS benefit hook (like "GREAT GIFT IDEA!" or "PERFECT FOR COFFEE ADDICTS!") |
|
|
- Emphasize giftability or uniqueness. |
|
|
- Mention comfort, style, and appeal. |
|
|
- **DO NOT use phrases like βClick Add to Cartβ** β this violates Amazon Merch on Demand guidelines. |
|
|
- Maintain persuasive language and urgency in a compliant way. |
|
|
|
|
|
β
**Keywords:** |
|
|
- Refine keyword list to include high-search and long-tail terms. |
|
|
- Avoid keyword stuffing. |
|
|
- Use commas, no quotes, and no repetition. |
|
|
- Balance between short-tail, gender-specific, seasonal, and evergreen search phrases. |
|
|
|
|
|
--- |
|
|
|
|
|
π‘ Think like a top Amazon seller: Use clear, concise, persuasive language that appeals to emotional triggers (like humor, identity, or gifting). Ensure your output follows Amazon's rules and character limits. |
|
|
|
|
|
Return your output in this exact structure: |
|
|
|
|
|
--- |
|
|
|
|
|
**Title (β€ 60 characters):** |
|
|
[Improved Title] |
|
|
|
|
|
**Brand Name (β€ 50 characters):** |
|
|
[Improved Brand Name] |
|
|
|
|
|
**Bullet Point 1 (200β256 characters):** |
|
|
[Improved Bullet Point 1] |
|
|
|
|
|
**Bullet Point 2 (200β256 characters):** |
|
|
[Improved Bullet Point 2] |
|
|
|
|
|
**Optimized Keywords:** |
|
|
[keyword, keyword, keyword, ...] |
|
|
--- |
|
|
""" |
|
|
|
|
|
|
|
|
def optimize_listing(user_input): |
|
|
headers = { |
|
|
"Content-Type": "application/json" |
|
|
} |
|
|
|
|
|
payload = { |
|
|
"contents": [{ |
|
|
"parts": [{ |
|
|
"text": f"{main_prompt}\n\n{user_input.strip()}" |
|
|
}] |
|
|
}], |
|
|
"generationConfig": { |
|
|
"temperature": 0.8, |
|
|
"topP": 1, |
|
|
"topK": 1, |
|
|
"maxOutputTokens": 1024 |
|
|
} |
|
|
} |
|
|
|
|
|
response = requests.post( |
|
|
f"{GEMINI_API_URL}?key={API_KEY}", |
|
|
headers=headers, |
|
|
json=payload |
|
|
) |
|
|
|
|
|
if response.status_code == 200: |
|
|
result = response.json() |
|
|
return result['candidates'][0]['content']['parts'][0]['text'] |
|
|
else: |
|
|
return f"Error: {response.status_code} - {response.text}" |
|
|
|
|
|
|
|
|
with gr.Blocks(theme=gr.themes.Soft()) as app: |
|
|
gr.Markdown("## ποΈ Amazon POD Listing Optimizer (Powered by Gemini 1.5 Pro)") |
|
|
api_key_input = gr.Textbox(label="π Your Gemini API Key", type="password") |
|
|
listing_input = gr.Textbox(label="π Paste Your Full Listing Below", lines=15, placeholder="Paste your Title, Brand Name, Bullet Points, and Keywords...") |
|
|
output_text = gr.Textbox(label="β
Optimized Listing", lines=20) |
|
|
submit_btn = gr.Button("β¨ Optimize Listing") |
|
|
|
|
|
def run_app(listing, key): |
|
|
global API_KEY |
|
|
API_KEY = key.strip() |
|
|
return optimize_listing(listing) |
|
|
|
|
|
submit_btn.click(fn=run_app, inputs=[listing_input, api_key_input], outputs=output_text) |
|
|
|
|
|
|
|
|
app.launch() |
|
|
|