kacapower commited on
Commit
d727447
ยท
verified ยท
1 Parent(s): ac4bf94

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +155 -127
app.py CHANGED
@@ -8,20 +8,19 @@ import json
8
  # -----------------------------
9
  # CONFIG
10
  # -----------------------------
11
- APP_PASSWORD = os.getenv("APP_PASSWORD") # Set this in your hf Space Secrets
12
 
13
- def generate_blogger_html(app_query, custom_link, mod_features):
14
  try:
15
- # 1. Agent searches the Play Store for the app
16
  search_results = search(app_query, lang='en', country='us')
17
  if not search_results:
18
- return "Error: Could not find this app on the Play Store."
19
 
20
- # 2. Extract the exact App ID and fetch full details
21
  app_id = search_results[0]['appId']
22
  app_details = app(app_id, lang='en', country='us')
23
 
24
- # 3. Parse the extended data
25
  title = app_details.get('title', app_query)
26
  icon_url = app_details.get('icon', '')
27
  rating = round(app_details.get('score', 4.5), 1)
@@ -30,181 +29,210 @@ def generate_blogger_html(app_query, custom_link, mod_features):
30
  developer = app_details.get('developer', 'Unknown Developer')
31
  installs = app_details.get('installs', '10,000+')
32
  version = app_details.get('version', 'Varies with device')
 
 
 
 
 
 
 
 
 
33
 
34
- # Format the updated timestamp
35
  updated_ts = app_details.get('updated', 0)
36
  updated_date = datetime.fromtimestamp(updated_ts).strftime('%B %d, %Y') if updated_ts else "Recently"
 
37
 
38
- # Use full description for better SEO and longer content
39
- description = app_details.get('summary', 'Premium application with enhanced features.')
40
- full_description = app_details.get('descriptionHTML', description)
41
 
42
- # 4. Format the custom Mod Features into an HTML list
43
- features_list = ""
44
- for feature in mod_features.split(','):
45
- if feature.strip():
46
- features_list += f'<li style="margin-bottom: 8px;"><i class="fa-solid fa-check" style="color: var(--neon-green); margin-right: 10px;"></i> {feature.strip()}</li>\n'
47
-
48
- # 5. Build the SEO-Optimized Schema.org JSON-LD
49
- schema_json = {
50
- "@context": "https://schema.org",
51
- "@type": "SoftwareApplication",
52
- "name": title,
53
- "operatingSystem": "ANDROID",
54
- "applicationCategory": category,
55
- "image": icon_url,
56
- "author": {
57
- "@type": "Organization",
58
- "name": developer
59
- },
60
- "aggregateRating": {
61
- "@type": "AggregateRating",
62
- "ratingValue": str(rating),
63
- "ratingCount": str(reviews_count)
64
- },
65
- "offers": {
66
- "@type": "Offer",
67
- "price": "0.00",
68
- "priceCurrency": "USD"
69
- }
70
  }
71
- schema_script = f'<script type="application/ld+json">\n{json.dumps(schema_json, indent=2)}\n</script>'
72
 
