mroccuper commited on
Commit
acca3b3
Β·
verified Β·
1 Parent(s): 4f03abc

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +103 -0
app.py ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import requests
3
+
4
+ # Gemini 1.5 Pro API setup
5
+ GEMINI_API_URL = "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-pro:generateContent"
6
+ API_KEY = "YOUR_API_KEY" # Replace this with your Gemini API key
7
+
8
+ # System prompt / role instructions
9
+ main_prompt = """
10
+ You are an Amazon Merch on Demand listing expert.
11
+
12
+ Your task is to analyze and optimize listings for print-on-demand apparel (especially t-shirts) based on Amazon SEO best practices and merchandising techniques.
13
+
14
+ Each time, you will receive a listing that contains:
15
+ - Title
16
+ - Brand Name
17
+ - Bullet Point 1
18
+ - Bullet Point 2
19
+ - Suggested Keywords
20
+
21
+ Your goal is to:
22
+ 1. Fix formatting issues (character limits, casing, repetition).
23
+ 2. Optimize for mobile readability (Title ≀ 60 chars, etc.).
24
+ 3. Use ALL CAPS for the start of each bullet (feature-driven structure).
25
+ 4. Add emotional triggers, benefit-driven language, and strong calls to action.
26
+ 5. Eliminate redundancy while keeping tone fun and relatable.
27
+ 6. Add keywords naturally without stuffing.
28
+ 7. Make sure Title includes a clear hook, event/holiday (if any), and age/gender targeting when relevant.
29
+ 8. Brand Name should be relevant, niche-aligned, and SEO-friendly.
30
+ 9. Replace vague terms with clearer, higher-converting ones.
31
+
32
+ Return the optimized listing in this structure:
33
+
34
+ ---
35
+ **OPTIMIZED LISTING**
36
+
37
+ **Title (≀ 60 characters):**
38
+ [Rewritten title]
39
+
40
+ **Brand Name (≀ 50 characters):**
41
+ [Rewritten brand name]
42
+
43
+ **Bullet Point 1 (200–256 characters):**
44
+ [Rewritten bullet 1]
45
+
46
+ **Bullet Point 2 (200–256 characters):**
47
+ [Rewritten bullet 2]
48
+
49
+ **Improved Keywords:**
50
+ [Comma-separated keyword suggestions]
51
+
52
+ ---
53
+ """
54
+
55
+ # Function to call Gemini API
56
+ def optimize_listing(user_input):
57
+ headers = {
58
+ "Content-Type": "application/json"
59
+ }
60
+
61
+ payload = {
62
+ "contents": [{
63
+ "parts": [{
64
+ "text": f"{main_prompt}\n\n{user_input.strip()}"
65
+ }]
66
+ }],
67
+ "generationConfig": {
68
+ "temperature": 0.8,
69
+ "topP": 1,
70
+ "topK": 1,
71
+ "maxOutputTokens": 1024
72
+ }
73
+ }
74
+
75
+ response = requests.post(
76
+ f"{GEMINI_API_URL}?key={API_KEY}",
77
+ headers=headers,
78
+ json=payload
79
+ )
80
+
81
+ if response.status_code == 200:
82
+ result = response.json()
83
+ return result['candidates'][0]['content']['parts'][0]['text']
84
+ else:
85
+ return f"Error: {response.status_code} - {response.text}"
86
+
87
+ # Gradio UI
88
+ with gr.Blocks() as app:
89
+ gr.Markdown("## πŸ›οΈ Amazon POD Listing Optimizer (Powered by Gemini 1.5 Pro)")
90
+ api_key_input = gr.Textbox(label="πŸ”‘ Your Gemini API Key", type="password")
91
+ listing_input = gr.Textbox(label="πŸ“„ Paste Your Full Listing Below", lines=15, placeholder="Paste your Title, Brand Name, Bullet Points, and Keywords...")
92
+ output_text = gr.Textbox(label="βœ… Optimized Listing", lines=20)
93
+ submit_btn = gr.Button("✨ Optimize Listing")
94
+
95
+ def run_app(listing, key):
96
+ global API_KEY
97
+ API_KEY = key.strip()
98
+ return optimize_listing(listing)
99
+
100
+ submit_btn.click(fn=run_app, inputs=[listing_input, api_key_input], outputs=output_text)
101
+
102
+ # Run locally or on Hugging Face Spaces
103
+ app.launch()