Spaces:
Sleeping
Sleeping
Commit
·
6c28c47
1
Parent(s):
0a19c36
feat(analytics): Replace unreliable LLM with robust Python-based summary generator
Browse files- core/strategist.py +31 -48
core/strategist.py
CHANGED
|
@@ -274,60 +274,43 @@ You are an expert Campaign Analyst...
|
|
| 274 |
|
| 275 |
def generate_influencer_analytics_summary(self, kpis: Dict[str, Any]) -> str:
|
| 276 |
"""
|
| 277 |
-
[BULLETPROOF "
|
| 278 |
-
|
| 279 |
"""
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
print(f"--- Strategist Skill (Influencer Analytics): Received KPIs for analysis.")
|
| 283 |
-
|
| 284 |
-
# === THE "FILL-IN-THE-BLANKS" PROMPT ===
|
| 285 |
-
# Model ko ab sirf खाली jagah bharni hai.
|
| 286 |
-
prompt = f"""You are an AI Analyst. Your job is to complete the 2-sentence summary below using the provided data.
|
| 287 |
-
DO NOT change the template. Only fill in the [adjective] and [actionable tip] placeholders.
|
| 288 |
-
|
| 289 |
-
[DATA]
|
| 290 |
-
- Engagement Rate: {kpis.get('avgEngagementRate', 0.0):.2f}%
|
| 291 |
-
- Total Reach: {kpis.get('totalReach', 0)}
|
| 292 |
|
| 293 |
-
[TEMPLATE TO COMPLETE]
|
| 294 |
-
"Your engagement rate is looking [adjective], which is great for building your community! To boost your reach even further, try to [actionable tip] on your next post."
|
| 295 |
-
|
| 296 |
-
[YOUR COMPLETED SUMMARY]
|
| 297 |
-
"""
|
| 298 |
-
|
| 299 |
try:
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 318 |
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
print(" - ⚠️ AI failed to fill the template. Falling back to a default message.")
|
| 322 |
-
return "Your performance analytics are looking solid! Keep creating great content to grow your reach."
|
| 323 |
-
|
| 324 |
-
print(f" - ✅ LLM generated and CLEANED summary successfully: '{summary_text}'")
|
| 325 |
-
return summary_text
|
| 326 |
|
| 327 |
except Exception as e:
|
| 328 |
-
print(f"--- Strategist Skill (Influencer Analytics) ERROR: {e}")
|
| 329 |
-
return "
|
| 330 |
-
|
| 331 |
|
| 332 |
def generate_influencer_growth_plan(self, influencer_data: Dict[str, Any]) -> List[str]:
|
| 333 |
"""
|
|
|
|
| 274 |
|
| 275 |
def generate_influencer_analytics_summary(self, kpis: Dict[str, Any]) -> str:
|
| 276 |
"""
|
| 277 |
+
[BULLETPROOF "NON-AI" VERSION] This function no longer calls the LLM.
|
| 278 |
+
It generates a high-quality, dynamic summary using Python logic for 100% reliability.
|
| 279 |
"""
|
| 280 |
+
print(f"--- Strategist Skill (Influencer Analytics): Generating summary with RELIABLE PYTHON logic.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 281 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 282 |
try:
|
| 283 |
+
engagement_rate = kpis.get('avgEngagementRate', 0.0)
|
| 284 |
+
reach = kpis.get('totalReach', 0)
|
| 285 |
+
|
| 286 |
+
# --- DYNAMIC SENTENCE GENERATION LOGIC ---
|
| 287 |
+
|
| 288 |
+
# Part 1: Adjective for engagement
|
| 289 |
+
if engagement_rate > 5.0:
|
| 290 |
+
adjective = "excellent"
|
| 291 |
+
elif engagement_rate > 2.5:
|
| 292 |
+
adjective = "solid"
|
| 293 |
+
else:
|
| 294 |
+
adjective = "good"
|
| 295 |
+
|
| 296 |
+
# Part 2: Actionable tip based on the most impactful metric
|
| 297 |
+
if reach < 1000 and engagement_rate < 3.0:
|
| 298 |
+
actionable_tip = "try collaborating with another creator to cross-promote and grow your audience."
|
| 299 |
+
elif engagement_rate < 2.0:
|
| 300 |
+
actionable_tip = "try asking a question in your next caption to boost comments and engagement."
|
| 301 |
+
else:
|
| 302 |
+
actionable_tip = "try using a trending audio or format on your next Reel to expand your reach."
|
| 303 |
+
|
| 304 |
+
# Part 3: Combine everything into a perfect summary
|
| 305 |
+
summary = f"Your engagement rate is looking {adjective}, which is great for building community! To grow even further, {actionable_tip}"
|
| 306 |
|
| 307 |
+
print(f" - ✅ Python-generated summary: '{summary}'")
|
| 308 |
+
return summary
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 309 |
|
| 310 |
except Exception as e:
|
| 311 |
+
print(f"--- Strategist Skill (Influencer Analytics) PYTHON ERROR: {e}")
|
| 312 |
+
return "Analytics summary is currently unavailable due to a system error."
|
| 313 |
+
|
| 314 |
|
| 315 |
def generate_influencer_growth_plan(self, influencer_data: Dict[str, Any]) -> List[str]:
|
| 316 |
"""
|