73
- # 6. Build the Lexical Space HTML Template
74
  html_template = f"""
75
  {schema_script}
76
- <div style="display: none;">
77
- <img src="{icon_url}" alt="Download {title} Mod APK" />
78
- </div>
 
79
 
80
- <div class="app-post-wrapper" style="background: rgba(15, 23, 42, 0.6); border-radius: 20px; padding: 30px; border: 1px solid rgba(255,255,255,0.05); backdrop-filter: blur(12px); color: #fff; font-family: 'Plus Jakarta Sans', sans-serif; max-width: 800px; margin: 0 auto;">
81
 
82
- <div style="display: flex; gap: 20px; align-items: center; border-bottom: 1px solid rgba(255,255,255,0.1); padding-bottom: 25px; margin-bottom: 25px; flex-wrap: wrap;">
83
- <img src="{icon_url}" alt="{title} Premium Unlocked" style="width: 110px; height: 110px; border-radius: 24px; box-shadow: 0 10px 20px rgba(0,0,0,0.5); flex-shrink: 0;">
 
 
84
  <div style="flex: 1; min-width: 250px;">
85
- <h1 style="margin: 0 0 8px 0; font-size: 2.2rem; font-weight: 800; line-height: 1.1;">{title} <span style="font-size: 0.8rem; background: var(--neon-blue); padding: 4px 10px; border-radius: 12px; vertical-align: middle; margin-left: 10px; letter-spacing: 1px;">MOD</span></h1>
86
- <p style="margin: 0 0 12px 0; color: #94a3b8; font-weight: 600;"><i class="fa-solid fa-layer-group"></i> {category} โ€ข Max Store Verified</p>
87
- <div style="display: flex; gap: 15px; font-size: 0.95rem; color: #cbd5e1; font-weight: 700;">
88
- <span><i class="fa-solid fa-star" style="color:#f59e0b;"></i> {rating}</span>
89
- <span><i class="fa-solid fa-download" style="color: #38bdf8;"></i> {installs}</span>
90
- <span><i class="fa-brands fa-android"></i> Android 9.0+</span>
91
  </div>
92
  </div>
93
  </div>
94
 
95
- <div style="text-align: center; margin-bottom: 35px; background: #020617; padding: 25px; border-radius: 16px; border: 1px solid rgba(255,255,255,0.02);">
96
- <a href="{custom_link}" target="_blank" rel="nofollow noopener" style="display: inline-block; width: 100%; max-width: 400px; background: var(--neon-blue); color: #fff; text-decoration: none; padding: 16px; border-radius: 50px; font-weight: 800; font-size: 1.15rem; box-shadow: 0 0 25px rgba(59,130,246,0.4); transition: transform 0.3s ease;">
97
- <i class="fa-solid fa-cloud-arrow-down" style="margin-right: 8px;"></i> Download APK via Secure Link
98
- </a>
99
- <p style="font-size: 0.8rem; color: #64748b; margin-top: 15px; margin-bottom: 0;">
100
- <i class="fa-solid fa-lock"></i> Link encrypted. Client-side scanning enabled.
101
- </p>
 
 
 
 
102
  </div>
103
 
104
- <h2 style="border-left: 4px solid #38bdf8; padding-left: 12px; margin-bottom: 20px; font-size: 1.3rem;">App Information</h2>
105
- <div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 15px; margin-bottom: 35px; background: rgba(255,255,255,0.02); padding: 20px; border-radius: 12px;">
106
- <div><span style="display: block; font-size: 0.8rem; color: #94a3b8; text-transform: uppercase;">Developer</span><strong>{developer}</strong></div>
107
- <div><span style="display: block; font-size: 0.8rem; color: #94a3b8; text-transform: uppercase;">Version</span><strong>{version}</strong></div>
108
- <div><span style="display: block; font-size: 0.8rem; color: #94a3b8; text-transform: uppercase;">Updated</span><strong>{updated_date}</strong></div>
109
- <div><span style="display: block; font-size: 0.8rem; color: #94a3b8; text-transform: uppercase;">Package ID</span><strong style="font-size: 0.85rem; word-break: break-all;">{app_id}</strong></div>
110
  </div>
111
 
112
- <h2 style="border-left: 4px solid var(--neon-green); padding-left: 12px; margin-bottom: 15px; font-size: 1.3rem;">Max Store Modifications</h2>
113
- <div style="background: rgba(16, 185, 129, 0.05); border: 1px solid rgba(16, 185, 129, 0.2); padding: 20px; border-radius: 12px; margin-bottom: 35px;">
114
- <ul style="color: #f1f5f9; line-height: 1.8; list-style-type: none; padding-left: 0; margin: 0; font-weight: 600;">
115
- {features_list}
116
- </ul>
117
  </div>
118
 
119
- <h2 style="border-left: 4px solid var(--neon-purple); padding-left: 12px; margin-bottom: 15px; font-size: 1.3rem;">About {title}</h2>
120
- <div style="color: #cbd5e1; line-height: 1.7; font-size: 0.95rem; overflow: hidden;">
121
- {full_description}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
122
  </div>
123
  </div>
124
  """
125
- return html_template
 
 
 
 
 
 
 
 
126
 
127
  except Exception as e:
128
- return f"Error generating HTML: {str(e)}"
129
 
130
  # -----------------------------
131
  # UI & AUTHENTICATION LOGIC
132
  # -----------------------------
