Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,6 +7,7 @@ from datetime import datetime
|
|
| 7 |
import json
|
| 8 |
import requests
|
| 9 |
import urllib.parse
|
|
|
|
| 10 |
|
| 11 |
# -----------------------------
|
| 12 |
# CONFIG & API CONNECTION
|
|
@@ -25,6 +26,11 @@ BLOGGER_CLIENT_SECRET = os.getenv("BLOGGER_CLIENT_SECRET")
|
|
| 25 |
BLOGGER_REFRESH_TOKEN = os.getenv("BLOGGER_REFRESH_TOKEN")
|
| 26 |
BLOGGER_BLOG_ID = os.getenv("BLOGGER_BLOG_ID")
|
| 27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
# -----------------------------
|
| 29 |
# FEATURE 1: KEYWORD DENSITY OPTIMIZER
|
| 30 |
# -----------------------------
|
|
@@ -83,11 +89,14 @@ def summarize_changelog(changelog_text):
|
|
| 83 |
bullets += f"<li>{clean}</li>"
|
| 84 |
return bullets if bullets else "<li>General improvements and bug fixes.</li>"
|
| 85 |
|
|
|
|
| 86 |
# -----------------------------
|
| 87 |
-
# FEATURE 5:
|
| 88 |
# -----------------------------
|
| 89 |
-
def generate_fake_reviews(title):
|
| 90 |
-
"""Generates 5 realistic mixed reviews
|
|
|
|
|
|
|
| 91 |
templates = [
|
| 92 |
("β
β
β
β
β
", "Been using {t} for months now, absolutely no complaints. Works flawlessly on my device.", "Rajan M."),
|
| 93 |
("β
β
β
β
β", "{t} is great overall but took a bit to set up. Worth it though!", "Priya S."),
|
|
@@ -96,8 +105,44 @@ def generate_fake_reviews(title):
|
|
| 96 |
("β
β
β
β
β
", "No ads, no bloat. {t} is exactly what I needed. Highly recommend.", "Sneha R."),
|
| 97 |
("β
β
β
β
β", "Reliable and fast. {t} hasn't crashed once since I installed it.", "David L."),
|
| 98 |
]
|
| 99 |
-
|
| 100 |
html = ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
for stars, review, author in selected:
|
| 102 |
html += f"""
|
| 103 |
<div style="background: rgba(255,255,255,0.03); border: 1px solid rgba(255,255,255,0.08); padding: 16px 20px; border-radius: 14px; margin-bottom: 12px;">
|
|
@@ -106,7 +151,6 @@ def generate_fake_reviews(title):
|
|
| 106 |
<span style="font-size: 0.78rem; color: #64748b; font-weight: 600;">{author} Β· Verified User</span>
|
| 107 |
</div>"""
|
| 108 |
return html
|
| 109 |
-
|
| 110 |
# -----------------------------
|
| 111 |
# FEATURE 6: CONTENT SPINNER / UNIQUENESS
|
| 112 |
# -----------------------------
|
|
|
|
| 7 |
import json
|
| 8 |
import requests
|
| 9 |
import urllib.parse
|
| 10 |
+
import google.generativeai as genai
|
| 11 |
|
| 12 |
# -----------------------------
|
| 13 |
# CONFIG & API CONNECTION
|
|
|
|
| 26 |
BLOGGER_REFRESH_TOKEN = os.getenv("BLOGGER_REFRESH_TOKEN")
|
| 27 |
BLOGGER_BLOG_ID = os.getenv("BLOGGER_BLOG_ID")
|
| 28 |
|
| 29 |
+
# --- Gemini API ---
|
| 30 |
+
GEMINI_API_KEY = os.getenv("GEMINI_API_KEY")
|
| 31 |
+
if GEMINI_API_KEY:
|
| 32 |
+
genai.configure(api_key=GEMINI_API_KEY)
|
| 33 |
+
|
| 34 |
# -----------------------------
|
| 35 |
# FEATURE 1: KEYWORD DENSITY OPTIMIZER
|
| 36 |
# -----------------------------
|
|
|
|
| 89 |
bullets += f"<li>{clean}</li>"
|
| 90 |
return bullets if bullets else "<li>General improvements and bug fixes.</li>"
|
| 91 |
|
| 92 |
+
|
| 93 |
# -----------------------------
|
| 94 |
+
# FEATURE 5: AI DYNAMIC REVIEW GENERATOR
|
| 95 |
# -----------------------------
|
| 96 |
+
def generate_fake_reviews(title, description=""):
|
| 97 |
+
"""Generates 5 realistic mixed reviews using Gemini API, with a static fallback."""
|
| 98 |
+
|
| 99 |
+
# The static fallback list (your original code)
|
| 100 |
templates = [
|
| 101 |
("β
β
β
β
β
", "Been using {t} for months now, absolutely no complaints. Works flawlessly on my device.", "Rajan M."),
|
| 102 |
("β
β
β
β
β", "{t} is great overall but took a bit to set up. Worth it though!", "Priya S."),
|
|
|
|
| 105 |
("β
β
β
β
β
", "No ads, no bloat. {t} is exactly what I needed. Highly recommend.", "Sneha R."),
|
| 106 |
("β
β
β
β
β", "Reliable and fast. {t} hasn't crashed once since I installed it.", "David L."),
|
| 107 |
]
|
| 108 |
+
|
| 109 |
html = ""
|
| 110 |
+
|
| 111 |
+
# Try fetching dynamic reviews from Gemini
|
| 112 |
+
if GEMINI_API_KEY:
|
| 113 |
+
try:
|
| 114 |
+
model = genai.GenerativeModel('gemini-1.5-flash')
|
| 115 |
+
prompt = f"""
|
| 116 |
+
Write 5 short, realistic user reviews for an Android app named '{title}'.
|
| 117 |
+
App description: {description}
|
| 118 |
+
|
| 119 |
+
Return ONLY a valid JSON array of objects. No markdown formatting, no code blocks, no extra text.
|
| 120 |
+
Format:
|
| 121 |
+
[
|
| 122 |
+
{{"author": "Random Indian Name", "rating": 5, "text": "Short review text..."}},
|
| 123 |
+
{{"author": "Random Global Name", "rating": 4, "text": "Short review text..."}}
|
| 124 |
+
]
|
| 125 |
+
Ensure ratings are between 3 and 5.
|
| 126 |
+
"""
|
| 127 |
+
|
| 128 |
+
response = model.generate_content(prompt)
|
| 129 |
+
reviews_data = json.loads(response.text.strip().strip('```json').strip('```'))
|
| 130 |
+
|
| 131 |
+
for rev in reviews_data[:5]:
|
| 132 |
+
stars = "β
" * rev['rating'] + "β" * (5 - rev['rating'])
|
| 133 |
+
html += f"""
|
| 134 |
+
<div style="background: rgba(255,255,255,0.03); border: 1px solid rgba(255,255,255,0.08); padding: 16px 20px; border-radius: 14px; margin-bottom: 12px;">
|
| 135 |
+
<div style="color: #f59e0b; font-size: 1rem; margin-bottom: 6px;">{stars}</div>
|
| 136 |
+
<p style="margin: 0 0 8px 0; color: #cbd5e1; font-size: 0.93rem; line-height: 1.6;">{rev['text']}</p>
|
| 137 |
+
<span style="font-size: 0.78rem; color: #64748b; font-weight: 600;">{rev['author']} Β· Verified User</span>
|
| 138 |
+
</div>"""
|
| 139 |
+
return html
|
| 140 |
+
except Exception as e:
|
| 141 |
+
print(f"Gemini API Error, falling back to static reviews: {e}")
|
| 142 |
+
pass # Move on to fallback
|
| 143 |
+
|
| 144 |
+
# Fallback generation if API fails or key is missing
|
| 145 |
+
selected = random.sample(templates, 5)
|
| 146 |
for stars, review, author in selected:
|
| 147 |
html += f"""
|
| 148 |
<div style="background: rgba(255,255,255,0.03); border: 1px solid rgba(255,255,255,0.08); padding: 16px 20px; border-radius: 14px; margin-bottom: 12px;">
|
|
|
|
| 151 |
<span style="font-size: 0.78rem; color: #64748b; font-weight: 600;">{author} Β· Verified User</span>
|
| 152 |
</div>"""
|
| 153 |
return html
|
|
|
|
| 154 |
# -----------------------------
|
| 155 |
# FEATURE 6: CONTENT SPINNER / UNIQUENESS
|
| 156 |
# -----------------------------
|