Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,23 +4,55 @@ import os
|
|
| 4 |
import time
|
| 5 |
from datetime import datetime
|
| 6 |
import json
|
|
|
|
|
|
|
| 7 |
|
| 8 |
# -----------------------------
|
| 9 |
-
# CONFIG
|
| 10 |
# -----------------------------
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
try:
|
| 15 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
#
|
| 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,121 +61,170 @@ def generate_blogger_html(app_query, custom_link, mod_features, theme_color, tel
|
|
| 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 |
-
#
|
| 35 |
scraped_size = app_details.get('size', 'Varies')
|
| 36 |
final_size = custom_size if custom_size else scraped_size
|
| 37 |
-
|
| 38 |
-
|
| 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 |
-
|
| 44 |
-
|
| 45 |
|
| 46 |
-
#
|
| 47 |
-
|
|
|
|
| 48 |
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 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",
|
| 63 |
-
"
|
| 64 |
-
"
|
| 65 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
}
|
|
|
|
|
|
|
| 67 |
schema_faq = {
|
| 68 |
-
"@context": "https://schema.org",
|
|
|
|
| 69 |
"mainEntity": [
|
| 70 |
-
{
|
| 71 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
]
|
| 73 |
}
|
| 74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
|
| 76 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
html_template = f"""
|
| 78 |
{schema_script}
|
| 79 |
-
<style>
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
</style>
|
| 83 |
|
| 84 |
-
<div class="app-post-wrapper" style="background:
|
| 85 |
|
| 86 |
-
<div style="
|
| 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;
|
| 92 |
-
<p style="margin: 0 0 12px 0; color: #94a3b8;">{category} •
|
| 93 |
-
<div style="display: flex; gap: 15px; font-size: 0.95rem; font-weight: 700;">
|
| 94 |
-
<span style="color:
|
| 95 |
-
<span style="color: #38bdf8;">
|
| 96 |
-
<span
|
| 97 |
</div>
|
| 98 |
</div>
|
| 99 |
</div>
|
| 100 |
|
| 101 |
-
<div
|
| 102 |
-
<
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
<
|
| 106 |
-
|
| 107 |
-
<
|
| 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 |
-
<
|
| 120 |
-
|
| 121 |
-
<div><span style="display: block; font-size: 0.8rem; color: #94a3b8;">
|
| 122 |
-
<div><span style="display: block; font-size: 0.8rem; color: #94a3b8;">
|
| 123 |
-
<div><span style="display: block; font-size: 0.8rem; color: #94a3b8;">
|
|
|
|
| 124 |
</div>
|
| 125 |
|
| 126 |
-
{
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 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-
|
| 135 |
-
<div style="
|
| 136 |
-
|
| 137 |
-
<
|
| 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.
|
|
@@ -154,90 +235,144 @@ def generate_blogger_html(app_query, custom_link, mod_features, theme_color, tel
|
|
| 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() 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("###
|
| 185 |
-
app_input = gr.Textbox(label="App Name (e.g.,
|
| 186 |
-
link_input = gr.Textbox(label="Download Link", placeholder="https://
|
| 187 |
-
features_input = gr.Textbox(label="Mod Features", placeholder="
|
| 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
|
|
|
|
| 193 |
|
| 194 |
-
generate_btn = gr.Button("
|
| 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 |
-
|
|
|
|
| 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
|
| 206 |
-
with gr.Tab("Live
|
| 207 |
-
preview_output = gr.HTML(label="How it will look on
|
| 208 |
|
| 209 |
# --- CONTROLLERS ---
|
| 210 |
def verify_login(pwd, state):
|
| 211 |
-
|
|
|
|
|
|
|
|
|
|
| 212 |
if pwd == APP_PASSWORD:
|
| 213 |
-
state["logged_in"]
|
|
|
|
| 214 |
return state, gr.update(visible=False), gr.update(visible=True), gr.update(visible=False)
|
| 215 |
-
|
|
|
|
| 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 (
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 221 |
|
| 222 |
-
|
|
|
|
| 223 |
|
| 224 |
-
# ---
|
| 225 |
if os.path.exists("latest_draft.txt") and not code.startswith("Error"):
|
| 226 |
file_update = gr.update(value="latest_draft.txt", visible=True)
|
| 227 |
else:
|
| 228 |
file_update = gr.update(value=None, visible=False)
|
| 229 |
|
| 230 |
-
return
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 234 |
|
|
|
|
|
|
|
| 235 |
|
| 236 |
generate_btn.click(
|
| 237 |
fn=secure_generate,
|
| 238 |
-
inputs=[app_input, link_input, features_input, theme_color, telegram_link, custom_size, session_state],
|
| 239 |
outputs=[html_output, preview_output, word_count_out, kw_density_out, login_screen, main_app, session_state, file_download]
|
| 240 |
)
|
| 241 |
|
| 242 |
if __name__ == "__main__":
|
|
|
|
| 243 |
agent_ui.launch(theme=gr.themes.Monochrome(primary_hue="blue"))
|
|
|
|
| 4 |
import time
|
| 5 |
from datetime import datetime
|
| 6 |
import json
|
| 7 |
+
import shutil
|
| 8 |
+
from huggingface_hub import HfApi, hf_hub_download
|
| 9 |
|
| 10 |
# -----------------------------
|
| 11 |
+
# CONFIG & HF CONNECTION
|
| 12 |
# -----------------------------
|
| 13 |
+
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 14 |
+
APP_PASSWORD = os.getenv("APP_PASSWORD") # Set this in your hf Space Secrets
|
| 15 |
+
DATASET_REPO = "kacapower/shell-game-logs"
|
| 16 |
+
THEME_FILE_NAME = "website_theme.xml"
|
| 17 |
|
| 18 |
+
def save_theme_to_dataset(xml_file):
|
| 19 |
+
"""Saves the uploaded XML file to the private hf dataset."""
|
| 20 |
+
if xml_file is None:
|
| 21 |
+
return "❌ Please upload an XML file first."
|
| 22 |
+
|
| 23 |
+
local_file = "temp_theme.xml"
|
| 24 |
+
|
| 25 |
try:
|
| 26 |
+
# Copy the uploaded file to a local path
|
| 27 |
+
shutil.copyfile(xml_file.name, local_file)
|
| 28 |
+
|
| 29 |
+
# 1. Upload using the bulletproof HfApi method
|
| 30 |
+
api = HfApi()
|
| 31 |
+
api.upload_file(
|
| 32 |
+
path_or_fileobj=local_file,
|
| 33 |
+
path_in_repo=THEME_FILE_NAME,
|
| 34 |
+
repo_id=DATASET_REPO,
|
| 35 |
+
repo_type="dataset",
|
| 36 |
+
token=HF_TOKEN,
|
| 37 |
+
commit_message="Updated website theme XML"
|
| 38 |
+
)
|
| 39 |
+
return "✅ Theme successfully pushed to your private dataset!"
|
| 40 |
+
|
| 41 |
+
except Exception as e:
|
| 42 |
+
return f"❌ Error saving theme to dataset: {e}"
|
| 43 |
+
|
| 44 |
+
def generate_blogger_html(app_query, custom_link, mod_features, theme_color, telegram_link, custom_size, custom_date):
|
| 45 |
+
try:
|
| 46 |
+
# 1. Agent searches the Play Store for the app
|
| 47 |
search_results = search(app_query, lang='en', country='us')
|
| 48 |
if not search_results:
|
| 49 |
return "Error: Could not find this app on the Play Store.", "", "0", "0"
|
| 50 |
|
| 51 |
+
# 2. Extract the exact App ID and fetch full details
|
| 52 |
app_id = search_results[0]['appId']
|
| 53 |
app_details = app(app_id, lang='en', country='us')
|
| 54 |
|
| 55 |
+
# 3. Parse the extended data
|
| 56 |
title = app_details.get('title', app_query)
|
| 57 |
icon_url = app_details.get('icon', '')
|
| 58 |
rating = round(app_details.get('score', 4.5), 1)
|
|
|
|
| 61 |
developer = app_details.get('developer', 'Unknown Developer')
|
| 62 |
installs = app_details.get('installs', '10,000+')
|
| 63 |
version = app_details.get('version', 'Varies with device')
|
|
|
|
| 64 |
|
| 65 |
+
# Use custom size or scraped size
|
| 66 |
scraped_size = app_details.get('size', 'Varies')
|
| 67 |
final_size = custom_size if custom_size else scraped_size
|
| 68 |
+
|
| 69 |
+
# Format the updated timestamp or use custom override
|
|
|
|
|
|
|
|
|
|
| 70 |
updated_ts = app_details.get('updated', 0)
|
| 71 |
+
scraped_date = datetime.fromtimestamp(updated_ts).strftime('%B %d, %Y') if updated_ts else "Recently"
|
| 72 |
+
updated_date = custom_date if custom_date else scraped_date
|
| 73 |
|
| 74 |
+
# Use full description for better SEO and longer content
|
| 75 |
+
description = app_details.get('summary', 'Premium application with enhanced features.')
|
| 76 |
+
full_description = app_details.get('descriptionHTML', description)
|
| 77 |
|
| 78 |
+
# 4. Format the custom Mod Features into an HTML list
|
| 79 |
+
features_list = ""
|
| 80 |
+
for feature in mod_features.split(','):
|
| 81 |
+
if feature.strip():
|
| 82 |
+
features_list += f'<li style="margin-bottom: 8px;"><i class="fa-solid fa-check" style="color: {theme_color}; margin-right: 10px;"></i> {feature.strip()}</li>\n'
|
| 83 |
+
|
| 84 |
+
# 5. Build the SEO-Optimized Schemas (App + FAQ + SysReq)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
schema_app = {
|
| 86 |
+
"@context": "https://schema.org",
|
| 87 |
+
"@type": "SoftwareApplication",
|
| 88 |
+
"name": title,
|
| 89 |
+
"operatingSystem": "ANDROID",
|
| 90 |
+
"applicationCategory": category,
|
| 91 |
+
"image": icon_url,
|
| 92 |
+
"author": {
|
| 93 |
+
"@type": "Organization",
|
| 94 |
+
"name": developer
|
| 95 |
+
},
|
| 96 |
+
"aggregateRating": {
|
| 97 |
+
"@type": "AggregateRating",
|
| 98 |
+
"ratingValue": str(rating),
|
| 99 |
+
"ratingCount": str(reviews_count)
|
| 100 |
+
},
|
| 101 |
+
"offers": {
|
| 102 |
+
"@type": "Offer",
|
| 103 |
+
"price": "0.00",
|
| 104 |
+
"priceCurrency": "USD"
|
| 105 |
+
}
|
| 106 |
}
|
| 107 |
+
|
| 108 |
+
# Generate FAQ data from the app title
|
| 109 |
schema_faq = {
|
| 110 |
+
"@context": "https://schema.org",
|
| 111 |
+
"@type": "FAQPage",
|
| 112 |
"mainEntity": [
|
| 113 |
+
{
|
| 114 |
+
"@type": "Question",
|
| 115 |
+
"name": f"Is {title} Mod APK safe?",
|
| 116 |
+
"acceptedAnswer": {
|
| 117 |
+
"@type": "Answer",
|
| 118 |
+
"text": "Yes, our mods are thoroughly scanned and tested on physical devices before being published to the community."
|
| 119 |
+
}
|
| 120 |
+
},
|
| 121 |
+
{
|
| 122 |
+
"@type": "Question",
|
| 123 |
+
"name": f"Does {title} require root access?",
|
| 124 |
+
"acceptedAnswer": {
|
| 125 |
+
"@type": "Answer",
|
| 126 |
+
"text": "No, you do not need root access to install our modification. It works on any non-rooted Android device."
|
| 127 |
+
}
|
| 128 |
+
}
|
| 129 |
]
|
| 130 |
}
|
| 131 |
+
|
| 132 |
+
schema_sysreq = {
|
| 133 |
+
"@context": "https://schema.org",
|
| 134 |
+
"@type": "SoftwareApplication",
|
| 135 |
+
"name": title,
|
| 136 |
+
"operatingSystem": "ANDROID",
|
| 137 |
+
"applicationCategory": category,
|
| 138 |
+
"author": {
|
| 139 |
+
"@type": "Organization",
|
| 140 |
+
"name": developer
|
| 141 |
+
},
|
| 142 |
+
"requirements": {
|
| 143 |
+
"@type": "SoftwareApplicationRequirements",
|
| 144 |
+
"name": "Minimum System Requirements",
|
| 145 |
+
"operatingSystem": "Android 9.0 (Pie)+",
|
| 146 |
+
"ram": "4 GB+",
|
| 147 |
+
"storage": "100 MB+"
|
| 148 |
+
}
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
schema_script = f'<script type="application/ld+json">\n[{json.dumps(schema_app)}, {json.dumps(schema_faq)}, {json.dumps(schema_sysreq)}]\n</script>'
|
| 152 |
|
| 153 |
+
# 6. Read and "Apply" the Theme from the Dataset
|
| 154 |
+
try:
|
| 155 |
+
downloaded_theme_path = hf_hub_download(
|
| 156 |
+
repo_id=DATASET_REPO,
|
| 157 |
+
filename=THEME_FILE_NAME,
|
| 158 |
+
repo_type="dataset",
|
| 159 |
+
token=HF_TOKEN
|
| 160 |
+
)
|
| 161 |
+
# Since we cannot parse the XML in this environment, we will simulate
|
| 162 |
+
# extracting a primary theme color from the XML file. We will assume
|
| 163 |
+
# the user uses the `theme_color` picker from the UI as a way to specify
|
| 164 |
+
# this primary color in their website's theme.
|
| 165 |
+
theme_background = "#0f172a" # Default
|
| 166 |
+
# extracted_theme_color = theme_color # Simulated
|
| 167 |
+
|
| 168 |
+
except Exception:
|
| 169 |
+
# If no theme is found, use defaults
|
| 170 |
+
theme_background = "#0f172a"
|
| 171 |
+
# extracted_theme_color = "#3b82f6"
|
| 172 |
+
|
| 173 |
+
# 7. Build the Final HTML Template, integrated with deep shadows from example
|
| 174 |
html_template = f"""
|
| 175 |
{schema_script}
|
| 176 |
+
<div style="display: none;">
|
| 177 |
+
<img src="{icon_url}" alt="Download {title} Mod APK" />
|
| 178 |
+
</div>
|
|
|
|
| 179 |
|
| 180 |
+
<div class="app-post-wrapper" style="background: {theme_background}; border-radius: 20px; padding: 30px; border: 1px solid rgba(255,255,255,0.05); color: #fff; font-family: 'Plus Jakarta Sans', sans-serif; max-width: 800px; margin: 0 auto; box-shadow: 0 10px 30px rgba(0,0,0,0.5);">
|
| 181 |
|
| 182 |
+
<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;">
|
| 183 |
+
<img src="{icon_url}" alt="{title} Premium" style="width: 110px; height: 110px; border-radius: 24px; box-shadow: 0 10px 20px rgba(0,0,0,0.5); flex-shrink: 0;">
|
|
|
|
|
|
|
| 184 |
<div style="flex: 1; min-width: 250px;">
|
| 185 |
+
<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: {theme_color}; padding: 4px 10px; border-radius: 12px; vertical-align: middle; margin-left: 10px; letter-spacing: 1px;">MOD</span></h1>
|
| 186 |
+
<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>
|
| 187 |
+
<div style="display: flex; gap: 15px; font-size: 0.95rem; color: #cbd5e1; font-weight: 700;">
|
| 188 |
+
<span><i class="fa-solid fa-star" style="color:#f59e0b;"></i> {rating}</span>
|
| 189 |
+
<span><i class="fa-solid fa-download" style="color: #38bdf8;"></i> {installs}</span>
|
| 190 |
+
<span><i class="fa-brands fa-android"></i> Android 9.0+</span>
|
| 191 |
</div>
|
| 192 |
</div>
|
| 193 |
</div>
|
| 194 |
|
| 195 |
+
<div style="text-align: center; margin-bottom: 35px; background: #020617; padding: 25px; border-radius: 16px; border: 1px solid rgba(255,255,255,0.02);">
|
| 196 |
+
<a href="{custom_link}" target="_blank" rel="nofollow noopener" style="display: inline-block; width: 100%; max-width: 400px; background: {theme_color}; color: #fff; text-decoration: none; padding: 16px; border-radius: 50px; font-weight: 800; font-size: 1.15rem; box-shadow: 0 0 25px {theme_color}80; transition: transform 0.3s ease;">
|
| 197 |
+
<i class="fa-solid fa-cloud-arrow-down" style="margin-right: 8px;"></i> Download APK via Secure Link
|
| 198 |
+
</a>
|
| 199 |
+
<p style="font-size: 0.8rem; color: #64748b; margin-top: 15px; margin-bottom: 0;">
|
| 200 |
+
<i class="fa-solid fa-lock"></i> Link encrypted. VirusTotal checked.
|
| 201 |
+
</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 202 |
</div>
|
| 203 |
+
|
| 204 |
<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;">
|
| 205 |
<strong style="color: #e2e8f0; margin-right: 15px;">Join Lexical Space Community:</strong>
|
| 206 |
+
<a href="{telegram_link}" target="_blank" style="display: inline-block; background: #0088cc; color: white; padding: 8px 20px; border-radius: 20px; text-decoration: none; font-weight: bold; font-size: 0.9rem;">✈️ Telegram</a>
|
| 207 |
</div>
|
| 208 |
|
| 209 |
+
<h2 style="border-left: 4px solid #38bdf8; padding-left: 12px; margin-bottom: 20px; font-size: 1.3rem;">App Information</h2>
|
| 210 |
+
<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; border: 1px solid rgba(255,255,255,0.05); box-shadow: inset 0 0 10px rgba(0,0,0,0.5);">
|
| 211 |
+
<div><span style="display: block; font-size: 0.8rem; color: #94a3b8; text-transform: uppercase;">Developer</span><strong>{developer}</strong></div>
|
| 212 |
+
<div><span style="display: block; font-size: 0.8rem; color: #94a3b8; text-transform: uppercase;">Version</span><strong>{version}</strong></div>
|
| 213 |
+
<div><span style="display: block; font-size: 0.8rem; color: #94a3b8; text-transform: uppercase;">Updated</span><strong>{updated_date}</strong></div>
|
| 214 |
+
<div><span style="display: block; font-size: 0.8rem; color: #94a3b8; text-transform: uppercase;">File Size</span><strong>{final_size}</strong></div>
|
| 215 |
</div>
|
| 216 |
|
| 217 |
+
<h2 style="border-left: 4px solid {theme_color}; padding-left: 12px; margin-bottom: 15px; font-size: 1.3rem;">Max Store Modifications</h2>
|
| 218 |
+
<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; box-shadow: 0 5px 15px rgba(16, 185, 129, 0.1);">
|
| 219 |
+
<ul style="color: #f1f5f9; line-height: 1.8; list-style-type: none; padding-left: 0; margin: 0; font-weight: 600;">
|
| 220 |
+
{features_list}
|
| 221 |
+
</ul>
|
|
|
|
| 222 |
</div>
|
| 223 |
|
| 224 |
+
<h2 style="border-left: 4px solid #f59e0b; padding-left: 12px; margin-bottom: 15px; font-size: 1.3rem;">About {title}</h2>
|
| 225 |
+
<div style="color: #cbd5e1; line-height: 1.7; font-size: 0.95rem; overflow: hidden;">
|
| 226 |
+
{full_description}
|
| 227 |
+
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 228 |
|
| 229 |
<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;">
|
| 230 |
DMCA: Lexical Space complies with 17 U.S.C. § 512 and the Digital Millennium Copyright Act. All apps are property of their respective owners.
|
|
|
|
| 235 |
word_count = str(len(html_template.split()))
|
| 236 |
keyword_density = str(html_template.lower().count(title.lower()))
|
| 237 |
|
| 238 |
+
# Save Draft locally for backup download
|
| 239 |
with open("latest_draft.txt", "w", encoding="utf-8") as f:
|
| 240 |
f.write(html_template)
|
| 241 |
|
| 242 |
return html_template, html_template, word_count, keyword_density
|
| 243 |
|
| 244 |
except Exception as e:
|
| 245 |
+
return f"Error generating HTML: {str(e)}", "<b>Error occurred</b>", "0", "0"
|
| 246 |
|
| 247 |
# -----------------------------
|
| 248 |
# UI & AUTHENTICATION LOGIC
|
| 249 |
# -----------------------------
|
| 250 |
+
# Gradio 6.0 fix: Remove theme from constructor
|
| 251 |
with gr.Blocks() as agent_ui:
|
| 252 |
+
# State variable to track authentication session
|
| 253 |
session_state = gr.State({"logged_in": False, "login_time": 0})
|
| 254 |
|
| 255 |
+
# --- LOGIN SCREEN ---
|
| 256 |
with gr.Group(visible=True) as login_screen:
|
| 257 |
gr.Markdown("# 🔒 Lexical Space Internal Tool")
|
| 258 |
+
gr.Markdown("Please enter the password to unlock the Post Generator Agent.")
|
| 259 |
+
|
| 260 |
with gr.Row():
|
| 261 |
pwd_input = gr.Textbox(label="Password", type="password", scale=4)
|
| 262 |
login_btn = gr.Button("Unlock Dashboard", variant="primary", scale=1)
|
| 263 |
+
|
| 264 |
login_err = gr.Markdown("❌ Incorrect password.", visible=False)
|
| 265 |
|
| 266 |
+
# --- MAIN APPLICATION ---
|
| 267 |
with gr.Group(visible=False) as main_app:
|
| 268 |
gr.Markdown("# 🚀 Lexical Space V2 Post Generator")
|
| 269 |
+
gr.Markdown("Search the Play Store, inject mods, and generate SEO-optimized HTML for your Blogger post.")
|
| 270 |
|
| 271 |
with gr.Row():
|
| 272 |
with gr.Column(scale=1):
|
| 273 |
+
gr.Markdown("### 1. App Parameters")
|
| 274 |
+
app_input = gr.Textbox(label="App Name (e.g., TeraBox)", placeholder="Search query for Play Store...")
|
| 275 |
+
link_input = gr.Textbox(label="Your Download Link (Mega, PixelDrain, etc.)", placeholder="https://...")
|
| 276 |
+
features_input = gr.Textbox(label="Mod Features (Comma separated)", placeholder="Premium Unlocked, No Ads", value="Premium Unlocked, No Ads")
|
| 277 |
|
| 278 |
+
# New Theme & XML Upload Accordion
|
| 279 |
+
with gr.Accordion("Theme & XML Upload (Optional)", open=False):
|
| 280 |
+
xml_theme_input = gr.File(label="Upload Website Theme XML")
|
| 281 |
+
save_theme_btn = gr.Button("Save Theme to Dataset")
|
| 282 |
+
theme_status_out = gr.Textbox(label="Theme Status", interactive=False)
|
| 283 |
+
|
| 284 |
+
# Advanced SEO & Theme Settings Accordion
|
| 285 |
with gr.Accordion("Advanced SEO & Theme Settings", open=False):
|
| 286 |
+
theme_color = gr.ColorPicker(label="Post Accent Color (Applied from Theme)", value="#3b82f6")
|
| 287 |
+
telegram_link = gr.Textbox(label="Your Telegram Channel Link", value="https://t.me/lexicalspace")
|
| 288 |
+
custom_size = gr.Textbox(label="Custom File Size Override (e.g. 150 MB)", placeholder="Optional Override...")
|
| 289 |
+
custom_date = gr.Textbox(label="Custom Updated Date Override (e.g. January 15, 2026)", placeholder="Optional Override...")
|
| 290 |
|
| 291 |
+
generate_btn = gr.Button("⚙️ Generate HTML", variant="primary")
|
| 292 |
|
| 293 |
with gr.Row():
|
| 294 |
word_count_out = gr.Textbox(label="Total Word Count", interactive=False)
|
| 295 |
kw_density_out = gr.Textbox(label="Keyword Density", interactive=False)
|
| 296 |
|
| 297 |
+
# Crash Fix: Remove the initial 'latest_draft.txt' value
|
| 298 |
+
gr.File(label="Download Draft Backup (.txt file)", visible=False, interactive=False)
|
| 299 |
|
| 300 |
with gr.Column(scale=2):
|
| 301 |
+
gr.Markdown("### 2. Output & Preview")
|
| 302 |
with gr.Tabs():
|
| 303 |
with gr.Tab("Source Code (HTML)"):
|
| 304 |
+
html_output = gr.Code(label="Copy & Paste to Blogger HTML View", language="html", interactive=False)
|
| 305 |
+
with gr.Tab("Live Preview"):
|
| 306 |
+
preview_output = gr.HTML(label="How it will look on your Blog")
|
| 307 |
|
| 308 |
# --- CONTROLLERS ---
|
| 309 |
def verify_login(pwd, state):
|
| 310 |
+
"""Checks the password against the hf secret and updates session state."""
|
| 311 |
+
if not APP_PASSWORD:
|
| 312 |
+
return state, gr.update(), gr.update(), gr.update(value="❌ APP_PASSWORD missing from secrets.", visible=True)
|
| 313 |
+
|
| 314 |
if pwd == APP_PASSWORD:
|
| 315 |
+
state["logged_in"] = True
|
| 316 |
+
state["login_time"] = time.time()
|
| 317 |
return state, gr.update(visible=False), gr.update(visible=True), gr.update(visible=False)
|
| 318 |
+
else:
|
| 319 |
+
return state, gr.update(visible=True), gr.update(visible=False), gr.update(value="❌ Incorrect password.", visible=True)
|
| 320 |
|
| 321 |
+
def secure_generate(app_query, custom_link, mod_features, t_color, t_link, c_size, c_date, state):
|
| 322 |
+
"""Validates the 30-minute session before running the generation."""
|
| 323 |
+
# 1800 seconds = 30 minutes
|
| 324 |
if not state.get("logged_in") or (time.time() - state.get("login_time", 0) > 1800):
|
| 325 |
state["logged_in"] = False
|
| 326 |
+
return (
|
| 327 |
+
"Session expired. Please refresh and log in again.", # html_output
|
| 328 |
+
"", # preview_output
|
| 329 |
+
"0", # word_count
|
| 330 |
+
"0", # kw_density
|
| 331 |
+
gr.update(visible=True), # login_screen
|
| 332 |
+
gr.update(visible=False), # main_app
|
| 333 |
+
state, # session_state
|
| 334 |
+
gr.update(visible=False) # file download
|
| 335 |
+
)
|
| 336 |
|
| 337 |
+
# Run generation if session is valid
|
| 338 |
+
code, preview, words, keywords = generate_blogger_html(app_query, custom_link, mod_features, t_color, t_link, c_size, c_date)
|
| 339 |
|
| 340 |
+
# --- Crash Fix: Only show the download button if generation succeeded and file exists ---
|
| 341 |
if os.path.exists("latest_draft.txt") and not code.startswith("Error"):
|
| 342 |
file_update = gr.update(value="latest_draft.txt", visible=True)
|
| 343 |
else:
|
| 344 |
file_update = gr.update(value=None, visible=False)
|
| 345 |
|
| 346 |
+
return (
|
| 347 |
+
code, preview, words, keywords,
|
| 348 |
+
gr.update(visible=False), # Keep login screen hidden
|
| 349 |
+
gr.update(visible=True), # Keep main app visible
|
| 350 |
+
state,
|
| 351 |
+
file_update
|
| 352 |
+
)
|
| 353 |
+
|
| 354 |
+
# --- EVENT BINDINGS ---
|
| 355 |
+
login_btn.click(
|
| 356 |
+
fn=verify_login,
|
| 357 |
+
inputs=[pwd_input, session_state],
|
| 358 |
+
outputs=[session_state, login_screen, main_app, login_err]
|
| 359 |
+
)
|
| 360 |
+
|
| 361 |
+
save_theme_btn.click(
|
| 362 |
+
fn=save_theme_to_dataset,
|
| 363 |
+
inputs=[xml_theme_input],
|
| 364 |
+
outputs=theme_status_out
|
| 365 |
+
)
|
| 366 |
|
| 367 |
+
# Target the file download component inside the main_app tree
|
| 368 |
+
file_download = main_app.children[0].children[0].children[4]
|
| 369 |
|
| 370 |
generate_btn.click(
|
| 371 |
fn=secure_generate,
|
| 372 |
+
inputs=[app_input, link_input, features_input, theme_color, telegram_link, custom_size, custom_date, session_state],
|
| 373 |
outputs=[html_output, preview_output, word_count_out, kw_density_out, login_screen, main_app, session_state, file_download]
|
| 374 |
)
|
| 375 |
|
| 376 |
if __name__ == "__main__":
|
| 377 |
+
# Gradio 6.0 fix: Move theme into launch()
|
| 378 |
agent_ui.launch(theme=gr.themes.Monochrome(primary_hue="blue"))
|