133
- with gr.Blocks(theme=gr.themes.Monochrome()) as agent_ui:
134
- # State variable to track authentication session
135
  session_state = gr.State({"logged_in": False, "login_time": 0})
136
 
137
- # --- LOGIN SCREEN ---
138
  with gr.Group(visible=True) as login_screen:
139
  gr.Markdown("# ๐Ÿ”’ Lexical Space Internal Tool")
140
- gr.Markdown("Please enter the password to unlock the Post Generator Agent for 30 minutes.")
141
-
142
  with gr.Row():
143
  pwd_input = gr.Textbox(label="Password", type="password", scale=4)
144
- login_btn = gr.Button("Unlock", variant="primary", scale=1)
145
-
146
  login_err = gr.Markdown("โŒ Incorrect password.", visible=False)
147
 
148
- # --- MAIN APPLICATION ---
149
  with gr.Group(visible=False) as main_app:
150
- gr.Markdown("# ๐Ÿš€ Lexical Space Post Generator Agent")
151
- gr.Markdown("Search the Play Store, inject mods, and generate SEO-optimized HTML for your Blogger post.")
152
 
153
  with gr.Row():
154
- with gr.Column():
155
- app_input = gr.Textbox(label="App Name (e.g., YouTube, TeraBox)", placeholder="Search query for Play Store...")
156
- link_input = gr.Textbox(label="Your Download Link (Mega, PixelDrain, etc.)", placeholder="https://...")
157
- features_input = gr.Textbox(label="Mod Features (Comma separated)", placeholder="Premium Unlocked, No Ads, Analytics Removed", value="Premium Unlocked, No Ads, Analytics Removed")
158
- generate_btn = gr.Button("โš™๏ธ Generate HTML", variant="primary")
 
 
 
 
 
159
 
160
- with gr.Column():
161
- html_output = gr.Code(label="Generated HTML (Copy & Paste to Blogger HTML View)", language="html", interactive=False)
 
 
 
 
 
 
 
 
 
 
 
 
162
 
163
  # --- CONTROLLERS ---
164
  def verify_login(pwd, state):
165
- """Checks the password against the hf secret and updates session state."""
166
- if not APP_PASSWORD:
167
- return state, gr.update(), gr.update(), gr.update(value="โŒ System error: APP_PASSWORD secret not set in hf environment.", visible=True)
168
-
169
  if pwd == APP_PASSWORD:
170
- state["logged_in"] = True
171
- state["login_time"] = time.time()
172
  return state, gr.update(visible=False), gr.update(visible=True), gr.update(visible=False)
173
- else:
174
- return state, gr.update(visible=True), gr.update(visible=False), gr.update(value="โŒ Incorrect password.", visible=True)
175
 
176
- def secure_generate(app_query, custom_link, mod_features, state):
177
- """Validates the 30-minute session before running the generation."""
178
- # 1800 seconds = 30 minutes
179
  if not state.get("logged_in") or (time.time() - state.get("login_time", 0) > 1800):
180
  state["logged_in"] = False
181
- return (
182
- "Session expired. Please refresh and log in again.", # html_output
183
- gr.update(visible=True), # login_screen
184
- gr.update(visible=False), # main_app
185
- state # session_state
186
- )
187
-
188
- # Run generation if session is valid
189
- html_result = generate_blogger_html(app_query, custom_link, mod_features)
190
- return (
191
- html_result,
192
- gr.update(visible=False), # Keep login screen hidden
193
- gr.update(visible=True), # Keep main app visible
194
- state
195
- )
196
-
197
- # --- EVENT BINDINGS ---
198
- login_btn.click(
199
- fn=verify_login,
200
- inputs=[pwd_input, session_state],
201
- outputs=[session_state, login_screen, main_app, login_err]
202
- )
203
 
 
 
 
 
 
204
  generate_btn.click(
205
  fn=secure_generate,
206
- inputs=[app_input, link_input, features_input, session_state],
207
- outputs=[html_output, login_screen, main_app, session_state]
208
  )
209
 
210
  if __name__ == "__main__":
 
8
  # -----------------------------
9
  # CONFIG
10
  # -----------------------------
11
+ APP_PASSWORD = os.getenv("APP_PASSWORD")
12
 
13
+ def generate_blogger_html(app_query, custom_link, mod_features, theme_color, telegram_link, custom_size):
14
  try:
