Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,20 +8,19 @@ import json
|
|
| 8 |
# -----------------------------
|
| 9 |
# CONFIG
|
| 10 |
# -----------------------------
|
| 11 |
-
APP_PASSWORD = os.getenv("APP_PASSWORD")
|
| 12 |
|
| 13 |
-
def generate_blogger_html(app_query, custom_link, mod_features):
|
| 14 |
try:
|
| 15 |
-
# 1.
|
| 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 |
-
#
|
| 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 |
-
#
|
| 39 |
-
|
| 40 |
-
full_description = app_details.get('descriptionHTML', description)
|
| 41 |
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
"
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
"
|
| 56 |
-
"author": {
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
"
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
"@type": "Offer",
|
| 67 |
-
"price": "0.00",
|
| 68 |
-
"priceCurrency": "USD"
|
| 69 |
-
}
|
| 70 |
}
|
| 71 |
-
schema_script = f'<script type="application/ld+json">\n{json.dumps(
|
| 72 |
|
| 73 |
-
#
|
| 74 |
html_template = f"""
|
| 75 |
{schema_script}
|
| 76 |
-
<
|
| 77 |
-
|
| 78 |
-
|
|
|
|
| 79 |
|
| 80 |
-
<div class="app-post-wrapper" style="background:
|
| 81 |
|
| 82 |
-
<div style="
|
| 83 |
-
|
|
|
|
|
|
|
| 84 |
<div style="flex: 1; min-width: 250px;">
|
| 85 |
-
<h1 style="margin: 0 0 8px 0; font-size: 2.2rem; font-weight: 800;
|
| 86 |
-
<p style="margin: 0 0 12px 0; color: #94a3b8;
|
| 87 |
-
<div style="display: flex; gap: 15px; font-size: 0.95rem;
|
| 88 |
-
<span
|
| 89 |
-
<span
|
| 90 |
-
<span
|
| 91 |
</div>
|
| 92 |
</div>
|
| 93 |
</div>
|
| 94 |
|
| 95 |
-
<div style="text-align: center; margin
|
| 96 |
-
<
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
<
|
| 100 |
-
|
| 101 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
</div>
|
| 103 |
|
| 104 |
-
<
|
| 105 |
-
|
| 106 |
-
|
| 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 |
-
<
|
| 113 |
-
|
| 114 |
-
<
|
| 115 |
-
|
| 116 |
-
</
|
| 117 |
</div>
|
| 118 |
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
</div>
|
| 123 |
</div>
|
| 124 |
"""
|
| 125 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
|
| 127 |
except Exception as e:
|
| 128 |
-
return f"Error
|
| 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
|
| 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 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 159 |
|
| 160 |
-
|
| 161 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 162 |
|
| 163 |
# --- CONTROLLERS ---
|
| 164 |
def verify_login(pwd, state):
|
| 165 |
-
|
| 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 |
-
|
| 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 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 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__":
|