ihtesham0345 commited on
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[:1500]}"\n\nReturn JSON with:\n- core_keywords: list of {{"keyword": str, "search_volume": str, "competition": str, "relevance": int}} (10 keywords)\n- related_phrases: list of strings (5 phrases)\n- viral_hashtags: list of {{"tag": str, "post_count": str}} (5 hashtags)\n- content_titles: list of strings (3 titles)\n- strategy_tips: list of strings (3 tips)\n- target_audience: string'}
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 with post ideas, engagement hooks, hashtags, ad copy, posting time, and growth tips."""
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[:1500]}"\n\nReturn JSON with:\n- post_ideas: list of {{"type": str, "content": str}} (4 posts, types: text/image/video/link/poll)\n- engagement_hooks: list of strings (5 hooks)\n- hashtags: list of strings (5 hashtags)\n- ad_copy_suggestions: list of strings (3 ad copies)\n- best_posting_time: string\n- page_growth_tips: list of strings (3 tips)'}
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 with captions, hashtags, content ideas, posting time, and growth strategies."""
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[:1500]}"\n\nReturn JSON with:\n- captions: list of {{"caption": str, "tone": str}} (3 captions, tones: educational, entertaining, inspirational)\n- hashtag_sets: {{"small": [str], "medium": [str], "large": [str]}} (5 each)\n- content_ideas: {{"reels": [str], "carousels": [str], "stories": [str]}} (2 each)\n- best_posting_time: string\n- growth_strategies: list of strings (3 strategies)'}
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 with post drafts, hashtags, article topics, thought leadership angles, posting time, and industry insights."""
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[:1500]}"\n\nReturn JSON with:\n- post_drafts: list of {{"headline": str, "body": str, "hook": str}} (3 posts)\n- hashtags: list of strings (5 hashtags)\n- article_topics: list of strings (3 topics)\n- thought_leadership_angles: list of strings (3 angles)\n- best_posting_time: string\n- industry_insights: string'}
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 with pin ideas, board organization, SEO keywords, posting time, and traffic strategies."""
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[:1500]}"\n\nReturn JSON with:\n- pin_ideas: list of {{"title": str, "description": str, "keyword_focus": str}} (5 pins)\n- board_organization: list of strings (5 boards)\n- seo_keywords: list of strings (10 keywords)\n- best_posting_time: string\n- traffic_strategies: list of strings (3 strategies)'}
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 with video concepts, trending angles, hashtags, posting time, and viral strategies."""
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[:1500]}"\n\nReturn JSON with:\n- video_concepts: list of {{"hook": str, "script_snippet": str, "sound_suggestion": str}} (4 concepts)\n- trending_angles: list of strings (3 angles)\n- hashtags: list of strings (5 hashtags)\n- best_posting_time: string\n- viral_strategies: list of strings (3 strategies)'}
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 with tweet threads, viral hooks, hashtags, posting time, and engagement tactics."""
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[:1500]}"\n\nReturn JSON with:\n- tweet_threads: list of {{"tweets": [str], "theme": str}} (2 threads, 3-5 tweets each)\n- viral_hooks: list of strings (5 hooks, under 280 chars)\n- hashtags: list of strings (2 hashtags)\n- best_posting_time: string\n- engagement_tactics: list of strings (3 tactics)'}
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 with video titles, tags, description, thumbnail ideas, posting time, engagement tips, and competition analysis."""
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[:1500]}"\n\nReturn JSON with:\n- video_titles: list of {{"title": str, "expected_ctr": str}} (5 titles)\n- tags: list of strings (10 tags)\n- description_template: string\n- thumbnail_ideas: list of strings (3 ideas)\n- best_posting_time: string\n- engagement_strategies: list of strings (3 strategies)\n- competition_gap_analysis: string'}
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)