Spaces:
Sleeping
Sleeping
Commit ·
b0fb0e7
1
Parent(s): 0ca65c8
perf: Reduce max_new_tokens 1500→800, cut output by 50% for faster CPU inference
Browse files- max_new_tokens: 1500 → 800 (cuts response time ~50%)
- Output items reduced: 5→3 titles, 10→5 tags, 3→2 ideas
- Topic truncation: 2000→1000 chars (less prompt processing)
- Content truncation: 2000→1000 chars (less prompt processing)
- Users on GPU can increase via .env config
services/analyzer.py
CHANGED
|
@@ -14,7 +14,6 @@ DEFAULTS = {
|
|
| 14 |
def analyze_seo_content(content: str) -> dict:
|
| 15 |
messages = [
|
| 16 |
{"role": "system", "content": SYSTEM_PROMPT},
|
| 17 |
-
{"role": "user", "content": f'Topic: "{content[:
|
| 18 |
]
|
| 19 |
-
|
| 20 |
-
return run_analysis(messages, defaults=DEFAULTS, temperature=0.3, max_new_tokens=1500)
|
|
|
|
| 14 |
def analyze_seo_content(content: str) -> dict:
|
| 15 |
messages = [
|
| 16 |
{"role": "system", "content": SYSTEM_PROMPT},
|
| 17 |
+
{"role": "user", "content": f'Topic: "{content[:1000]}"\nReturn JSON:\n- core_keywords (5 items, each with "keyword" + "search_volume" + "competition" + "relevance")\n- related_phrases (3 items)\n- viral_hashtags (3 items, each with "tag" + "post_count")\n- content_titles (3 items)\n- strategy_tips (3 items)\n- target_audience (string)'}
|
| 18 |
]
|
| 19 |
+
return run_analysis(messages, defaults=DEFAULTS, temperature=0.3, max_new_tokens=800)
|
|
|
services/facebook_analyzer.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
from services.utils import run_analysis
|
| 2 |
|
| 3 |
-
SYSTEM_PROMPT = """You are a Facebook marketing expert. Return ONLY valid JSON
|
| 4 |
|
| 5 |
DEFAULTS = {
|
| 6 |
"post_ideas": [{"type": "text", "content": "Share your thoughts on this topic below!"}],
|
|
@@ -14,7 +14,6 @@ DEFAULTS = {
|
|
| 14 |
def analyze_facebook(content: str) -> dict:
|
| 15 |
messages = [
|
| 16 |
{"role": "system", "content": SYSTEM_PROMPT},
|
| 17 |
-
{"role": "user", "content": f'Topic: "{content[:
|
| 18 |
]
|
| 19 |
-
|
| 20 |
-
return run_analysis(messages, defaults=DEFAULTS, temperature=0.3, max_new_tokens=1500)
|
|
|
|
| 1 |
from services.utils import run_analysis
|
| 2 |
|
| 3 |
+
SYSTEM_PROMPT = """You are a Facebook marketing expert. Return ONLY valid JSON."""
|
| 4 |
|
| 5 |
DEFAULTS = {
|
| 6 |
"post_ideas": [{"type": "text", "content": "Share your thoughts on this topic below!"}],
|
|
|
|
| 14 |
def analyze_facebook(content: str) -> dict:
|
| 15 |
messages = [
|
| 16 |
{"role": "system", "content": SYSTEM_PROMPT},
|
| 17 |
+
{"role": "user", "content": f'Topic: "{content[:1000]}"\nReturn JSON:\n- post_ideas (2 items, each with "type" + "content")\n- engagement_hooks (3 items)\n- hashtags (3 items)\n- ad_copy_suggestions (2 items)\n- best_posting_time (string)\n- page_growth_tips (2 items)'}
|
| 18 |
]
|
| 19 |
+
return run_analysis(messages, defaults=DEFAULTS, temperature=0.3, max_new_tokens=800)
|
|
|
services/instagram_analyzer.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
from services.utils import run_analysis
|
| 2 |
|
| 3 |
-
SYSTEM_PROMPT = """You are an Instagram growth expert. Return ONLY valid JSON
|
| 4 |
|
| 5 |
DEFAULTS = {
|
| 6 |
"captions": [{"caption": "Check out this amazing content about [TOPIC]!", "tone": "engaging"}],
|
|
@@ -13,7 +13,6 @@ DEFAULTS = {
|
|
| 13 |
def analyze_instagram(content: str) -> dict:
|
| 14 |
messages = [
|
| 15 |
{"role": "system", "content": SYSTEM_PROMPT},
|
| 16 |
-
{"role": "user", "content": f'Topic: "{content[:
|
| 17 |
]
|
| 18 |
-
|
| 19 |
-
return run_analysis(messages, defaults=DEFAULTS, temperature=0.35, max_new_tokens=1500)
|
|
|
|
| 1 |
from services.utils import run_analysis
|
| 2 |
|
| 3 |
+
SYSTEM_PROMPT = """You are an Instagram growth expert. Return ONLY valid JSON."""
|
| 4 |
|
| 5 |
DEFAULTS = {
|
| 6 |
"captions": [{"caption": "Check out this amazing content about [TOPIC]!", "tone": "engaging"}],
|
|
|
|
| 13 |
def analyze_instagram(content: str) -> dict:
|
| 14 |
messages = [
|
| 15 |
{"role": "system", "content": SYSTEM_PROMPT},
|
| 16 |
+
{"role": "user", "content": f'Topic: "{content[:1000]}"\nReturn JSON:\n- captions (2 items, each with "caption" + "tone")\n- hashtag_sets: {"small": [3], "medium": [3], "large": [3]}\n- content_ideas: {"reels": [2], "carousels": [2], "stories": [2]}\n- best_posting_time (string)\n- growth_strategies (2 items)'}
|
| 17 |
]
|
| 18 |
+
return run_analysis(messages, defaults=DEFAULTS, temperature=0.35, max_new_tokens=800)
|
|
|
services/linkedin_analyzer.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
from services.utils import run_analysis
|
| 2 |
|
| 3 |
-
SYSTEM_PROMPT = """You are a LinkedIn content strategist. Return ONLY valid JSON
|
| 4 |
|
| 5 |
DEFAULTS = {
|
| 6 |
"post_drafts": [{"headline": "Key Insights on This Topic", "body": "Here are my thoughts on this important subject.", "hook": "Stop scrolling if you care about this"}],
|
|
@@ -14,7 +14,6 @@ DEFAULTS = {
|
|
| 14 |
def analyze_linkedin(content: str) -> dict:
|
| 15 |
messages = [
|
| 16 |
{"role": "system", "content": SYSTEM_PROMPT},
|
| 17 |
-
{"role": "user", "content": f'Topic: "{content[:
|
| 18 |
]
|
| 19 |
-
|
| 20 |
-
return run_analysis(messages, defaults=DEFAULTS, temperature=0.3, max_new_tokens=1500)
|
|
|
|
| 1 |
from services.utils import run_analysis
|
| 2 |
|
| 3 |
+
SYSTEM_PROMPT = """You are a LinkedIn content strategist. Return ONLY valid JSON."""
|
| 4 |
|
| 5 |
DEFAULTS = {
|
| 6 |
"post_drafts": [{"headline": "Key Insights on This Topic", "body": "Here are my thoughts on this important subject.", "hook": "Stop scrolling if you care about this"}],
|
|
|
|
| 14 |
def analyze_linkedin(content: str) -> dict:
|
| 15 |
messages = [
|
| 16 |
{"role": "system", "content": SYSTEM_PROMPT},
|
| 17 |
+
{"role": "user", "content": f'Topic: "{content[:1000]}"\nReturn JSON:\n- post_drafts (2 items, each with "headline" + "body" + "hook")\n- hashtags (3 items)\n- article_topics (2 items)\n- thought_leadership_angles (2 items)\n- best_posting_time (string)\n- industry_insights (string)'}
|
| 18 |
]
|
| 19 |
+
return run_analysis(messages, defaults=DEFAULTS, temperature=0.3, max_new_tokens=800)
|
|
|
services/pinterest_analyzer.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
from services.utils import run_analysis
|
| 2 |
|
| 3 |
-
SYSTEM_PROMPT = """You are a Pinterest SEO specialist. Return ONLY valid JSON
|
| 4 |
|
| 5 |
DEFAULTS = {
|
| 6 |
"pin_ideas": [{"title": "Complete Guide to This Topic", "description": "Learn everything about this topic with our comprehensive guide.", "keyword_focus": "main topic keyword"}],
|
|
@@ -13,7 +13,6 @@ DEFAULTS = {
|
|
| 13 |
def analyze_pinterest(content: str) -> dict:
|
| 14 |
messages = [
|
| 15 |
{"role": "system", "content": SYSTEM_PROMPT},
|
| 16 |
-
{"role": "user", "content": f'Topic: "{content[:
|
| 17 |
]
|
| 18 |
-
|
| 19 |
-
return run_analysis(messages, defaults=DEFAULTS, temperature=0.3, max_new_tokens=1500)
|
|
|
|
| 1 |
from services.utils import run_analysis
|
| 2 |
|
| 3 |
+
SYSTEM_PROMPT = """You are a Pinterest SEO specialist. Return ONLY valid JSON."""
|
| 4 |
|
| 5 |
DEFAULTS = {
|
| 6 |
"pin_ideas": [{"title": "Complete Guide to This Topic", "description": "Learn everything about this topic with our comprehensive guide.", "keyword_focus": "main topic keyword"}],
|
|
|
|
| 13 |
def analyze_pinterest(content: str) -> dict:
|
| 14 |
messages = [
|
| 15 |
{"role": "system", "content": SYSTEM_PROMPT},
|
| 16 |
+
{"role": "user", "content": f'Topic: "{content[:1000]}"\nReturn JSON:\n- pin_ideas (2 items, each with "title" + "description" + "keyword_focus")\n- board_organization (3 items)\n- seo_keywords (5 items)\n- best_posting_time (string)\n- traffic_strategies (2 items)'}
|
| 17 |
]
|
| 18 |
+
return run_analysis(messages, defaults=DEFAULTS, temperature=0.3, max_new_tokens=800)
|
|
|
services/tiktok_analyzer.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
from services.utils import run_analysis
|
| 2 |
|
| 3 |
-
SYSTEM_PROMPT = """You are a TikTok viral strategist. Return ONLY valid JSON
|
| 4 |
|
| 5 |
DEFAULTS = {
|
| 6 |
"video_concepts": [{"hook": "You won't believe this", "script_snippet": "Here's the full story...", "sound_suggestion": "Trending audio"}],
|
|
@@ -13,7 +13,6 @@ DEFAULTS = {
|
|
| 13 |
def analyze_tiktok(content: str) -> dict:
|
| 14 |
messages = [
|
| 15 |
{"role": "system", "content": SYSTEM_PROMPT},
|
| 16 |
-
{"role": "user", "content": f'Topic: "{content[:
|
| 17 |
]
|
| 18 |
-
|
| 19 |
-
return run_analysis(messages, defaults=DEFAULTS, temperature=0.4, max_new_tokens=1500)
|
|
|
|
| 1 |
from services.utils import run_analysis
|
| 2 |
|
| 3 |
+
SYSTEM_PROMPT = """You are a TikTok viral strategist. Return ONLY valid JSON."""
|
| 4 |
|
| 5 |
DEFAULTS = {
|
| 6 |
"video_concepts": [{"hook": "You won't believe this", "script_snippet": "Here's the full story...", "sound_suggestion": "Trending audio"}],
|
|
|
|
| 13 |
def analyze_tiktok(content: str) -> dict:
|
| 14 |
messages = [
|
| 15 |
{"role": "system", "content": SYSTEM_PROMPT},
|
| 16 |
+
{"role": "user", "content": f'Topic: "{content[:1000]}"\nReturn JSON:\n- video_concepts (2 items, each with "hook" + "script_snippet" + "sound_suggestion")\n- trending_angles (2 items)\n- hashtags (3 items)\n- best_posting_time (string)\n- viral_strategies (2 items)'}
|
| 17 |
]
|
| 18 |
+
return run_analysis(messages, defaults=DEFAULTS, temperature=0.4, max_new_tokens=800)
|
|
|
services/twitter_analyzer.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
from services.utils import run_analysis
|
| 2 |
|
| 3 |
-
SYSTEM_PROMPT = """You are a Twitter/X content strategist. Return ONLY valid JSON
|
| 4 |
|
| 5 |
DEFAULTS = {
|
| 6 |
"tweet_threads": [{"tweets": ["Tweet 1 about the topic", "Tweet 2 with more detail", "Tweet 3 with key insight"], "theme": "educational"}],
|
|
@@ -13,7 +13,6 @@ DEFAULTS = {
|
|
| 13 |
def analyze_twitter(content: str) -> dict:
|
| 14 |
messages = [
|
| 15 |
{"role": "system", "content": SYSTEM_PROMPT},
|
| 16 |
-
{"role": "user", "content": f'Topic: "{content[:
|
| 17 |
]
|
| 18 |
-
|
| 19 |
-
return run_analysis(messages, defaults=DEFAULTS, temperature=0.35, max_new_tokens=1500)
|
|
|
|
| 1 |
from services.utils import run_analysis
|
| 2 |
|
| 3 |
+
SYSTEM_PROMPT = """You are a Twitter/X content strategist. Return ONLY valid JSON."""
|
| 4 |
|
| 5 |
DEFAULTS = {
|
| 6 |
"tweet_threads": [{"tweets": ["Tweet 1 about the topic", "Tweet 2 with more detail", "Tweet 3 with key insight"], "theme": "educational"}],
|
|
|
|
| 13 |
def analyze_twitter(content: str) -> dict:
|
| 14 |
messages = [
|
| 15 |
{"role": "system", "content": SYSTEM_PROMPT},
|
| 16 |
+
{"role": "user", "content": f'Topic: "{content[:1000]}"\nReturn JSON:\n- tweet_threads (1 item, with "tweets" (3 items) + "theme")\n- viral_hooks (3 items, under 280 chars)\n- hashtags (2 items)\n- best_posting_time (string)\n- engagement_tactics (2 items)'}
|
| 17 |
]
|
| 18 |
+
return run_analysis(messages, defaults=DEFAULTS, temperature=0.35, max_new_tokens=800)
|
|
|
services/youtube_analyzer.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
from services.utils import run_analysis
|
| 2 |
|
| 3 |
-
SYSTEM_PROMPT = """You are a YouTube SEO expert. Return ONLY valid JSON
|
| 4 |
|
| 5 |
DEFAULTS = {
|
| 6 |
"video_titles": [{"title": "Topic Deep Dive: Complete Guide", "expected_ctr": "8-12%"}],
|
|
@@ -15,7 +15,6 @@ DEFAULTS = {
|
|
| 15 |
def analyze_youtube(content: str) -> dict:
|
| 16 |
messages = [
|
| 17 |
{"role": "system", "content": SYSTEM_PROMPT},
|
| 18 |
-
{"role": "user", "content": f'Topic: "{content[:
|
| 19 |
]
|
| 20 |
-
|
| 21 |
-
return run_analysis(messages, defaults=DEFAULTS, temperature=0.3, max_new_tokens=1500)
|
|
|
|
| 1 |
from services.utils import run_analysis
|
| 2 |
|
| 3 |
+
SYSTEM_PROMPT = """You are a YouTube SEO expert. Return ONLY valid JSON."""
|
| 4 |
|
| 5 |
DEFAULTS = {
|
| 6 |
"video_titles": [{"title": "Topic Deep Dive: Complete Guide", "expected_ctr": "8-12%"}],
|
|
|
|
| 15 |
def analyze_youtube(content: str) -> dict:
|
| 16 |
messages = [
|
| 17 |
{"role": "system", "content": SYSTEM_PROMPT},
|
| 18 |
+
{"role": "user", "content": f'Topic: "{content[:1000]}"\nReturn JSON:\n- video_titles (3 items, each with "title" + "expected_ctr")\n- tags (5 items)\n- description_template (string)\n- thumbnail_ideas (2 items)\n- best_posting_time (string)\n- engagement_strategies (2 items)\n- competition_gap_analysis (string)'}
|
| 19 |
]
|
| 20 |
+
return run_analysis(messages, defaults=DEFAULTS, temperature=0.3, max_new_tokens=800)
|
|
|