15
+ # 1. Search & Extract
16
  search_results = search(app_query, lang='en', country='us')
17
  if not search_results:
18
+ return "Error: Could not find this app on the Play Store.", "", "0", "0"
19
 
 
20
  app_id = search_results[0]['appId']
21
  app_details = app(app_id, lang='en', country='us')
22
 
23
+ # 2. Parse Extended Data
24
  title = app_details.get('title', app_query)
25
  icon_url = app_details.get('icon', '')
26
  rating = round(app_details.get('score', 4.5), 1)
 
29
  developer = app_details.get('developer', 'Unknown Developer')
30
  installs = app_details.get('installs', '10,000+')
31
  version = app_details.get('version', 'Varies with device')
32
+ play_store_url = f"https://play.google.com/store/apps/details?id={app_id}"
33
+
34
+ # New Scraped Features
35
+ scraped_size = app_details.get('size', 'Varies')
36
+ final_size = custom_size if custom_size else scraped_size
37
+ screenshots = app_details.get('screenshots', [])[:3] # Get top 3
38
+ video_url = app_details.get('video', None)
39
+ changelog = app_details.get('recentChanges', 'Bug fixes and performance improvements.')
40
+ if not changelog: changelog = 'Bug fixes and performance improvements.'
41
 
 
42
  updated_ts = app_details.get('updated', 0)
43
  updated_date = datetime.fromtimestamp(updated_ts).strftime('%B %d, %Y') if updated_ts else "Recently"
44
+ full_description = app_details.get('descriptionHTML', app_details.get('summary', 'Premium app.'))
45
 
46
+ # 3. Formats & Generators
47
+ features_list = "".join([f'<li style="margin-bottom: 8px;"><i class="fa-solid fa-check" style="color: {theme_color}; margin-right: 10px;"></i> {f.strip()}</li>\n' for f in mod_features.split(',') if f.strip()])
 
48
 
49
+ screenshots_html = ""
50
+ if screenshots:
51
+ screenshots_html = f'<h2 style="border-left: 4px solid {theme_color}; padding-left: 12px; margin-top: 30px;">App Screenshots</h2><div style="display: flex; gap: 10px; overflow-x: auto; padding-bottom: 15px;">'
52
+ for snap in screenshots:
53
+ screenshots_html += f'<img src="{snap}" style="height: 250px; border-radius: 12px; border: 1px solid rgba(255,255,255,0.1);">'
54
+ screenshots_html += '</div>'
55
+
56
+ video_html = ""
57
+ if video_url:
58
+ video_html = f'<h2 style="border-left: 4px solid {theme_color}; padding-left: 12px; margin-top: 30px;">Official Trailer</h2><div style="position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden; border-radius: 16px;"><iframe src="{video_url.replace("watch?v=", "embed/")}" style="position: absolute; top: 0; left: 0; width: 100%; height: 100%;" frameborder="0" allowfullscreen></iframe></div>'
59
+
60
+ # 4. JSON-LD Schemas (App + FAQ)
61
+ schema_app = {
62
+ "@context": "https://schema.org", "@type": "SoftwareApplication", "name": title, "operatingSystem": "ANDROID",
63
+ "applicationCategory": category, "image": icon_url, "author": {"@type": "Organization", "name": developer},
64
+ "aggregateRating": {"@type": "AggregateRating", "ratingValue": str(rating), "ratingCount": str(reviews_count)},
65
+ "offers": {"@type": "Offer", "price": "0.00", "priceCurrency": "USD"}
66
+ }
67
+ schema_faq = {
68
+ "@context": "https://schema.org", "@type": "FAQPage",
69
+ "mainEntity": [
70
+ {"@type": "Question", "name": f"Is {title} Mod APK safe?", "acceptedAnswer": {"@type": "Answer", "text": "Yes, it is scanned and free from viruses."}},
71
+ {"@type": "Question", "name": f"Does {title} require root?", "acceptedAnswer": {"@type": "Answer", "text": "No, you can install it on any standard Android device."}}
72
+ ]
 
 
 
 
73
  }
74
+ schema_script = f'<script type="application/ld+json">\n[{json.dumps(schema_app)}, {json.dumps(schema_faq)}]\n</script>'
75
 
