import gradio as gr import requests # Gemini 1.5 Pro API setup GEMINI_API_URL = "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-pro:generateContent" API_KEY = "YOUR_API_KEY" # Replace this with your Gemini API key # System prompt / role instructions 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, ...] --- """ # Function to call Gemini API 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}" # Gradio UI 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) # Run locally or on Hugging Face Spaces app.launch()