Update file paths in BrandStyleManager to use absolute paths for loading JSON data. Refactor MarketingCopywriter to streamline the generate_copy method by removing unused parameters and initialize dependencies in the generate_marketing_copy function. Modify main.py to remove unnecessary campaign prompt management. Update sample campaigns in campaigns.json for a TV company marketing campaign.

This commit is contained in:
boladeE
2025-04-18 22:34:15 +01:00
parent 4ac80ad73d
commit 3c0dd1d972
4 changed files with 15 additions and 11 deletions
+3 -2
View File
@@ -17,7 +17,7 @@ class BrandStyleManager:
def _load_brand_voice(self) -> Dict[str, Any]:
"""Load brand voice guidelines from JSON."""
file_path = "data/style_guidelines/brand_voice.json"
file_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "data", "style_guidelines", "brand_voice.json"))
if os.path.exists(file_path):
with open(file_path, 'r', encoding='utf-8') as f:
return json.load(f)
@@ -25,7 +25,8 @@ class BrandStyleManager:
def _load_sample_campaigns(self) -> List[Dict[str, Any]]:
"""Load sample campaigns from JSON."""
file_path = "data/past_campaigns/sample_campaigns.json"
file_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "data", "past_campaigns", "sample_campaigns.json"))
if os.path.exists(file_path):
with open(file_path, 'r', encoding='utf-8') as f:
data = json.load(f)
+9 -4
View File
@@ -3,6 +3,8 @@ import requests
import json
from config import settings
from brand_style import BrandStyleManager
from embeddings import CohereEmbeddings
from vector_store import VectorStore
class MarketingCopywriter:
def __init__(self, brand_style_manager: BrandStyleManager):
@@ -52,10 +54,10 @@ class MarketingCopywriter:
Generate the marketing copy:
"""
def generate_copy(self, prompt: str, context: List[Dict], content_type: str, tone: str,
brand_voice: Dict[str, Any], sample_campaigns: List[Dict[str, Any]]) -> str:
def generate_copy(self, prompt: str, context: List[Dict], tone: str,
brand_voice: Dict[str, Any], sample_campaigns) -> str:
"""Generate marketing copy using DeepSeek."""
full_prompt = self._build_prompt(prompt, context, content_type, tone, brand_voice, sample_campaigns)
full_prompt = self._build_prompt(prompt, context, tone, brand_voice, sample_campaigns)
headers = {
"Authorization": f"Bearer {self.api_key}",
@@ -79,10 +81,13 @@ class MarketingCopywriter:
def generate_marketing_copy(prompt: str) -> str:
"""Helper function to generate marketing copy."""
brand_style_manager = BrandStyleManager()
embeddings = CohereEmbeddings()
vector_store = VectorStore()
brand_style_manager = BrandStyleManager(embeddings, vector_store)
copywriter = MarketingCopywriter(brand_style_manager)
context = brand_style_manager.get_relevant_context(prompt)
tone = "professional and empathetic"
brand_voice = brand_style_manager.get_brand_voice()
sample_campaigns = brand_style_manager.get_sample_campaigns()
print(sample_campaigns)
return copywriter.generate_copy(prompt, context, tone, brand_voice, sample_campaigns)
-2
View File
@@ -11,7 +11,6 @@ import datetime
app = Flask(__name__)
# Initialize brand style manager
brand_style_manager = BrandStyleManager()
data_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "data"))
campaign_prompt = []
@@ -35,7 +34,6 @@ def root():
global prompt
if request.method == 'POST':
prompt = request.form.get('prompt')
campaign_prompt.pop()
campaign_prompt.append(prompt)
marketing_copy = generate_marketing_copy(prompt)
return render_template('index.html', generated_copy=marketing_copy)