76
+ # 5. Build HTML
77
  html_template = f"""
78
  {schema_script}
79
+ <style>
80
+ @keyframes pulse {{ 0% {{ transform: scale(1); }} 50% {{ transform: scale(1.02); box-shadow: 0 0 30px {theme_color}80; }} 100% {{ transform: scale(1); }} }}
81
+ .lex-btn:hover {{ filter: brightness(1.2); }}
82
+ </style>
83
 
84
+ <div class="app-post-wrapper" style="background: #0f172a; border-radius: 20px; padding: 30px; border: 1px solid rgba(255,255,255,0.05); color: #f8fafc; font-family: sans-serif; max-width: 850px; margin: 0 auto; line-height: 1.6;">
85
 
86
+ <div style="font-size: 0.8rem; background: rgba(255,255,255,0.05); display: inline-block; padding: 5px 15px; border-radius: 20px; margin-bottom: 20px;">๐Ÿ“Œ <strong>Contents:</strong> <a href="#download" style="color: {theme_color};">Download</a> | <a href="#features" style="color: {theme_color};">Features</a> | <a href="#guide" style="color: {theme_color};">Install Guide</a></div>
87
+
88
+ <div style="display: flex; gap: 20px; align-items: center; border-bottom: 1px solid rgba(255,255,255,0.1); padding-bottom: 25px; flex-wrap: wrap;">
89
+ <img src="{icon_url}" alt="{title} Premium" style="width: 120px; height: 120px; border-radius: 24px; box-shadow: 0 10px 20px rgba(0,0,0,0.5);">
90
  <div style="flex: 1; min-width: 250px;">
91
+ <h1 style="margin: 0 0 8px 0; font-size: 2.2rem; font-weight: 800;">{title} <span style="font-size: 0.8rem; background: {theme_color}; padding: 4px 10px; border-radius: 12px; margin-left: 10px; color:#fff;">MOD APK</span></h1>
92
+ <p style="margin: 0 0 12px 0; color: #94a3b8;">{category} โ€ข By {developer}</p>
93
+ <div style="display: flex; gap: 15px; font-size: 0.95rem; font-weight: 700;">
94
+ <span style="color: #fbbf24;">โ˜… {rating} / 5.0</span>
95
+ <span style="color: #38bdf8;">โฌ‡ {installs}</span>
96
+ <span style="color: #a78bfa;">๐Ÿ“ฆ {final_size}</span>
97
  </div>
98
  </div>
99
  </div>
100
 
101
+ <div id="download" style="text-align: center; margin: 35px 0; background: #020617; padding: 30px; border-radius: 16px; border: 1px solid rgba(255,255,255,0.02);">
102
+ <div style="display: flex; justify-content: center; gap: 15px; margin-bottom: 20px; flex-wrap: wrap;">
103
+ <a href="{custom_link}" target="_blank" rel="nofollow" class="lex-btn" style="flex: 1; min-width: 250px; background: {theme_color}; color: #fff; text-decoration: none; padding: 18px; border-radius: 50px; font-weight: 800; font-size: 1.1rem; animation: pulse 2s infinite;">๐Ÿ“ฅ Download Mod APK</a>
104
+ <a href="{play_store_url}" target="_blank" rel="nofollow" class="lex-btn" style="flex: 1; min-width: 250px; background: #1e293b; border: 1px solid #334155; color: #fff; text-decoration: none; padding: 18px; border-radius: 50px; font-weight: bold; display: flex; align-items: center; justify-content: center; gap: 10px;">๐ŸŽฎ Get on Google Play</a>
105
+ </div>
106
+
107
+ <div style="display: flex; justify-content: center; gap: 20px; font-size: 0.85rem; color: #64748b;">
108
+ <span>๐Ÿ›ก๏ธ VirusTotal Scanned</span>
109
+ <span>QR Available</span>
110
+ <a href="mailto:admin@lexicalspace.com" style="color: #ef4444; text-decoration: none;">๐Ÿšฉ Report Dead Link</a>
111
+ </div>
112
  </div>
113
 
114
+ <div style="background: rgba(56, 189, 248, 0.1); border: 1px solid rgba(56, 189, 248, 0.2); padding: 15px; border-radius: 12px; text-align: center; margin-bottom: 30px;">
115
+ <strong style="color: #e2e8f0; margin-right: 15px;">Join Lexical Space Community:</strong>
116
+ <a href="{telegram_link}" target="_blank" style="background: #0088cc; color: white; padding: 8px 20px; border-radius: 20px; text-decoration: none; font-weight: bold;">โœˆ๏ธ Telegram</a>
 
 
 
117
  </div>
118
 
119
+ <div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 15px; margin-bottom: 35px; background: rgba(255,255,255,0.02); padding: 20px; border-radius: 12px;">
120
+ <div><span style="display: block; font-size: 0.8rem; color: #94a3b8;">Version</span><strong>{version}</strong></div>
121
+ <div><span style="display: block; font-size: 0.8rem; color: #94a3b8;">Updated</span><strong>{updated_date}</strong></div>
122
+ <div><span style="display: block; font-size: 0.8rem; color: #94a3b8;">Requires</span><strong>Android 9.0+</strong></div>
123
+ <div><span style="display: block; font-size: 0.8rem; color: #94a3b8;">Package</span><strong style="font-size: 0.8rem;">{app_id}</strong></div>
124
  </div>
125
 
126
+ {video_html}
127
+ {screenshots_html}
128
+
129
+ <h2 id="features" style="border-left: 4px solid {theme_color}; padding-left: 12px; margin-top: 30px;">Premium Mod Features</h2>
130
+ <div style="background: rgba(16, 185, 129, 0.05); border: 1px solid rgba(16, 185, 129, 0.2); padding: 20px; border-radius: 12px;">
131
+ <ul style="list-style-type: none; padding: 0; margin: 0; font-weight: 600;">{features_list}</ul>
132
+ </div>
133
+
134
+ <h2 style="border-left: 4px solid #f59e0b; padding-left: 12px; margin-top: 30px;">What's New in {version}</h2>
135
+ <div style="background: rgba(255,255,255,0.02); padding: 15px; border-radius: 8px; font-family: monospace; color: #cbd5e1;">{changelog}</div>
136
+
137
+ <h2 id="guide" style="border-left: 4px solid #a78bfa; padding-left: 12px; margin-top: 30px;">How to Install</h2>
138
+ <ol style="color: #cbd5e1; padding-left: 20px;">
139
+ <li style="margin-bottom: 10px;">Download the {title} APK file from the secure link above.</li>
140
+ <li style="margin-bottom: 10px;">Go to your device <strong>Settings > Security</strong> and enable <strong>Unknown Sources</strong>.</li>
141
+ <li style="margin-bottom: 10px;">Open your File Manager, locate the downloaded APK, and tap to install.</li>
142
+ <li style="margin-bottom: 10px;">Launch the app and enjoy the premium features!</li>
143
+ </ol>
144
+
145
+ <h2 style="border-left: 4px solid #ec4899; padding-left: 12px; margin-top: 30px;">About {title}</h2>
146
+ <div style="color: #cbd5e1; overflow: hidden; font-size: 0.95rem;">{full_description}</div>
147
+
148
+ <div style="margin-top: 40px; padding-top: 20px; border-top: 1px solid rgba(255,255,255,0.1); font-size: 0.75rem; color: #64748b; text-align: center;">
149
+ DMCA: Lexical Space complies with 17 U.S.C. ยง 512 and the Digital Millennium Copyright Act. All apps are property of their respective owners.
150
  </div>
151
  </div>
152
  """
