Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,14 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from google_play_scraper import search, app
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
def generate_blogger_html(app_query, custom_link, mod_features):
|
| 5 |
try:
|
|
@@ -12,13 +21,23 @@ def generate_blogger_html(app_query, custom_link, mod_features):
|
|
| 12 |
app_id = search_results[0]['appId']
|
| 13 |
app_details = app(app_id, lang='en', country='us')
|
| 14 |
|
| 15 |
-
# 3. Parse the data
|
| 16 |
title = app_details.get('title', app_query)
|
| 17 |
icon_url = app_details.get('icon', '')
|
| 18 |
rating = round(app_details.get('score', 4.5), 1)
|
|
|
|
| 19 |
category = app_details.get('genre', 'Utility')
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
description = app_details.get('summary', 'Premium application with enhanced features.')
|
|
|
|
| 22 |
|
| 23 |
# 4. Format the custom Mod Features into an HTML list
|
| 24 |
features_list = ""
|
|
@@ -26,29 +45,55 @@ def generate_blogger_html(app_query, custom_link, mod_features):
|
|
| 26 |
if feature.strip():
|
| 27 |
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'
|
| 28 |
|
| 29 |
-
# 5. Build the
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
html_template = f"""
|
|
|
|
| 31 |
<div style="display: none;">
|
| 32 |
-
<img src="{icon_url}" alt="{title}
|
| 33 |
</div>
|
| 34 |
|
| 35 |
<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;">
|
| 36 |
|
| 37 |
<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;">
|
| 38 |
-
<img src="{icon_url}" style="width: 110px; height: 110px; border-radius: 24px; box-shadow: 0 10px 20px rgba(0,0,0,0.5); flex-shrink: 0;">
|
| 39 |
<div style="flex: 1; min-width: 250px;">
|
| 40 |
<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>
|
| 41 |
<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>
|
| 42 |
<div style="display: flex; gap: 15px; font-size: 0.95rem; color: #cbd5e1; font-weight: 700;">
|
| 43 |
<span><i class="fa-solid fa-star" style="color:#f59e0b;"></i> {rating}</span>
|
| 44 |
-
<span><i class="fa-solid fa-
|
| 45 |
<span><i class="fa-brands fa-android"></i> Android 9.0+</span>
|
| 46 |
</div>
|
| 47 |
</div>
|
| 48 |
</div>
|
| 49 |
|
| 50 |
<div style="text-align: center; margin-bottom: 35px; background: #020617; padding: 25px; border-radius: 16px; border: 1px solid rgba(255,255,255,0.02);">
|
| 51 |
-
<a href="{custom_link}" target="_blank" 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;">
|
| 52 |
<i class="fa-solid fa-cloud-arrow-down" style="margin-right: 8px;"></i> Download APK via Secure Link
|
| 53 |
</a>
|
| 54 |
<p style="font-size: 0.8rem; color: #64748b; margin-top: 15px; margin-bottom: 0;">
|
|
@@ -56,15 +101,25 @@ def generate_blogger_html(app_query, custom_link, mod_features):
|
|
| 56 |
</p>
|
| 57 |
</div>
|
| 58 |
|
| 59 |
-
<
|
| 60 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
|
| 62 |
-
<
|
| 63 |
-
<div style="background: rgba(16, 185, 129, 0.05); border: 1px solid rgba(16, 185, 129, 0.2); padding: 20px; border-radius: 12px;">
|
| 64 |
<ul style="color: #f1f5f9; line-height: 1.8; list-style-type: none; padding-left: 0; margin: 0; font-weight: 600;">
|
| 65 |
{features_list}
|
| 66 |
</ul>
|
| 67 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
</div>
|
| 69 |
"""
|
| 70 |
return html_template
|
|
@@ -72,25 +127,84 @@ def generate_blogger_html(app_query, custom_link, mod_features):
|
|
| 72 |
except Exception as e:
|
| 73 |
return f"Error generating HTML: {str(e)}"
|
| 74 |
|
| 75 |
-
#
|
|
|
|
|
|
|
| 76 |
with gr.Blocks(theme=gr.themes.Monochrome()) as agent_ui:
|
| 77 |
-
|
| 78 |
-
gr.
|
| 79 |
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
|
|
|
|
|
|
| 86 |
|
| 87 |
-
|
| 88 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
generate_btn.click(
|
| 91 |
-
fn=
|
| 92 |
-
inputs=[app_input, link_input, features_input],
|
| 93 |
-
outputs=[html_output]
|
| 94 |
)
|
| 95 |
|
| 96 |
if __name__ == "__main__":
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from google_play_scraper import search, app
|
| 3 |
+
import os
|
| 4 |
+
import time
|
| 5 |
+
from datetime import datetime
|
| 6 |
+
import json
|
| 7 |
+
|
| 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:
|
|
|
|
| 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)
|
| 28 |
+
reviews_count = app_details.get('ratings', 1000)
|
| 29 |
category = app_details.get('genre', 'Utility')
|
| 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 = ""
|
|
|
|
| 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;">
|
|
|
|
| 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
|
|
|
|
| 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__":
|