153
+ # Calculate Stats
154
+ word_count = str(len(html_template.split()))
155
+ keyword_density = str(html_template.lower().count(title.lower()))
156
+
157
+ # Save Draft locally
158
+ with open("latest_draft.txt", "w", encoding="utf-8") as f:
159
+ f.write(html_template)
160
+
161
+ return html_template, html_template, word_count, keyword_density
162
 
163
  except Exception as e:
164
+ return f"Error: {str(e)}", "<b>Error occurred</b>", "0", "0"
165
 
166
  # -----------------------------
167
  # UI & AUTHENTICATION LOGIC
168
  # -----------------------------
169
+ with gr.Blocks(theme=gr.themes.Monochrome(primary_hue="blue")) as agent_ui:
 
170
  session_state = gr.State({"logged_in": False, "login_time": 0})
171
 
 
172
  with gr.Group(visible=True) as login_screen:
173
  gr.Markdown("# ๐Ÿ”’ Lexical Space Internal Tool")
 
 
174
  with gr.Row():
175
  pwd_input = gr.Textbox(label="Password", type="password", scale=4)
176
+ login_btn = gr.Button("Unlock Dashboard", variant="primary", scale=1)
 
177
  login_err = gr.Markdown("โŒ Incorrect password.", visible=False)
178
 
 
179
  with gr.Group(visible=False) as main_app:
180
+ gr.Markdown("# ๐Ÿš€ Lexical Space V2 Post Generator")
 
181
 
182
  with gr.Row():
183
+ with gr.Column(scale=1):
184
+ gr.Markdown("### โš™๏ธ App Parameters")
185
+ app_input = gr.Textbox(label="App Name (e.g., YouTube)", placeholder="Search query...")
186
+ link_input = gr.Textbox(label="Download Link", placeholder="https://mega.nz/...")
187
+ features_input = gr.Textbox(label="Mod Features", placeholder="Comma separated...", value="Premium Unlocked, No Ads")
188
+
189
+ with gr.Accordion("Advanced SEO & Theme Settings", open=False):
190
+ theme_color = gr.ColorPicker(label="Accent Color", value="#3b82f6")
191
+ telegram_link = gr.Textbox(label="Telegram Link", value="https://t.me/lexicalspace")
192
+ custom_size = gr.Textbox(label="Custom File Size Override", placeholder="e.g. 150 MB")
193
 
194
+ generate_btn = gr.Button("โšก Generate Mega-Post", variant="primary")
195
+
196
+ with gr.Row():
197
+ word_count_out = gr.Textbox(label="Total Word Count", interactive=False)
198
+ kw_density_out = gr.Textbox(label="Keyword Density", interactive=False)
199
+
200
+ gr.File(label="Download Draft Backup", value="latest_draft.txt", visible=False, interactive=False)
201
+
202
+ with gr.Column(scale=2):
203
+ with gr.Tabs():
204
+ with gr.Tab("Source Code (HTML)"):
205
+ html_output = gr.Code(label="Copy this into Blogger's HTML View", language="html", interactive=False, lines=25)
206
+ with gr.Tab("Live Visual Preview"):
207
+ preview_output = gr.HTML(label="How it will look on Lexical Space")
208
 
209
  # --- CONTROLLERS ---
210
  def verify_login(pwd, state):
211
+ if not APP_PASSWORD: return state, gr.update(), gr.update(), gr.update(value="โŒ APP_PASSWORD missing.", visible=True)
 
 
 
212
  if pwd == APP_PASSWORD:
213
+ state["logged_in"], state["login_time"] = True, time.time()
 
214
  return state, gr.update(visible=False), gr.update(visible=True), gr.update(visible=False)
215
+ return state, gr.update(visible=True), gr.update(visible=False), gr.update(value="โŒ Incorrect.", visible=True)
 
216
 
217
+ def secure_generate(app_query, custom_link, mod_features, t_color, t_link, c_size, state):
 
 
218
  if not state.get("logged_in") or (time.time() - state.get("login_time", 0) > 1800):
219
  state["logged_in"] = False
220
+ return ("Session expired.", "", "0", "0", gr.update(visible=True), gr.update(visible=False), state, gr.update(visible=False))
221
+
222
+ code, preview, words, keywords = generate_blogger_html(app_query, custom_link, mod_features, t_color, t_link, c_size)
223
+
224
+ # Unhide the file download component so the user can download the txt file
225
+ return code, preview, words, keywords, gr.update(visible=False), gr.update(visible=True), state, gr.update(value="latest_draft.txt", visible=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
226
 
227
+ # --- BINDS ---
228
+ login_btn.click(fn=verify_login, inputs=[pwd_input, session_state], outputs=[session_state, login_screen, main_app, login_err])
229
+
230
+ file_download = main_app.children[0].children[0].children[4] # Target the hidden file component
231
+
232
  generate_btn.click(
233
  fn=secure_generate,
234
+ inputs=[app_input, link_input, features_input, theme_color, telegram_link, custom_size, session_state],
235
+ outputs=[html_output, preview_output, word_count_out, kw_density_out, login_screen, main_app, session_state, file_download]
236
  )
237
 
238
  if __name__ == "__main__":